Class: ActiveMerchant::Billing::EwayGateway

Inherits:
Gateway
  • Object
show all
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, 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.

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Gateway

gateway, supports?, #test?

Methods included from RequiresParameters

#requires!

Methods included from PostsData

#included?, #ssl_post

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(options = {})
   requires!(options, :login)
   @options = options
   super
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



87
88
89
# File 'lib/active_merchant/billing/gateways/eway.rb', line 87

def options
  @options
end

#responseObject (readonly)

Returns the value of attribute response.



86
87
88
# File 'lib/active_merchant/billing/gateways/eway.rb', line 86

def response
  @response
end

#urlObject (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_cardtypesObject



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, 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