lib/active_merchant/billing/gateways/payment_express.rb in activemerchant-1.2.1 vs lib/active_merchant/billing/gateways/payment_express.rb in activemerchant-1.3.0

- old
+ new

@@ -1,18 +1,14 @@ require 'rexml/document' -module ActiveMerchant - module Billing +module ActiveMerchant #:nodoc: + module Billing #:nodoc: # 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. class PaymentExpressGateway < Gateway - attr_reader :url - attr_reader :response - attr_reader :options - self.default_currency = 'NZD' # PS supports all major credit cards; Visa, Mastercard, Amex, Diners, BankCard & JCB. # Various white label cards can be accepted as well; Farmers, AirNZCard and Elders etc. # Please note that not all acquirers and Eftpos networks can support some of these card types. # VISA, Mastercard, Diners Club and Farmers cards are supported @@ -35,47 +31,38 @@ :authorization => 'Auth', :capture => 'Complete', :validate => 'Validate' } - POST_HEADERS = { "Content-Type" => "application/x-www-form-urlencoded" } - # We require the DPS gateway username and password when the object is created. def initialize(options = {}) # A DPS username and password must exist requires!(options, :login, :password) # Make the options an instance variable @options = options super end # Funds are transferred immediately. - def purchase(money, credit_card_or_billing_token, options = {}) + def purchase(money, payment_source, options = {}) - credit_card = credit_card_or_billing_token if credit_card_or_billing_token.respond_to?(:number) + credit_card = payment_source if payment_source.respond_to?(:number) if credit_card - if result = test_result_from_cc_number(credit_card.number) - return result - end options[:credit_card] = credit_card else - options[:token] = credit_card_or_billing_token + options[:token] = payment_source end request = build_purchase_or_authorization_request(money, options) commit(:purchase, request) end # 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: http://www.paymentexpress.com/technical_resources/ecommerce_nonhosted/pxpost.html#Authcomplete def authorize(money, credit_card, options = {}) - if result = test_result_from_cc_number(credit_card.number) - return result - end - options[:credit_card] = credit_card request = build_purchase_or_authorization_request(money, options) commit(:authorization, request) end @@ -182,11 +169,11 @@ def add_transaction_type(xml, action) xml.add_element("TxnType").text = TRANSACTIONS[action] end def add_invoice(xml, options) - xml.add_element("TxnId").text = options[:order_id] unless options[:order_id].blank? + xml.add_element("TxnId").text = options[:order_id].to_s.slice(0, 16) unless options[:order_id].blank? xml.add_element("MerchantReference").text = options[:description] unless options[:description].blank? end def add_address_verification_data(xml, options) address = options[:billing_address] || options[:address] @@ -206,27 +193,21 @@ # Take in the request and post it to DPS def commit(action, request) add_credentials(request) add_transaction_type(request, action) - # Next, post it to the server - response = ssl_post(PAYMENT_URL, request.to_s, POST_HEADERS) - # Parse the XML response - @response = parse_response(response) + response = parse( ssl_post(PAYMENT_URL, request.to_s) ) - success = @response[:success] == APPROVED - test = @response[:test_mode] == '1' - # Return a response - PaymentExpressResponse.new(success, @response[:response_text], @response, - :test => test, - :authorization => @response[:dps_txn_ref] + PaymentExpressResponse.new(response[:success] == APPROVED, response[:response_text], response, + :test => response[:test_mode] == '1', + :authorization => response[:dps_txn_ref] ) end # Response XML documentation: http://www.paymentexpress.com/technical_resources/ecommerce_nonhosted/pxpost.html#XMLTxnOutput - def parse_response(xml_string) + def parse(xml_string) response = {} xml = REXML::Document.new(xml_string) # Gather all root elements such as HelpText \ No newline at end of file