Skip to content

Instantly share code, notes, and snippets.

@rvalyi
Last active June 15, 2016 21:10
Show Gist options
  • Save rvalyi/92fed21b35ae27c9fce1e8ff61f2bdef to your computer and use it in GitHub Desktop.
Save rvalyi/92fed21b35ae27c9fce1e8ff61f2bdef to your computer and use it in GitHub Desktop.
ActiveMerchant::Billing::Base.mode = :test
Ooor.new(url: "http://154023-9-0-72d03e.runbot8.odoo.com", database: "154023-9-0-72d03e-all", username: "admin", password: "admin", models: ["payment.acquirer"])
gateway = OdooMerchant.gateway_for(:authorize)
amount = 1000 # $10.00
# The card verification value is also known as CVV2, CVC2, or CID
credit_card = ActiveMerchant::Billing::CreditCard.new(
:first_name => 'Bob',
:last_name => 'Bobsen',
:number => '4242424242424242',
:month => '8',
:year => Time.now.year+1,
:verification_value => '000')
# Validating the card automatically detects the card type
if credit_card.validate.empty?
# Capture $10 from the credit card
response = gateway.purchase(amount, credit_card)
if response.success?
puts "Successfully charged $#{sprintf("%.2f", amount / 100)} to the credit card #{credit_card.display_number}"
else
raise StandardError, response.message
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment