Class: ActiveMerchant::Billing::EwayGateway
- Defined in:
- lib/active_merchant/billing/gateways/eway.rb
Overview
TO USE: First, make sure you have everything setup correctly and all of your dependencies in place with:
require 'rubygems'
require 'money'
require 'active_merchant'
The second line is a require for the ‘money’ library. Make sure you have it installed with ‘gem install money’
Using the money library, create a money object. Pass the dollar value in cents. In this case, $10 US becomes 1000.
tendollar = Money.us_dollar(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 = {
:login => '87654321',
:order_id => '1230123',
:email => '[email protected]',
:address => { :address1 => '47 Bobway, Bobville, WA, 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()
Now we are ready to process our transaction
response = gateway.purchase(tendollar, creditcard, )
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.
3) Retrieve and store the unique transaction ID returned by eWway, for use in referencing the transaction in the future.
response.
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.
Constant Summary collapse
- TEST_URL =
'https://www.eway.com.au/gateway/xmltest/testpage.asp'
- LIVE_URL =
'https://www.eway.com.au/gateway/xmlpayment.asp'
- TEST_CVN_URL =
'https://www.eway.com.au/gateway_cvn/xmltest/testpage.asp'
- LIVE_CVN_URL =
'https://www.eway.com.au/gateway_cvn/xmlpayment.asp'
- MESSAGES =
{ "00" => "Transaction was successfully processed", "A8" => "Amount is invalid", "A9" => "Card number is invalid", "AA" => "Account is invalid", "AB" => "Card expiry date is invalid", "01" => "Card verification number didn't match", "05" => "Card verification number didn't match" }
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ EwayGateway
constructor
A new instance of EwayGateway.
-
#purchase(money, creditcard, options = {}) ⇒ Object
ewayCustomerEmail, ewayCustomerAddress, ewayCustomerPostcode.
Methods inherited from Gateway
Methods included from RequiresParameters
Methods included from PostsData
Constructor Details
#initialize(options = {}) ⇒ EwayGateway
Returns a new instance of EwayGateway.
91 92 93 94 95 |
# File 'lib/active_merchant/billing/gateways/eway.rb', line 91 def initialize( = {}) requires!(, :login) @options = super end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
87 88 89 |
# File 'lib/active_merchant/billing/gateways/eway.rb', line 87 def @options end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
86 87 88 |
# File 'lib/active_merchant/billing/gateways/eway.rb', line 86 def response @response end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
85 86 87 |
# File 'lib/active_merchant/billing/gateways/eway.rb', line 85 def url @url end |
Class Method Details
.supported_cardtypes ⇒ Object
112 113 114 |
# File 'lib/active_merchant/billing/gateways/eway.rb', line 112 def self.supported_cardtypes [:visa, :master] end |
Instance Method Details
#purchase(money, creditcard, options = {}) ⇒ Object
ewayCustomerEmail, ewayCustomerAddress, ewayCustomerPostcode
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/active_merchant/billing/gateways/eway.rb', line 98 def purchase(money, creditcard, = {}) requires!(, :order_id) post = {} add_creditcard(post, creditcard) add_address(post, ) add_customer_data(post, ) add_invoice_data(post, ) # The request fails if all of the fields aren't present add_optional_data(post) commit(money, post) end |