Square Payment Processing Error: HTTP Response Not OK | Using Connect .net API

Im using asp.net API from Connect Square to generate nonce and create a payment. My payment form is loading correctly generating a nonce but not creating paymentrequest. Here is the error response

HTTP Response Not OKSquare.Exceptions.ApiException: HTTP Response Not OK at
 Square.Utilities.ApiHelper.RunTaskSynchronously(Task t) at
 Square.Apis.PaymentsApi.CreatePayment(CreatePaymentRequest body) at
 sqRazorSample.Pages.ProcessPaymentModel.OnPost() in 
C:UsersUserDesktopcsharp_paymentPagesProcessPayment.cshtml.cs:line 60

Here is the code at line 60.. payment Creation
 public void OnPost()
    {
        string nonce = Request.Form["nonce"];
        // IPaymentsApi paymentsApi = new PaymentsApi(this.BasePath);
        // paymentsApi.Configuration.AccessToken = this.AccessToken;
        IPaymentsApi PaymentsApi = client.PaymentsApi;

        string uuid = NewIdempotencyKey(); //NewIdempotencyKey();
        Money amount = new Money(100, "USD");

        CreatePaymentRequest createPaymentRequest = new CreatePaymentRequest(amountMoney: amount, idempotencyKey: uuid, sourceId: nonce);
        try
        {
            var response = PaymentsApi.CreatePayment(createPaymentRequest); \This is giving error
            this.ResultMessage = "Payment complete! " + response;
        }
        catch (ApiException e)
        {
            this.ResultMessage = e.Message + e;
        }
    }

Working in Sandbox environment and localhost. Anyhelp would be appreciated

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

My account was in GPB and currency set here was in USD. exception is not printing error details. so we have to print it in an object


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x