首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调用payment.Create()时出错

调用payment.Create()时出错
EN

Stack Overflow用户
提问于 2016-05-24 15:11:20
回答 1查看 892关注 0票数 1

动机

我想在我的网站上接受信用卡。我之所以选择PayPal,是因为它们似乎是最不麻烦、也不算糟糕的利率,我想尽快开始接受信用卡。我选择信用卡支付,因为我不希望我的网站用户去PayPal网站,我希望他们留在我的网站。这看起来更令人印象深刻和专业。

我做了什么,

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

The Issue

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

但是,在调用payment.Create(apiContext)时会引发异常:

代码语言:javascript
复制
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的开发者网站上也失败了!以及在从示例应用程序本身运行时失败。

代码

代码语言:javascript
复制
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);
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-01 14:36:46

问题是沙箱如何处理特定的卡号。您应该能够使用以下步骤4生成一个新的测试卡号:我们

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37417523

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档