square / connect-csharp-sdk

C# client library for the Square Connect APIs
https://docs.connect.squareup.com/
Apache License 2.0
27 stars 25 forks source link

Updating to new version and receiving error with CreatePayment related to permissions #134

Closed Telarin closed 4 years ago

Telarin commented 5 years ago

So I'm working on rewriting my checkout code to move from the old 2.10 version to the most recent. I have rewritten everything, converting the C# sample to VB.Net as best as I can, but am receiving an odd exception when I call CreatePayment:

Error calling CreatePayment: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

at Square.Connect.Api.PaymentsApi.CreatePaymentWithHttpInfo(CreatePaymentRequest body)
at Square.Connect.Api.PaymentsApi.CreatePayment(CreatePaymentRequest body)
at USGemstone.ShoppingCart1.btnPaymentNewSubmit_Click(Object sender, EventArgs e) in \USGemstone\ShoppingCart.aspx.vb:line 388

I believe my payment code to be correct, and fairly straightforward. I will post a simplified version (error handling removed for clarity):

        Configuration.Default.AccessToken = AccessToken

        Dim uuid As String = Guid.NewGuid().ToString()

        Dim amount As New Money((subtotal + ShoppingCart.ShippingAmount) * 100, "USD")

        Dim body As New CreatePaymentRequest(Request.Form("nonce"), uuid, amount)

        Dim _address As New Address
        _address.AddressLine1 = ShoppingCart.ShippingAddress.Address1
        _address.AddressLine2 = ShoppingCart.ShippingAddress.Address2
        _address.Locality = ShoppingCart.ShippingAddress.City
        _address.Country = ShoppingCart.ShippingAddress.Country
        _address.AdministrativeDistrictLevel1 = ShoppingCart.ShippingAddress.Region
        body.ShippingAddress = _address

        Dim _paymentsApi As New PaymentsApi(Configuration.Default)
        Dim paymentResponse As CreatePaymentResponse = _paymentsApi.CreatePayment(body)

Am I missing something obvious? Is this perhaps some kind of issue with the configuration of the server environment? Using GoDaddy for hosting.

StephenJosey commented 5 years ago

Hi @Telarin sorry for the delay here. It sounds like it's a security issue related to your server. Doing some searches, it sounds like it might be something around permissions/trusting around network like intranet, but that's out of my domain unfortunately.

As a test, can you do any Square API calls? Ie even a simple ListLocations or anything? Or do they all fail?

Telarin commented 4 years ago

Just wanted to reply for completeness, in case anyone else has this issue. Godaddy sets applications to medium trust by default, so the Square Connect SDK cannot communicate out. Was resolved by adding

<trust level="Full"

to the system.web section of my web.config so that it runs in full trust mode.