Ruby on Rails Activemerchant集成 - 传递变量

时间:2012-01-23 14:43:04

标签: ruby-on-rails paypal activemerchant

我使用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?

1 个答案:

答案 0 :(得分: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