Class: ActiveMerchant::Billing::PaymentExpressGateway

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

Overview

In NZ DPS supports ANZ, Westpac, National Bank, ASB and BNZ. In Australia DPS supports ANZ, NAB, Westpac, CBA, St George and Bank of South Australia. The Maybank in Malaysia is supported and the Citibank for Singapore.

Constant Summary collapse

APPROVED =
'1'
TRANSACTIONS =
{
  :purchase       => 'Purchase',
  :credit         => 'Refund',
  :authorization  => 'Auth',
  :capture        => 'Complete',
  :validate       => 'Validate'
}

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 = {}) ⇒ PaymentExpressGateway

We require the DPS gateway username and password when the object is created.

The PaymentExpress gateway also supports a :use_custom_payment_token boolean option. If set to true the gateway will use BillingId for the Token type. If set to false, then the token will be sent as the DPS specified “DpsBillingId”. This is per the documentation at www.paymentexpress.com/technical_resources/ecommerce_nonhosted/pxpost.html#Tokenbilling



42
43
44
45
46
47
48
# File 'lib/active_merchant/billing/gateways/payment_express.rb', line 42

def initialize(options = {})
  # A DPS username and password must exist
  requires!(options, :login, :password)
  # Make the options an instance variable
  @options = options
  super
end

Instance Method Details

#authorize(money, payment_source, options = {}) ⇒ Object

NOTE: Perhaps in options we allow a transaction note to be inserted Verifies that funds are available for the requested card and amount and reserves the specified amount. See: www.paymentexpress.com/technical_resources/ecommerce_nonhosted/pxpost.html#Authcomplete

‘payment_source` can be a usual ActiveMerchant credit_card object or a token, see #purchased method



67
68
69
70
# File 'lib/active_merchant/billing/gateways/payment_express.rb', line 67

def authorize(money, payment_source, options = {})
  request = build_purchase_or_authorization_request(money, payment_source, options)
  commit(:authorization, request)
end

#capture(money, identification, options = {}) ⇒ Object



74
75
76
77
# File 'lib/active_merchant/billing/gateways/payment_express.rb', line 74

def capture(money, identification, options = {})
  request = build_capture_or_credit_request(money, identification, options)                                            
  commit(:capture, request)
end

#credit(money, identification, options = {}) ⇒ Object



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

def credit(money, identification, options = {})
  deprecated CREDIT_DEPRECATION_MESSAGE
  refund(money, identification, options)
end

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

Funds are transferred immediately.

‘payment_source` can be a usual ActiveMerchant credit_card object, or can also be a string of the `DpsBillingId` or `BillingId` which can be gotten through the store method. If you are using a `BillingId` instead of `DpsBillingId` you must also set the instance method `#use_billing_id_for_token` to true, see the `#store` method for an example of how to do this.



57
58
59
60
# File 'lib/active_merchant/billing/gateways/payment_express.rb', line 57

def purchase(money, payment_source, options = {})
  request = build_purchase_or_authorization_request(money, payment_source, options)
  commit(:purchase, request)      
end

#refund(money, identification, options = {}) ⇒ Object

Refund funds to the card holder



80
81
82
83
84
85
# File 'lib/active_merchant/billing/gateways/payment_express.rb', line 80

def refund(money, identification, options = {})
  requires!(options, :description)
  
  request = build_capture_or_credit_request(money, identification, options)                                            
  commit(:credit, request)
end

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

Token Based Billing

Instead of storing the credit card details locally, you can store them inside the Payment Express system and instead bill future transactions against a token.

This token can either be specified by your code or autogenerated by the PaymentExpress system. The default is to let PaymentExpress generate the token for you and so use the ‘DpsBillingId`. If you do not pass in any option of the `billing_id`, then the store method will ask PaymentExpress to create a token for you. Additionally, if you are using the default `DpsBillingId`, you do not have to do anything extra in the initialization of your gateway object.

To specify and use your own token, you need to do two things.

Firstly, pass in a ‘:billing_id` as an option in the hash of this store method. No validation is done on this BillingId by PaymentExpress so you must ensure that it is unique.

gateway.store(credit_card, {:billing_id => 'YourUniqueBillingId'})

Secondly, you will need to pass in the option ‘=> true` when initializing your gateway instance, like so:

gateway = ActiveMerchant::Billing::PaymentExpressGateway.new(
  :login    => 'USERNAME',
  :password => 'PASSWORD',
  :use_custom_payment_token => true
)

see: www.paymentexpress.com/technical_resources/ecommerce_nonhosted/pxpost.html#Tokenbilling

Note, once stored, PaymentExpress does not support unstoring a stored card.



123
124
125
126
# File 'lib/active_merchant/billing/gateways/payment_express.rb', line 123

def store(credit_card, options = {})
  request  = build_token_request(credit_card, options)
  commit(:validate, request)
end