Created
March 7, 2012 12:32
-
-
Save joelcogen/1992846 to your computer and use it in GitHub Desktop.
Add Ogone payment to your Rails app with active_merchant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gem 'activemerchant' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Refund 10 EUR | |
| refund_response = OGONE_GATEWAY.refund(1000, response.authorization) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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