Class Index [+]

Quicksearch

ActiveMerchant::Billing::PaymentExpressGateway

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.

Constants

URL
APPROVED
TRANSACTIONS

Public Class Methods

new(options = {}) click to toggle source

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

    # File lib/active_merchant/billing/gateways/payment_express.rb, line 37
37:       def initialize(options = {})
38:         # A DPS username and password must exist 
39:         requires!(options, :login, :password)
40:         # Make the options an instance variable
41:         @options = options
42:         super
43:       end

Public Instance Methods

authorize(money, payment_source, options = {}) click to toggle source

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

    # File lib/active_merchant/billing/gateways/payment_express.rb, line 54
54:       def authorize(money, payment_source, options = {})
55:         request = build_purchase_or_authorization_request(money, payment_source, options)
56:         commit(:authorization, request)
57:       end
capture(money, identification, options = {}) click to toggle source

Transfer pre-authorized funds immediately See: www.paymentexpress.com/technical_resources/ecommerce_nonhosted/pxpost.html#Authcomplete

    # File lib/active_merchant/billing/gateways/payment_express.rb, line 61
61:       def capture(money, identification, options = {})
62:         request = build_capture_or_credit_request(money, identification, options)                                            
63:         commit(:capture, request)
64:       end
credit(money, identification, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/payment_express.rb, line 74
74:       def credit(money, identification, options = {})
75:         deprecated CREDIT_DEPRECATION_MESSAGE
76:         refund(money, identification, options)
77:       end
purchase(money, payment_source, options = {}) click to toggle source

Funds are transferred immediately.

    # File lib/active_merchant/billing/gateways/payment_express.rb, line 46
46:       def purchase(money, payment_source, options = {})
47:         request = build_purchase_or_authorization_request(money, payment_source, options)
48:         commit(:purchase, request)      
49:       end
refund(money, identification, options = {}) click to toggle source

Refund funds to the card holder

    # File lib/active_merchant/billing/gateways/payment_express.rb, line 67
67:       def refund(money, identification, options = {})
68:         requires!(options, :description)
69:         
70:         request = build_capture_or_credit_request(money, identification, options)                                            
71:         commit(:credit, request)
72:       end
store(credit_card, options = {}) click to toggle source

initiates a “Validate” transcation to store card data on payment express servers returns a “token” that can be used to rebill this card see: www.paymentexpress.com/technical_resources/ecommerce_nonhosted/pxpost.html#Tokenbilling PaymentExpress does not support unstoring a stored card.

    # File lib/active_merchant/billing/gateways/payment_express.rb, line 85
85:       def store(credit_card, options = {})
86:         request  = build_token_request(credit_card, options)
87:         commit(:validate, request)
88:       end

Private Instance Methods

add_address_verification_data(xml, options) click to toggle source
     # File lib/active_merchant/billing/gateways/payment_express.rb, line 171
171:       def add_address_verification_data(xml, options)
172:         address = options[:billing_address] || options[:address]
173:         return if address.nil?
174:         
175:         xml.add_element("EnableAvsData").text = 1
176:         xml.add_element("AvsAction").text = 1
177:         
178:         xml.add_element("AvsStreetAddress").text = address[:address1]
179:         xml.add_element("AvsPostCode").text = address[:zip]
180:       end
add_amount(xml, money, options) click to toggle source
     # File lib/active_merchant/billing/gateways/payment_express.rb, line 157
157:       def add_amount(xml, money, options)
158:         xml.add_element("Amount").text = amount(money)
159:         xml.add_element("InputCurrency").text = options[:currency] || currency(money)
160:       end
add_billing_token(xml, token) click to toggle source
     # File lib/active_merchant/billing/gateways/payment_express.rb, line 148
148:       def add_billing_token(xml, token) 
149:         xml.add_element("DpsBillingId").text = token
150:       end
add_credentials(xml) click to toggle source
     # File lib/active_merchant/billing/gateways/payment_express.rb, line 124
124:       def add_credentials(xml)
125:         xml.add_element("PostUsername").text = @options[:login]
126:         xml.add_element("PostPassword").text = @options[:password]
127:       end
add_credit_card(xml, credit_card) click to toggle source
     # File lib/active_merchant/billing/gateways/payment_express.rb, line 133
133:       def add_credit_card(xml, credit_card)
134:         xml.add_element("CardHolderName").text = credit_card.name
135:         xml.add_element("CardNumber").text = credit_card.number
136:         xml.add_element("DateExpiry").text = format_date(credit_card.month, credit_card.year)
137:         
138:         if credit_card.verification_value?
139:           xml.add_element("Cvc2").text = credit_card.verification_value
140:         end
141:         
142:         if requires_start_date_or_issue_number?(credit_card)
143:           xml.add_element("DateStart").text = format_date(credit_card.start_month, credit_card.start_year) unless credit_card.start_month.blank? || credit_card.start_year.blank?
144:           xml.add_element("IssueNumber").text = credit_card.issue_number unless credit_card.issue_number.blank?
145:         end
146:       end
add_invoice(xml, options) click to toggle source
     # File lib/active_merchant/billing/gateways/payment_express.rb, line 166
166:       def add_invoice(xml, options)
167:         xml.add_element("TxnId").text = options[:order_id].to_s.slice(0, 16) unless options[:order_id].blank?
168:         xml.add_element("MerchantReference").text = options[:description] unless options[:description].blank?
169:       end
add_reference(xml, identification) click to toggle source
     # File lib/active_merchant/billing/gateways/payment_express.rb, line 129
129:       def add_reference(xml, identification)
130:         xml.add_element("DpsTxnRef").text = identification
131:       end
add_token_request(xml, options) click to toggle source
     # File lib/active_merchant/billing/gateways/payment_express.rb, line 152
152:       def add_token_request(xml, options)
153:         xml.add_element("BillingId").text = options[:billing_id] if options[:billing_id]
154:         xml.add_element("EnableAddBillCard").text = 1
155:       end
add_transaction_type(xml, action) click to toggle source
     # File lib/active_merchant/billing/gateways/payment_express.rb, line 162
162:       def add_transaction_type(xml, action)
163:         xml.add_element("TxnType").text = TRANSACTIONS[action]
164:       end
build_capture_or_credit_request(money, identification, options) click to toggle source
     # File lib/active_merchant/billing/gateways/payment_express.rb, line 107
107:       def build_capture_or_credit_request(money, identification, options)
108:         result = new_transaction
109:       
110:         add_amount(result, money, options)
111:         add_invoice(result, options)
112:         add_reference(result, identification)
113:         result
114:       end
build_purchase_or_authorization_request(money, payment_source, options) click to toggle source
     # File lib/active_merchant/billing/gateways/payment_express.rb, line 92
 92:       def build_purchase_or_authorization_request(money, payment_source, options)
 93:         result = new_transaction      
 94: 
 95:         if payment_source.is_a?(String)
 96:           add_billing_token(result, payment_source)
 97:         else
 98:           add_credit_card(result, payment_source)
 99:         end
100:         
101:         add_amount(result, money, options)
102:         add_invoice(result, options)
103:         add_address_verification_data(result, options)
104:         result
105:       end
build_token_request(credit_card, options) click to toggle source
     # File lib/active_merchant/billing/gateways/payment_express.rb, line 116
116:       def build_token_request(credit_card, options)
117:         result = new_transaction
118:         add_credit_card(result, credit_card)
119:         add_amount(result, 100, options) #need to make an auth request for $1
120:         add_token_request(result, options)
121:         result
122:       end
commit(action, request) click to toggle source

Take in the request and post it to DPS

     # File lib/active_merchant/billing/gateways/payment_express.rb, line 187
187:       def commit(action, request)
188:         add_credentials(request)
189:         add_transaction_type(request, action)
190:         
191:         # Parse the XML response
192:         response = parse( ssl_post(URL, request.to_s) )
193:         
194:         # Return a response
195:         PaymentExpressResponse.new(response[:success] == APPROVED, response[:card_holder_help_text], response,
196:           :test => response[:test_mode] == '1',
197:           :authorization => response[:dps_txn_ref]
198:         )
199:       end
format_date(month, year) click to toggle source
     # File lib/active_merchant/billing/gateways/payment_express.rb, line 222
222:       def format_date(month, year)
223:         "#{format(month, :two_digits)}#{format(year, :two_digits)}"
224:       end
new_transaction() click to toggle source
     # File lib/active_merchant/billing/gateways/payment_express.rb, line 182
182:       def new_transaction
183:         REXML::Document.new.add_element("Txn")
184:       end
parse(xml_string) click to toggle source

Response XML documentation: www.paymentexpress.com/technical_resources/ecommerce_nonhosted/pxpost.html#XMLTxnOutput

     # File lib/active_merchant/billing/gateways/payment_express.rb, line 202
202:       def parse(xml_string)
203:         response = {}
204: 
205:         xml = REXML::Document.new(xml_string)          
206: 
207:         # Gather all root elements such as HelpText
208:         xml.elements.each('Txn/*') do |element|
209:           response[element.name.underscore.to_sym] = element.text unless element.name == 'Transaction'
210:         end
211: 
212:         # Gather all transaction elements and prefix with "account_"
213:         # So we could access the MerchantResponseText by going
214:         # response[account_merchant_response_text]
215:         xml.elements.each('Txn/Transaction/*') do |element|
216:           response[element.name.underscore.to_sym] = element.text
217:         end
218:         
219:         response
220:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.