Class: ActiveMerchant::Billing::EwayRapidGateway
- 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
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ EwayRapidGateway
constructor
A new instance of EwayRapidGateway.
-
#purchase(amount, payment_method, options = {}) ⇒ Object
Public: Run a purchase transaction.
-
#setup_purchase(amount, options = {}) ⇒ Object
Public: Acquire the token necessary to run a transparent redirect.
-
#status(identification) ⇒ Object
Public: Retrieve the status of a transaction.
-
#store(payment_method, options = {}) ⇒ Object
Public: Store card details and return a valid token.
Methods inherited from Gateway
#card_brand, card_brand, inherited, supports?, #test?
Methods included from CreditCardFormatting
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( = {}) requires!(, :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, ={}) 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, .merge(:redirect_url => "http://example.com/"))} r.process{run_purchase(r., payment_method, r.params["formactionurl"])} r.process{status(r.)} 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, ={}) requires!(, :redirect_url) request = build_xml_request("CreateAccessCodeRequest") do |doc| (doc, ) add_invoice(doc, amount, ) add_customer_data(doc, ) 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, = {}) requires!(, :billing_address) purchase(0, payment_method, .merge(:request_method => "CreateTokenCustomer")) end |