I'm trying to integrate Square API with my asp.net C# application and charge a card it give an exception
Error calling Charge: {"errors":[{"category":"PAYMENT_METHOD_ERROR","code":"CARD_DECLINED","detail":"Card declined."}]}
But when I use Sandbox credential it work fine.
This is the git link for whole code. https://github.com/square/connect-api-examples/blob/master/connect-examples/v2/csharp_payment/PaymentExample/Default.aspx.cs
Following is my code.
private static TransactionsApi _transactionsApi = new TransactionsApi();
private static string _locationId = "G5CXF7RRQ5**";
[System.Web.Services.WebMethod]
public static string Charge(string nonce)
{
string msg = "";
try
{
Configuration.Default.AccessToken = "sq0atp-QXNE1q59un5dzDeDC****";
string uuid = NewIdempotencyKey();
Money amount = new Money(100, Money.CurrencyEnum.USD);
string a = "";
ChargeRequest body = new ChargeRequest(AmountMoney: amount, IdempotencyKey: uuid, CardNonce: nonce);
var response = _transactionsApi.Charge(_locationId, body);
return msg = response.ToJson();
}
catch (ApiException e)
{
return msg = e.Message;
}
}
public static string NewIdempotencyKey()
{
return Guid.NewGuid().ToString();
}