Posts Tagged ‘activemerchant’

ActiveMerchant and Authorize.net Refunds / Credits

September 23rd, 2008

I’ve been using ActiveMerchant on several eCommerce projects (written with Ruby on Rails). It works great, and I love the fact Cody is offering this code open source on github. When I have used it for processing orders it does so without a hitch. I did recently run into a problem using it to process refunds (credits). The issue lies with Authorize.net requiring more information than is provided by the credit method in ActiveMerchant. I have posted a patch to the ActiveMerchant guys and you can also find the code here. (It’s a simple but essential change).

Authorized.net has changed their requirements for processing a refund/credit. ActiveMerchant only has card_number as required, but now first_name, last_name and zip are required.

Below is the method fixed to work with Authorize.net (active_merchant/lib/active_merchant/billing/gateways/authorize_net.rb) lines 123-147:

# Credit an account.
#
# This transaction is also referred to as a Refund and indicates to the gateway that
# money should flow from the merchant to the customer.
#
# ==== Parameters
#
# * <tt>money</tt> — The amount to be credited to the customer. Either an Integer value in cents or a Money object.
# * <tt>identification</tt> — The ID of the original transaction against which the credit is being issued.
# * <tt>options</tt> — A hash of parameters.
#
# ==== Options
#
# * <tt>:card_number</tt> — The credit card number the credit is being issued to. (REQUIRED)
# * <tt>:first_name</tt> — The billTo fisrt name associated with the credit card and transaction. (REQUIRED)
# * <tt>:last_name</tt> — The billTo last name associated with the credit card and transaction. (REQUIRED)
# * <tt>:zip</tt> — The zip code associated with the billTo address used with the transaction. (REQUIRED)

def credit(money, identification, options = {})
requires!(options, :card_number, :first_name, :last_name, :zip)

post = { :trans_id => identification,
:card_num => options[:card_number],
:first_name => options[:first_name],
:last_name => options[:last_name],
:zip => options[:zip]
}
add_invoice(post, options)

commit(‘CREDIT’, money, post)
end