【问题标题】:How to use PayPal for checkout in rails4如何在 rails4 中使用 PayPal 进行结帐
【发布时间】:2014-11-07 15:00:29
【问题描述】:

我正在尝试将 PayPal 电子支付添加到我的 RoR 应用程序中。所以我继续如下: 我的 panier.rb:

class Panier < ActiveRecord::Base
  belongs_to :user



 def paypal_url(return_path)
values = {
    :business => 'r.karoui-buyer@loganddrive.com',
    :cmd => '_cart',
    :upload => 1,
    :return => return_path,
    :invoice => id
}
line_items.each_with_index do |item, index|
  values.merge!({
                    "amount_#{index+1}" => item.price,
                    "item_name_#{index+1}" => item.book.title,
                    "item_number_#{index+1}" => item.id,
                    "quantity_#{index+1}" => 1
                })
  end

 "#{Rails.application.secrets.paypal_host}/cgi-bin/webscr?" + values.to_query
end
end

我的 details.html.erb:我在哪里调用 PayPal 服务

<%= @panier.book_id %> | <%= @panier.price %> | <%= link_to 'acheter' , @panier.paypal_url(paniers_path) %>

但我收到了这个错误:

用于#的未定义局部变量或方法`line_items'

我只是遵循这个 railsCast 教程:

http://railscasts.com/episodes/141-paypal-basics

我应该用什么代替 line_items.each_with_index do |item, index|如果这里是错误,如果不是,请帮助我找出问题所在

【问题讨论】:

    标签: paypal ruby-on-rails-4.1


    【解决方案1】:

    试试

    def paypal_url(return_path)
    values = {
        :business => 'r.karoui-buyer@loganddrive.com',
        :cmd => '_cart',
        :upload => 1,
        :return => return_path,
        :invoice => id
    }
    
     values.merge!({
                    "amount_#{index+1}" => item.price,
                    "item_name_#{index+1}" => item.book.title,
                    "item_number_#{index+1}" => item.id,
                    "quantity_#{index+1}" => 1
                })
    
    
     "#{Rails.application.secrets.paypal_host}/cgi-bin/webscr?" + values.to_query
    end
    

    【讨论】:

      猜你喜欢
      • 2013-10-26
      • 2014-05-13
      • 2012-05-05
      • 2014-05-08
      • 2014-12-12
      • 2015-03-14
      • 2015-12-30
      • 2014-09-06
      • 2014-10-21
      相关资源
      最近更新 更多