我正在开发一款具有paypal交易功能的应用。我正在使用'paypal-sdk-rest'
gem来建立与paypal api的连接,但是我在尝试将多个项目传递到购物车时遇到了麻烦。
让我们看一下这个例子,说明我在说什么。
这有效:
payment = {
:intent => "sale",
:payer => {:payment_method => "paypal"},
:transactions =>
[{
:amount => {
:total => '500',
:currency => "USD" },
:item_list => {
:items => { :name => "pizza", :sku => "pizza", :price => '500', :currency => "USD", :quantity => 1 },
},
:description => "Some description"
}],
:redirect_urls => {
:return_url => "http://localhost:3000/somepath",
:cancel_url => "http://localhost:3000/otherpath"
}
}
@payment = Payment.new(payment)
@payment.create
但这没有(在项目列表中添加了一个项目):
payment = {
:intent => "sale",
:payer => {:payment_method => "paypal"},
:transactions =>
[{
:amount => {
:total => '500',
:currency => "USD" },
:item_list => {
:items => [{ :name => "pizza", :sku => "pizza", :price => '500', :currency => "USD", :quantity => 1 },{ :name => "pizza2", :sku => "pizza2", :price => '1000', :currency => "USD", :quantity => 1 }],
},
:description => "Some description"
}],
:redirect_urls => {
:return_url => "http://localhost:3000/somepath",
:cancel_url => "http://localhost:3000/otherpath"
}
}
@payment = Payment.new(payment)
@payment.create
我想要的东西与第二个类似,因为我想在交易中添加许多物品,实际上是我购物车中的每件物品。我的问题清楚了吗?
任何帮助都会非常感激,因为我一整天都试图解决这个问题并尝试了一切,但没有运气。
答案 0 :(得分:0)
我终于得到了解决方案!问题是,总金额必须与所添加物品的总价格一致。因此,在该示例中,错误是:total
必须是'1500'
而不是'500'
,因为两个商品价格的总和为1500
。