【发布时间】:2017-08-22 17:33:47
【问题描述】:
我正在尝试将 Square API 与我的 asp.net C# 应用程序集成并收取一张卡,它给出了一个例外
Error calling Charge: {"errors":[{"category":"PAYMENT_METHOD_ERROR","code":"CARD_DECLINED","detail":"Card declined."}]}
但是当我使用沙盒凭据时,它可以正常工作。
这是整个代码的 git 链接。 https://github.com/square/connect-api-examples/blob/master/connect-examples/v2/csharp_payment/PaymentExample/Default.aspx.cs
以下是我的代码。
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();
}
【问题讨论】:
-
请提供更多信息和一些您正在使用的代码,以便他人理解您的问题并为您提供帮助。
-
这是整个代码的 git 链接。github.com/square/connect-api-examples/blob/master/…
-
现在我分享我的代码.....
标签: c# payment-gateway square square-connect