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

Square Get Payments Code Hangs #139

Closed jmawebtech closed 4 years ago

jmawebtech commented 4 years ago

Hi,

My code here hangs:

batchToken = response.Result.BatchToken;

I opened Fiddler and I see a request and response with JSON. The code never throws an exception. I added a breakpoint at the Debug.Print line, but it is never hit. I use version 2.18 of the SDK.

Is there any logging with this SDK?

Here is my code:

` public List SearchPayments(DateTime beginTime, DateTime endTime, List locationNames) { List payments = new List(); // Configure OAuth2 access token for authorization: oauth2

        if (locationNames == null || locationNames.Count() == 0)
            locationNames = Locations.Select(a => a.Name).ToList();

        foreach (string locationName in locationNames)
        {
            var apiInstance = new V1TransactionsApi();
            var locationId = String.IsNullOrEmpty(locationName) ? null : Locations.Where(a => a.Name == locationName || a.Id == locationName).FirstOrDefault().Id;  // string | The ID of the location to list payments for. If you specify me, this endpoint returns payments aggregated from all of the business's Locations.
            var limit = 100;  // int? | The maximum number of payments to return in a single response. This value cannot exceed 200. (optional) 
            var includePartial = true;  // bool? | Indicates whether or not to include partial payments in the response. Partial payments will have the tenders collected so far, but the itemizations will be empty until the payment is completed. (optional) 
            string batchToken = string.Empty;

            try
            {
                // ListPayments
                var response = apiInstance.ListPaymentsAsyncWithHttpInfo(locationId, null, beginTime.ToUniversalTime().ToString("o"), endTime.ToUniversalTime().ToString("o"), limit, batchToken, includePartial);

                batchToken = response.Result.BatchToken;
                payments.AddRange(response.Result.Data);

                while (!String.IsNullOrEmpty(batchToken))
                {
                    response = apiInstance.ListPaymentsAsyncWithHttpInfo(locationId, null, beginTime.ToUniversalTime().ToString("o"), endTime.ToUniversalTime().ToString("o"), limit, batchToken, includePartial);
                    batchToken = response.Result.BatchToken;
                    payments.AddRange(response.Result.Data);
                }
            }
            catch (Exception e)
            {
                Debug.Print("Exception when calling V1TransactionsApi.ListPayments: " + e.Message);
            }
        }

        return payments;
    }

`

Here is the request and response:

GET https://connect.squareup.com/v1/RQXJ1MQBC9XMW/payments?begin_time=2019-09-01T04%3a00%3a00.0000000Z&end_time=2019-11-01T03%3a59%3a00.0000000Z&limit=100&batch_token=&include_partial=True HTTP/1.1 Accept: application/json Authorization: Bearer X User-Agent: Square-Connect-CSharp/2.20190508.0 Host: connect.squareup.com Accept-Encoding: gzip, deflate Connection: Keep-Alive

HTTP/1.1 200 OK Content-Type: application/json Vary: Origin, Accept-Encoding X-Content-Type-Options: nosniff X-Download-Options: noopen X-Frame-Options: SAMEORIGIN X-Permitted-Cross-Domain-Policies: none X-Xss-Protection: 1; mode=block Date: Tue, 22 Oct 2019 19:40:17 GMT keep-alive: timeout=60 Strict-Transport-Security: max-age=631152000 content-length: 2060

[{"id":"s2qjt30BoYaeqcrqIpvR3tMF","merchant_id":"RQXJ1MQBC9XMW","created_at":"2019-10-14T19:12:33Z","device":{},"payment_url":"https://squareup.com/dashboard/sales/transactions/k97XblBgaQ7aroMAmSsY0wMF","receipt_url":"https://squareup.com/receipt/preview/s2qjt30BoYaeqcrqIpvR3tMF","inclusive_tax_money":{"amount":0,"currency_code":"USD"},"additive_tax_money":{"amount":0,"currency_code":"USD"},"tax_money":{"amount":0,"currency_code":"USD"},"tip_money":{"amount":0,"currency_code":"USD"},"discount_money":{"amount":0,"currency_code":"USD"},"total_collected_money":{"amount":100,"currency_code":"USD"},"processing_fee_money":{"amount":-19,"currency_code":"USD"},"net_total_money":{"amount":81,"currency_code":"USD"},"refunded_money":{"amount":0,"currency_code":"USD"},"swedish_rounding_money":{"amount":0,"currency_code":"USD"},"gross_sales_money":{"amount":100,"currency_code":"USD"},"net_sales_money":{"amount":100,"currency_code":"USD"},"surcharge_money":{"amount":0,"currency_code":"USD"},"surcharges":[],"inclusive_tax":[],"additive_tax":[],"tender":[{"type":"CREDIT_CARD","payment_note":"Online Transaction","name":"Credit Card","id":"s2qjt30BoYaeqcrqIpvR3tMF","total_money":{"amount":100,"currency_code":"USD"},"card_brand":"AMERICAN_EXPRESS","pan_suffix":"1005","entry_method":"MANUAL","refunded_money":{"amount":0,"currency_code":"USD"},"receipt_url":"https://squareup.com/receipt/preview/s2qjt30BoYaeqcrqIpvR3tMF","employee_id":"hW0as_ckX6d5_vxcJboG","is_exchange":false,"tendered_at":"2019-10-14T19:12:33Z","settled_at":"2019-10-14T19:12:33Z"}],"refunds":[],"itemizations":[{"name":"Custom Amount","quantity":"1.00000000","notes":"Online Transaction","item_detail":{"category_name":"","sku":""},"itemization_type":"CUSTOM_AMOUNT","total_money":{"amount":100,"currency_code":"USD"},"single_quantity_money":{"amount":100,"currency_code":"USD"},"gross_sales_money":{"amount":100,"currency_code":"USD"},"discount_money":{"amount":0,"currency_code":"USD"},"net_sales_money":{"amount":100,"currency_code":"USD"},"taxes":[],"discounts":[],"modifiers":[]}]}]

StephenJosey commented 4 years ago

It most likely doesn't have a response by the time you're hitting the next line batchToken = response.Result.BatchToken; since you're using the asynchronous call. Could you try using ListPaymentsWithHttpInfo instead? If you really want the async call, then know that it's returning a Task, and you're not running the task or doing anything with it. I think you can do something like response.Start() but I'm not super familiar with C# myself.

IvanMykhayliv commented 4 years ago

Hello, my name is Ivan and I am with JMA Web Technologies as well.

I just wanted to inform you that we updated our code and the issue appears to have been resolved. You can go ahead and close this ticket.

Thank you very much for the help, and have a great day.