我正在尝试将Paypal集成到我的.net mvc项目中。我创建了一个应用程序,并在web.config和控制器中添加了代码(要查看代码,请参见下文)。 我可以在新帐户上进行一次交易,但是当我致电另一个交易时,它返回了交易失败:远程服务器返回了一个错误:(400)错误的请求。
以下是我的web.config代码
securitycheck=85b39cc89f04bc1612ce9d0c384b39ca
以下是我的控制器,该控制器调用贝宝api
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="paypal" type="PayPal.SDKConfigHandler, PayPal" />
</configSections>
<!-- PayPal SDK settings -->
<paypal>
<settings>
<add name="mode" value="sandbox" />
<!--<add name="clientId" value="AfLQXEBebCzqXtXyPYW987x5Zg75PXpTgYACmv8i9pMaWiMCN0U-FIkKPngd3WQ4YK9J-_gE1ZfMiQlb" />
<add name="clientSecret" value="EFNJZjqrmGkAY-W4-NmCRq-DgkEmCgRteDY_v4aBf6TTU55ZwARMj0399UfFZ5T7iExAtoqq3tdOuyd" />-->
<add name="clientId" value="AQ3-ATuhAujxd7-Y5BVOKw8fdlIt5KlDul1d0OIJ4hQavS0smxF0Np_MfO6tZXAcuYqklG33yycQnNvj" />
<add name="clientSecret" value="EA77LpQNkL8U6xH96A2VZTKXjdthToF8yFsw4SKRfGmY5iHMxTv_yxJXMxBHCeXVnNFF_EO5UOeDjq1Q" />
</settings>
</paypal>
答案 0 :(得分:1)
使用“以下代码”解决问题。
public Payment CreatePayment(APIContext apiContext, string redirectUrl)
{
//create itemlist and add item objects to it
var itemList = new ItemList() { items = new List<Item>() };
//Adding Item Details like name, currency, price etc
itemList.items.Add(new Item()
{
name = "Item Name comes here",
currency = "USD",
price = "4",
quantity = "1",
sku = "sku"
});
var payer = new Payer() { payment_method = "paypal" };
// Configure Redirect Urls here with RedirectUrls object
var redirUrls = new RedirectUrls()
{
cancel_url = redirectUrl + "&Cancel=true",
return_url = redirectUrl
};
// Adding Tax, shipping and Subtotal details
var details = new Details()
{
tax = "1",
shipping = "1",
subtotal = "4",
shipping_discount = "-1"
};
//Final amount with details
var amount = new Amount()
{
currency = "USD",
total = "5", // Total must be equal to sum of tax, shipping and subtotal.
details = details
};
var transactionList = new List<Transaction>();
// Adding description about the transaction
transactionList.Add(new Transaction()
{
description = "Transaction description",
invoice_number = Convert.ToString((new Random()).Next(100000)),
amount = amount,
item_list = itemList
});
this.payment = new Payment()
{
intent = "sale",
payer = payer,
transactions = transactionList,
redirect_urls = redirUrls
};
// Create a payment using a APIContext
return this.payment.Create(apiContext);
}
问候 欧姆卡。