gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 16:07:07 25 4
gpt4 key购买 nike

动机

我想在我的网站上接受信用卡。我选择 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com