Search code examples
ruby-on-railspaypalactivemerchant

Ruby on Rails Activemerchant integration - Passing variables


I've setup recurring payments in my app using activemerchant and paypal. All the code is run off the controller with the test data and i'm getting success message return from this:

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'
}

However I want this to work in my app with the credit card details supplied by a form. But the details never make it from the form to the controller setup like this:

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'
}

Do I need to move this to the model to make the card value from the form pass into :card_number?


Solution

  • You probably want:

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

    Since params is the hash of HTTP parameter values you get from the form.

    You can check that you're getting the values you expect by printing the value of params to the console when you make a request. Add this code to your controller action: p params.