First, make sure you have everything setup correctly and all of your dependencies in place with:
require 'rubygems' require 'active_merchant'
ActiveMerchant expects the amounts to be given as an Integer in cents. In this case, $10 US becomes 1000.
tendollar = 1000
Next, create a credit card object using a TC approved test card.
creditcard = ActiveMerchant::Billing::CreditCard.new( :number => '4111111111111111', :month => 8, :year => 2006, :first_name => 'Longbob', :last_name => 'Longsen' ) options = { :order_id => '1230123', :email => 'bob@testbob.com', :address => { :address1 => '47 Bobway', :city => 'Bobville', :state => 'WA', :country => 'Australia', :zip => '2000' } :description => 'purchased items' }
To finish setting up, create the active_merchant object you will be using, with the eWay gateway. If you have a functional eWay account, replace :login with your account info.
gateway = ActiveMerchant::Billing::Base.gateway(:eway).new(:login => '87654321')
Now we are ready to process our transaction
response = gateway.purchase(tendollar, creditcard, options)
Sending a transaction to TrustCommerce with active_merchant returns a Response object, which consistently allows you to:
1) Check whether the transaction was successful
response.success?
2) Retrieve any message returned by eWay, either a “transaction was successful” note or an explanation of why the transaction was rejected.
response.message
3) Retrieve and store the unique transaction ID returned by eWway, for use in referencing the transaction in the future.
response.authorization
This should be enough to get you started with eWay and active_merchant. For further information, review the methods below and the rest of active_merchant’s documentation.
ewayCustomerEmail, ewayCustomerAddress, ewayCustomerPostcode
# File lib/active_merchant/billing/gateways/eway.rb, line 145 def purchase(money, creditcard, options = {}) requires!(options, :order_id) post = {} add_creditcard(post, creditcard) add_address(post, options) add_customer_data(post, options) add_invoice_data(post, options) # The request fails if all of the fields aren't present add_optional_data(post) commit(money, post) end
Generated with the Darkfish Rdoc Generator 2.