Skip to content

Instantly share code, notes, and snippets.

@joelcogen
Created March 7, 2012 12:32
Show Gist options
  • Save joelcogen/1992846 to your computer and use it in GitHub Desktop.
Save joelcogen/1992846 to your computer and use it in GitHub Desktop.
Add Ogone payment to your Rails app with active_merchant
OGONE_GATEWAY = ActiveMerchant::Billing::OgoneGateway.new(
:login => "login of your Ogone account (PDPID)",
:user => "username of API user (Userid)",
:password => "password for API user",
:signature => "SHA-IN Pass phrase",
:signature_encryptor => "sha512",
:test => true # Change to false when using your production account
)
# Freeze 10 EUR on the credit card
response = OGONE_GATEWAY.authorize(1000, credit_card)
# Charge the frozen 10 EUR
capture_response = OGONE_GATEWAY.capture(1000, response.authorization)
# Or unfreeze them
void_response = OGONE_GATEWAY.void(response.authorization)
gem 'activemerchant'
# Refund 10 EUR
refund_response = OGONE_GATEWAY.refund(1000, response.authorization)
credit_card = ActiveMerchant::Billing::CreditCard.new(
:first_name => 'John',
:last_name => 'Matrix',
:number => '4111 1111 1111 1111',
:month => 4,
:year => 2013,
:verification_value => 123 # CVC code
)
# Charge 10 EUR
response = OGONE_GATEWAY.purchase(1000, credit_card, :order_id => "1", :store => "john_matrix")
puts response.success? # Check whether the transaction was successful
puts response.message # Retrieve the message returned by Ogone
puts response.authorization # Retrieve the unique transaction ID returned by Ogone (you should save this somewhere)
# Storing at first purchase
response = OGONE_GATEWAY.purchase(1000, credit_card, :store => "john_matrix")
# Storing without a purchase
response = OGONE_GATEWAY.store(credit_card, :store => "john_matrix")
# Storing with an Ogone-generated alias
response = OGONE_GATEWAY.store(credit_card)
puts response.alias # Retrieve the generated alias
# Future purchases can now be made using the alias:
new_response = OGONE_GATEWAY.purchase(2000, "john_matrix")
# The alias can be used any time in place of the credit card:
new_response = OGONE_GATEWAY.authorize(1500, "john_matrix")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment