调用 payment.Create() 时出错

Error calling payment.Create()

动机

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

我做了什么

我在沙盒上从 Paypal. I'm running with PayPal.dll version 1.7.3.0 I created a developer account 下载了 PayPal.SDK.NET451PayPal.SDK.Sample.VS.2013,但是对于这个实验,他们建议只使用 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算法就没问题,可以使用其他测试卡号生成器。