【发布时间】:2014-05-30 14:15:53
【问题描述】:
您好,我知道这是一个菜鸟问题,但我找不到任何文件,我想在同一笔交易中支付 1 件或多件商品,但我收到此错误:
Exception in HttpConnection Execute: Invalid HTTP response The remote server returned an error: (400) Bad Request.
我对项目列表部分进行了硬编码,但我不明白 Amount.Total 和我所有项目价格 * 数量之间的差异
public ActionResult CreatePayment(string description, decimal price, decimal tax = 0, decimal shipping = 0)
{
var viewData = new PayPalViewData();
var guid = Guid.NewGuid().ToString();
var paymentInit = new Payment
{
intent = "authorize",
payer = new Payer
{
payment_method = "paypal"
},
transactions = new List<Transaction>
{
new Transaction
{
item_list = new ItemList{
items = new List<Item>{
new Item{
name = "item 1",
currency = "USD",
price = "20",
quantity = "2"
},
new Item{
name = "item 2",
currency = "USD",
price = "40",
quantity = "1"
},
new Item{
name = "item 3",
currency = "USD",
price = "40",
quantity = "1"
}
}
},
amount = new Amount
{
currency = "EUR",
total = (price + tax + shipping).ToString(),
details = new Details
{
subtotal = price.ToString(),
tax = tax.ToString(),
shipping = shipping.ToString()
}
},
description = description
},
},
redirect_urls = new RedirectUrls
{
return_url = Utilities.ToAbsoluteUrl(HttpContext, String.Format("~/paypal/confirmed?id={0}", guid)),
cancel_url = Utilities.ToAbsoluteUrl(HttpContext, String.Format("~/paypal/canceled?id={0}", guid)),
},
};
viewData.JsonRequest = JObject.Parse(paymentInit.ConvertToJson()).ToString(Formatting.Indented);
try
{
var accessToken = new OAuthTokenCredential(ConfigManager.Instance.GetProperties()["ClientID"], ConfigManager.Instance.GetProperties()["ClientSecret"]).GetAccessToken();
var apiContext = new APIContext(accessToken);
var createdPayment = paymentInit.Create(apiContext);
var approvalUrl = createdPayment.links.ToArray().FirstOrDefault(f => f.rel.Contains("approval_url"));
if (approvalUrl != null)
{
Session.Add(guid, createdPayment.id);
return Redirect(approvalUrl.href);
}
viewData.JsonResponse = JObject.Parse(createdPayment.ConvertToJson()).ToString(Formatting.Indented);
return View("Error", viewData);
}
catch (PayPalException ex)
{
viewData.ErrorMessage = ex.Message;
return View("Error", viewData);
}
}
如果我删除项目列表,它可以工作,但数量中只描述了 1 个项目 我能做些什么?你有这方面的指南吗? Paypal 指南和演示仅适用于一项
谢谢
【问题讨论】:
-
谢谢,但我不想在视图中这样做,并且贝宝链接是经典 api,我使用的是 Rest api,它没有示例代码,只有商家的费用和其他信息
-
那我猜你得自己写一些代码了。
-
你解决过这个问题吗?遇到类似的问题
标签: c# asp.net-mvc paypal shopping-cart