付款方式错误平方Api

时间:2017-08-22 17:33:48

标签: c# payment-gateway square square-connect

我试图将Square API与我的asp.net C#应用程序集成,然后向卡片收取异常

Error calling Charge: {"errors":[{"category":"PAYMENT_METHOD_ERROR","code":"CARD_DECLINED","detail":"Card declined."}]}

但是当我使用Sandbox凭证时,它可以正常工作。

这是整个代码的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();
        }

1 个答案:

答案 0 :(得分:0)

Square的开发者沙箱在接受卡片方面更为宽松。尝试使用其他卡,如果卡被拒绝,您将收到预期的错误。