Class: ActiveMerchant::Billing::EwayManagedGateway

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

Defined Under Namespace

Classes: EwayResponse

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?

Methods included from CreditCardFormatting

#format

Constructor Details

#initialize(options = {}) ⇒ EwayManagedGateway

Returns a new instance of EwayManagedGateway.



24
25
26
27
28
29
30
31
32
# File 'lib/active_merchant/billing/gateways/eway_managed.rb', line 24

def initialize(options = {})
  requires!(options, :login, :username, :password)
  @options = options

  # eWay returns 500 code for faults, which AM snaffles.
  # So, we tell it to allow them.
  @options[:ignore_http_status]=true
  super
end

Instance Method Details

#purchase(money, billing_id, options = {}) ⇒ Object

Process a payment in the given amount against the stored credit card given by billing_id

Parameters

  • money – The amount to be purchased as an Integer value in cents.

  • billing_id – The eWay provided card/customer token to charge (managedCustomerID)

  • options – A hash of optional parameters.

Options

  • :order_id – The order number, passed to eWay as the “Invoice Reference”

  • :invoice – The invoice number, passed to eWay as the “Invoice Reference” unless :order_id is also given

  • :description – A description of the payment, passed to eWay as the “Invoice Description”



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

def purchase(money, billing_id, options={})        
  post = {}  
  post[:managedCustomerID] = billing_id.to_s
  post[:amount]=money
  add_invoice(post, options)
  
  commit("ProcessPayment", post)
end

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

add a new customer CC to your eway account and return unique ManagedCustomerID supports storing details required by eway see “add_creditcard” and “add_address”



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/active_merchant/billing/gateways/eway_managed.rb', line 36

def store(creditcard, options = {})
  post = {}
  
  # Handle our required fields
  requires!(options, :billing_address)

  # Handle eWay specific required fields.
  billing_address = options[:billing_address]
  eway_requires!(billing_address)
  
  add_creditcard(post, creditcard)
  add_address(post, billing_address)
  add_misc_fields(post, options)
       
  commit("CreateCustomer", post)
end

#test?Boolean

TODO: eWay API also provides QueryCustomer TODO: eWay API also provides QueryPayment

Returns:

  • (Boolean)


96
97
98
# File 'lib/active_merchant/billing/gateways/eway_managed.rb', line 96

def test?
  @options[:test] || Base.gateway_mode == :test
end

#update(billing_id, creditcard, options = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/active_merchant/billing/gateways/eway_managed.rb', line 53

def update(billing_id, creditcard, options={})
  post = {}
  
  # Handle our required fields
  requires!(options, :billing_address)

  # Handle eWay specific required fields.
  billing_address = options[:billing_address]
  eway_requires!(billing_address)
  
  post[:managedCustomerID]=billing_id
  add_creditcard(post, creditcard)
  add_address(post, billing_address)
  add_misc_fields(post, options)
       
  commit("UpdateCustomer", post)
end