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:\Users\User\Desktop\csharp_payment\Pages\ProcessPayment.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

Since you mentioned it’s working in sandbox, are you successfully switching to PRODUCTION environment? Something like this:

            SquareClient client = new SquareClient.Builder()
                .Environment(Square.Environment.Production)
                .AccessToken("production_access_token")
                .Build();

If yes, can you share your Square application id and I can take a look at our logs?

foreach (var item in e.Errors)
{
resulterr += item.Detail;
this.ResultMessage = (resulterr);
}

This will help printing the error properly