Now I'm earning my keep.
Trying to get your sample_transaction.rb
up and running I got this error:
➜ activemerchant-demo ruby sample_transaction.rb
/home/nathan/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activemerchant-1.42.6/lib/active_merchant/billing/gateways/authorize_net.rb:288:in `success?': undefined method `exclude?' for ["310", "311"]:Array (NoMethodError)
from /home/nathan/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activemerchant-1.42.6/lib/active_merchant/billing/gateways/authorize_net.rb:278:in `commit'
from /home/nathan/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activemerchant-1.42.6/lib/active_merchant/billing/gateways/authorize_net.rb:117:in `purchase'
from sample_transaction.rb:30:in `<main>'
So, I dug into the ActiveMerchant source code and found it was coming from here:
def success?(response)
response[:response_code] == APPROVED && TRANSACTION_ALREADY_ACTIONED.exclude?(response[:response_reason_code])
end
That TRANSACTION_ALREADY_ACTIONED
constant is an Array:
TRANSACTION_ALREADY_ACTIONED = %w(310 311)
The second part of the &&
statement was added just a few weeks ago.
But, there's no exclude?
method on a ruby array!!!
*googles ruby exclude? method*
Aha! The exclude?
method is added to Enumerable
by ActiveSupport
! This code will only work in Rails!!
Or... we can add require 'active_support/all'
to sample_transaction.rb
.
➜ activemerchant-demo ruby sample_transaction.rb
The transaction was successful! The authorization is 2207330213
{"response_code"=>1, "response_reason_code"=>"1", "response_reason_text"=>"This transaction has been approved.", "avs_result_code"=>"Y", "transaction_id"=>"2207330213", "card_code"=>"P", "authorization_code"=>"WQQA6J", "cardholder_authentication_code"=>"2", "action"=>"AUTH_CAPTURE"}