Class: ActiveMerchant::Billing::EwayRapidGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/eway_rapid.rb

Defined Under Namespace

Classes: EwayRapidResponse

Constant Summary

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, inherited, supports?, #test?

Methods included from CreditCardFormatting

#format

Constructor Details

#initialize(options = {}) ⇒ EwayRapidGateway

Returns a new instance of EwayRapidGateway.



17
18
19
20
# File 'lib/active_merchant/billing/gateways/eway_rapid.rb', line 17

def initialize(options = {})
  requires!(options, :login, :password)
  super
end

Instance Method Details

#purchase(amount, payment_method, options = {}) ⇒ Object

Public: Run a purchase transaction. Treats the Rapid 3.0 transparent redirect as an API endpoint in order to conform to the standard ActiveMerchant #purchase API.

amount - The monetary amount of the transaction in cents. options - A standard ActiveMerchant options hash:

:order_id         - A merchant-supplied identifier for the
                    transaction (optional).
:description      - A merchant-supplied description of the
                    transaction (optional).
:currency         - Three letter currency code for the
                    transaction (default: "AUD")
:billing_address  - Standard ActiveMerchant address hash
                    (optional).
:shipping_address - Standard ActiveMerchant address hash
                    (optional).
:ip               - The ip of the consumer initiating the
                    transaction (optional).
:application_id   - A string identifying the application
                    submitting the transaction
                    (default: "https://github.com/Shopify/active_merchant")

Returns an ActiveMerchant::Billing::Response object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/active_merchant/billing/gateways/eway_rapid.rb', line 45

def purchase(amount, payment_method, options={})
  MultiResponse.new.tap do |r|
    # Rather than follow the redirect, we detect the 302 and capture the
    # token out of the Location header in the run_purchase step. But we
    # still need a placeholder url to pass to eWay, and that is what
    # example.com is used for here.
    r.process{setup_purchase(amount, options.merge(:redirect_url => "http://example.com/"))}
    r.process{run_purchase(r.authorization, payment_method, r.params["formactionurl"])}
    r.process{status(r.authorization)}
  end
end

#setup_purchase(amount, options = {}) ⇒ Object

Public: Acquire the token necessary to run a transparent redirect.

amount - The monetary amount of the transaction in cents. options - A supplemented ActiveMerchant options hash:

:redirect_url     - The url to return the customer to after
                    the transparent redirect is completed
                    (required).
:order_id         - A merchant-supplied identifier for the
                    transaction (optional).
:description      - A merchant-supplied description of the
                    transaction (optional).
:currency         - Three letter currency code for the
                    transaction (default: "AUD")
:billing_address  - Standard ActiveMerchant address hash
                    (optional).
:shipping_address - Standard ActiveMerchant address hash
                    (optional).
:ip               - The ip of the consumer initiating the
                    transaction (optional).
:application_id   - A string identifying the application
                    submitting the transaction
                    (default: "https://github.com/Shopify/active_merchant")

Returns an EwayRapidResponse object, which conforms to the ActiveMerchant::Billing::Response API, but also exposes #form_url.



82
83
84
85
86
87
88
89
90
91
# File 'lib/active_merchant/billing/gateways/eway_rapid.rb', line 82

def setup_purchase(amount, options={})
  requires!(options, :redirect_url)
  request = build_xml_request("CreateAccessCodeRequest") do |doc|
    (doc, options)
    add_invoice(doc, amount, options)
    add_customer_data(doc, options)
  end

  commit(url_for("CreateAccessCode"), request)
end

#status(identification) ⇒ Object

Public: Retrieve the status of a transaction.

identification - The Eway Rapid 3.0 access code for the transaction

(returned as the response.authorization by
#setup_purchase).

Returns an EwayRapidResponse object.



100
101
102
103
104
105
# File 'lib/active_merchant/billing/gateways/eway_rapid.rb', line 100

def status(identification)
  request = build_xml_request("GetAccessCodeResultRequest") do |doc|
    doc.AccessCode identification
  end
  commit(url_for("GetAccessCodeResult"), request)
end

#store(payment_method, options = {}) ⇒ Object

Public: Store card details and return a valid token

options - A supplemented ActiveMerchant options hash:

:order_id         - A merchant-supplied identifier for the
                    transaction (optional).
:billing_address  - Standard ActiveMerchant address hash
                    (required).
:ip               - The ip of the consumer initiating the
                    transaction (optional).
:application_id   - A string identifying the application
                    submitting the transaction
                    (default: "https://github.com/Shopify/active_merchant")


119
120
121
122
# File 'lib/active_merchant/billing/gateways/eway_rapid.rb', line 119

def store(payment_method, options = {})
  requires!(options, :billing_address)
  purchase(0, payment_method, options.merge(:request_method => "CreateTokenCustomer"))
end