【问题标题】:Ruby on Rails Activemerchant integration - Passing variablesRuby on Rails Activemerchant 集成 - 传递变量
【发布时间】:2012-01-23 14:43:04
【问题描述】:

我已经使用 activemerchant 和 paypal 在我的应用中设置了定期付款。所有代码都在带有测试数据的控制器上运行,我从这里得到成功消息返回:

credit_card = {
:type => "visa",
:number => "4402526063652333",
:verification_value => '122',
:month => '06',
:year => '2016',
:first_name => 'Test Name',
:last_name => 'Test Account',
:street_1 => 'Test Street',
:city => 'Test city',
:state => 'Heref',
:country => 'US',
:zip => '111111',
:email => 'test@test.com'
}

但是,我希望它能够在我的应用中使用表单提供的信用卡详细信息。但是细节从来没有像这样从表单到控制器设置:

credit_card = {
:type => :card_type,
:number => :card_number,
:verification_value => :card_verification,
:month => :card_month,
:year => :card_year,
:first_name => 'Test Name',
:last_name => 'Test Account',
:street_1 => 'Test Street',
:city => 'Test city',
:state => 'Heref',
:country => 'US',
:zip => '111111',
:email => 'test@test.com'
}

我是否需要将其移动到模型中以使表单中的卡值传递到 :card_number 中?

【问题讨论】:

    标签: ruby-on-rails paypal activemerchant


    【解决方案1】:

    你可能想要:

    credit_card = {
      :type => params[:card_type],
      :number => params[:card_number],
      :verification_value => params[:card_verification],
      :month => params[:card_month],
      :year => params[:card_year],
      # ...
    

    因为params 是您从表单中获得的 HTTP 参数值的哈希值。

    您可以通过在发出请求时将params 的值打印到控制台来检查您是否获得了预期的值。将此代码添加到您的控制器操作中:p params

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-05
      • 2010-12-06
      • 1970-01-01
      • 2013-10-04
      • 1970-01-01
      • 1970-01-01
      • 2013-09-18
      • 1970-01-01
      相关资源
      最近更新 更多