We use GoDaddy to host our website to talk with Square thru the API.
We have been taking credit card payments for the past couple of months and yesterday we started getting exceptions with the CreatePaymentAsync not returning.
I have contacted Square and they said nothing is coming thru and GoDaddy said no issues. We have not changed the code. Any help would be greatly appreciated. This is the code we are using.
We get an exception from the TakePaymentHelper without any exception information.
Additionally the
Task.WaitAll(result) doesn’t seem to complete.
I have no idea what could have changed or where to start. Our code just stopped working? GoDaddy problem? Square issue?
Please help since this is for a neighborhood pool and we can’t take payments.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
using Newtonsoft.Json.Converters;
using Square;
using Square.Utilities;
using Square.Http.Client;
using Square.Http.Response;
using Square.Apis;
using Square.Exceptions;
namespace SquareSDKHelperClassLibrary
{
public class SquareHelper
{
ApiException Except;
public Square.Models.CreatePaymentResponse TakePaymentHelper(String Nonce, Double Amount, String Reference, String Description, String CustomerID, String CustomerEmail, ref ApiException SquExcept)
{
try
{
Except = null;
Square.Models.CreatePaymentResponse PaymentResponse = null;
Task<Square.Models.CreatePaymentResponse> result = TakePayment(Nonce, Amount, Reference, Description, CustomerID, CustomerEmail);
Task.WaitAll(result);
if (result.Result != null)
{
PaymentResponse = result.Result;
//TextBoxError.Text = PaymentResponse.ToString();
}
SquExcept = Except;
return PaymentResponse;
}
catch (Exception ex)
{
Console.WriteLine("Failed to make the request");
Console.WriteLine("Exception " + ex.Message);
return null;
}
// Dim payment As Models.CreatePaymentResponse = result.Result
}
async Task<Square.Models.CreatePaymentResponse> TakePayment(String Nonce, Double Amount, String Reference, String Description, String CustomerID, String CustomerEmail)
{
SquareClient client = new SquareClient.Builder()
.Environment(Square.Environment.Production)
.AccessToken("sq0atp-removed") //production
.Build();
String LocationStr = "removed"; //production
String PaymentGUID = Guid.NewGuid().ToString();
IPaymentsApi paymentsApi = client.PaymentsApi;
long IntAmount = Convert.ToInt64(Amount * 100.0); //Convert to Square value
var bodyAmountMoney = new Square.Models.Money.Builder()
.Amount(IntAmount)
.Currency("USD")
.Build();
var body = new Square.Models.CreatePaymentRequest.Builder(
Nonce,
PaymentGUID,
bodyAmountMoney)
.Autocomplete(true)
.CustomerId(CustomerID)
.LocationId(LocationStr)
.ReferenceId(Reference)
.Note(Description)
.BuyerEmailAddress(CustomerEmail)
.Build();
Square.Models.CreatePaymentResponse result = null;
try
{
result = await paymentsApi.CreatePaymentAsync(body);
return result;
}
catch (ApiException e)
{
Except = e;
return result;
};
}
}