Question

I am trying to register a test credit card so I could test my application. I am using ActiveMerchant. I have a registration form where user inputs data and then I collect the parameters, and transfer it to payment, but I am only getting a nil as a response.

I have a code like this:

user.rb

def store_credit_card(payment_attributes)
    pay = Payment.new(payment_attributes) # this return always nil. Why?
    pay.build_contact_info
    pay.contact_info.name = name
    pay.contact_info.email = email
    pay.contact_info.phone = phone
    pay.first_name = first_name
    pay.last_name = last_name
    pay.construct_billing_address(self)
    pay.escrow_amount = (0.01).to_money

    pay.authorize!
  end

I transfer parameters to store_credit_card and they look like this:

payment_attributes
{"card_type"=>"bogus", "card_number"=>"1", "card_expires_month"=>"12", "card_expires_year"=>"2015", "security_code"=>"123"}

But when I call:

pay = Payment.new(payment_attributes)

the pay is always returning a nil.

What should I do in order to make it possible to register a bogus card with ActiveMerchant? And why it is returning a nil? I am developing in my local development environment. I am using Ubuntu.

Was it helpful?

Solution

Hi have fond an answer to my own question. After digging in deeper into debugger and stepping into a Payment methods, I have found out that the zip code that I was transferring to ActiveMerchant was reporting an error. But the error itself didn't report on some upper level functions, which is strange. Anyway, the error was that I was sending a json data wich have had

billing_attributes { zipcode: $scope.zipcode}

But when I have looked at my view, I have found that I have used ng-model zipcode I have accidentally missed _ in the data that is sent to the ActiveMerchant, it should have been:

billing_attributes { zip_code: $scope.zipcode}

All this problem because of typo. Not a big problem, but wanted to note the place where to first look if someone runs on this problem. The data seemed good, but for all others please pay attention if the data you are sending is really formatted like it should.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top