Credit Card Payments using ActiveMerchant and

56 sec read

If you want to integrate Credit Card Payments for a web-applications, check out this blog on working with ActiveMerchant and payment gateways.

The first requirement is to obtain a test-account from from For integration on Credit-Card Payments made through website, a No Card Account is required. When you register for a test account sends you the API Key and Transaction Key for authentication at the gateways.
Create a credit card object that will be used later for the billing process as following:
[source language=”ruby”]
credit_card =
:number => ‘Test Credit Card Number’,
:verification_value => ‘123’,
:month => 8, #for test cards, use any date in the future
:year => 2018,
:first_name => ‘test’,
:last_name => ‘user’,
:type => ‘Test Credit Card Type’ )
The following code makes a call to the ActiveMerchant Gateway.
[source language=”ruby”]
gateway = ActiveMerchant::Billing::Base.gateway(:authorized_net).new(
:login =>Your API Login ID’, :password =>’Transaction Key’, :test => true)
Rest of the logic is quite simple,
[source language=”ruby”]
if credit_card.valid?
response = gateway.authorize(amount_to_charge*100 , credit_card, :billing_address =>
{ :name =>’Mark McBride’,
:address1 => ’33 New Montgomery St.’,
:city => ‘San Francisco’,
:state => ‘CA’,
:country => ‘US’,
:zip => ‘760001’,
:phone => ‘(555)555-5555′} )
if response.success?
gateway.capture(amount_to_charge, response.authorization)
render :text =>’Success:’ + response.message.to_s and return
render :text => ‘Fail:’ + response.message.to_s and return
render :text =>’Credit card not valid: ‘ + credit_card.validate.to_s and return

Related posts:

One Reply to “Credit Card Payments using ActiveMerchant and”

Leave a Reply

Your email address will not be published. Required fields are marked *