【发布时间】:2014-04-26 00:48:43
【问题描述】:
我在使用 PayPal 快速结账时遇到了一个奇怪的问题。当我传入 options[:item][:quantity] 时,我从 PayPal 收到一个错误代码,表明交易无效。
#controllers/orders_controller.rb
def express
options = {
:ip => request.remote_ip,
:return_url => new_order_url,
:cancel_return_url => products_url,
:items => current_cart.line_items_hash
}
response = EXPRESS_GATEWAY.setup_purchase(current_cart.build_order.price_in_cents,
options)
redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token)
end
# models/cart.rb
def line_items_hash
self.line_items.map do |line_item|
{
:name => Product.find(line_item.product_id).name
# :quantity => line_item.quantity,
:description => line_item.product.description,
:amount => line_item.gross_price_in_cents}
end
end
所以这很好用。问题是 PayPal 订单确认页面上未显示正确的数量。但是,如果我取消注释 line_items_hash 函数中的数量变量,整个事情就会中断,我会得到“来自贝宝的无效交易”。有什么想法吗?
【问题讨论】:
标签: ruby-on-rails paypal ruby-on-rails-4 shopping-cart activemerchant