paypal - 调用 payment.Create() 时出错

标签 paypal paypal-sandbox

动机

我想在我的网站上接受信用卡。我选择 PayPal 是因为它们看起来最省事而且费率也不错,而且我想尽快开始接受信用卡。我选择信用卡付款是因为我不希望我的网站用户访问 PayPal 网站;我希望他们留在我的网站上。这看起来更令人印象深刻和专业。

我做了什么

我从 Paypal 下载了 PayPal.SDK.NET451PayPal.SDK.Sample.VS.2013 .我正在运行 PayPal.dll 版本 1.7.3.0 我创建了一个 developer account在沙盒上,但对于这个实验,他们建议只使用示例项目附带的 clientIdclientSecret,以排除我的帐户或应用程序定义的任何问题托管在 PayPal 上。

问题

在下面的代码中,Configuration.GetAPIContext()card.Create(apiContext) 是成功的。我正在使用 Fiddler 进行跟踪并且可以看到 2xx 响应并且这些调用没有抛出异常。

但是,在调用 payment.Create(apiContext) 时抛出异常:

PayPal.PaymentsException was unhandled by user code   
HResult=-2146233088   
Message=The remote server returned an error: (400) Bad Request.   
Response={"name":"UNKNOWN_ERROR","message":"An unknown error has occurred", "information_link":"https://developer.paypal.com/webapps/developer/docs/api/#UNKNOWN_ERROR", "debug_id":"2ae8b36c6ea98"}   
Source=PayPal   
StackTrace:      
   at PayPal.Api.PayPalResource.ConfigureAndExecute[T](APIContext apiContext, HttpMethod httpMethod, String resource, String payload, String endpoint, Boolean setAuthorizationHeader) in C:\Documents\Downloads\PayPal-NET-SDK-develop\PayPal-NET-SDK-develop\Source\SDK\Api\PayPalResource.cs:line 208      
   at PayPal.Api.Payment.Create(APIContext apiContext, Payment payment) in C:\Documents\Downloads\PayPal-NET-SDK-develop\PayPal-NET-SDK-develop\Source\SDK\Api\Payment.cs:line 140      
   at PayPal.Api.Payment.Create(APIContext apiContext) in C:\Documents\Downloads\PayPal-NET-SDK-develop\PayPal-NET-SDK-develop\Source\SDK\Api\Payment.cs:line 124      

更多信息

异常中没有信息说明原因。请注意,同样的功能似乎在 PayPal's developer site 上失败了。还有!以及从示例应用程序本身运行时失败。

代码

using PayPal.Api;
using PayPal.Sample;

protected void TestCreditCardPayment()
{
  var apiContext = Configuration.GetAPIContext();

  // First vault a credit card.
  var card = new CreditCard
  {
    expire_month = 11,
    expire_year = 2018,
    number = "4877274905927862",
    type = "visa",
    cvv2 = "874"
  };
  var createdCard = card.Create(apiContext);

  // Next, create the payment authorization using the vaulted card as the funding instrument.
  var payment = new Payment
  {
    intent = "authorize",
    payer = new Payer
    {
      payment_method = "credit_card",
      funding_instruments = new List<FundingInstrument>
    {
        new FundingInstrument
        {
            credit_card_token = new CreditCardToken
            {
                credit_card_id = createdCard.id,
                expire_month = createdCard.expire_month,
                expire_year = createdCard.expire_year
            }
        }
    }
    },
    transactions = new List<Transaction>
    {
        new Transaction
        {
            amount = new Amount
            {
                currency = "USD",
                total = "1.00"
            },
            description = "This is the payment transaction description."
        }
    }
  };
  var createdPayment = payment.Create(apiContext);
}

最佳答案

问题在于沙箱如何处理该特定卡号。您应该能够使用此处的第 4 步生成新的测试卡号:https://www.paypal-knowledge.com/infocenter/index?page=content&id=FAQ1413&expand=true&locale=en_US

只要卡片通过了 LUHN 算法就可以了,可以使用其他测试卡号生成器。

关于paypal - 调用 payment.Create() 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37417523/

相关文章:

paypal - 使用 Paypal 沙箱测试应用程序

asp.net - 具有快速结账功能的 Paypal 获取 BillingAgreementID

php - notify_url 未达到或可能是沙盒 paypal 中的错误响应

python - django-paypal 无法处理通知信号

php - 如何使用 PHP 解析来自 PayPal API 的 SOAP 响应?

paypal - 如何验证 Paypal 引用交易是否已启用

Paypal 定期付款未检索交易 ID

testing - 如何使用沙箱进行网站支付标准?

Paypal 订阅 : Can I make the first payment different ammount?

javascript - 使用单独的 Javascript 函数提交隐藏的 PayPal 表单