【问题标题】:Rails 4 - ActiveMerchant Paypal Express Checkout Issue with Passing Item QuantityRails 4 - ActiveMerchant Paypal Express 结帐问题与传递项目数量
【发布时间】: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


    【解决方案1】:

    愚蠢的老我。 Paypal 不断使我的交易无效,因为我传递了错误的信息。我将金额设置为 line_item total,这已经是数量 * product.price 的总数。所以 Paypal 收到的信息是数量 * (数量 * product.price)。

    愚蠢的小错误,但我最终设法抓住了它。

    # 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.price.in_cents}
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2012-06-30
      • 2014-11-26
      • 1970-01-01
      • 1970-01-01
      • 2011-06-01
      • 2015-10-24
      • 2011-05-10
      • 2014-10-21
      • 2011-05-28
      相关资源
      最近更新 更多