Using ActiveMerchant you will get:
- Support for too many payment gateways
- Bogus gateway for testing all payment functions that can done on actual gateways (except recurring).
- Validates credit card format
- You can install ActiveMerchant as gem:
gem install activemerchant
or as plugin
ruby script/plugin install http://activemerchant.googlecode.com/svn/trunk/active_merchant - Create a credit card object:
credit_card = ActiveMerchant::Billing::CreditCard.new({
:number => 5105105105105100,
:month => 9,
:year => Time.now.year + 1,
:first_name => 'test',
:last_name => 'account',
:verification_value => '123',
:type => 'visa'
})
You can check if the given credit card information is valid or not:
puts credit_card.errors.to_json if !credit_card.valid? - Create a bogus gateway instance:
@gateway = ActiveMerchant::Billing::BogusGateway.new(
:login => 'bogus',
:password => 'bogus'
) - Now, you can use the bogus gateway instance to process any e-commerce request you want (authorize, purchase, credit, etc)
response = @gateway.authorize(1000, @creditcard, @options)
response = @gateway.purchase(1000, @creditcard, @options)
Note: 1000 = 10$ (credit values in cents) - If your application uses default currency different than the default currency in the targeted payment gateway, you need to initialize ActiveMerchant with your required currency. To do that, add the default currency in your environment configuration file:
ActiveMerchant::Billing::PaypalExpressGateway.default_currency = 'GBP'
or you can pass the currency in each interaction with the gateway:
:currency => 'GBP'
Using the bogus gateway in your test will not help you in testing all credit card types (master card, visa, etc). Bogus gateway support only one card type "bogus" :).
Check the full documentation for ActiveMerchant.
1 comment:
Wael,
That is a great summary and intro to ActiveMerchant. One thing to note is that we've recently moved over to github, so you can install the plugin from there now: ruby script/plugin install git://github.com/Shopify/active_merchant.git
Post a Comment