class ActiveMerchant::Billing::PayGateXmlGateway

This gateway accepts the following arguments:

:login    => your PayJunction username
:password => your PayJunction pass

Example use:

gateway = ActiveMerchant::Billing::Base.gateway(:pay_gate_xml).new(
            :login => "my_account",
            :password => "my_pass"
         )

# set up credit card obj as in main ActiveMerchant example
creditcard = ActiveMerchant::Billing::CreditCard.new(
  :type       => 'visa',
  :number     => '4242424242424242',
  :month      => 8,
  :year       => 2009,
  :first_name => 'Bob',
  :last_name  => 'Bobsen'
)

# run request
response = gateway.purchase(1000, creditcard) # charge 10 dollars

1) Check whether the transaction was successful

response.success?

2) Retrieve the message returned by PayJunction

response.message

3) Retrieve the unique transaction ID returned by PayGateXML

response.authorization

This gateway has many other features which are not implemented here yet The basic setup here only supports auth/capture transactions.

Test Transactions

PayGateXML has a global test user/pass, but you can also sign up for your own. The class and the test come equipped with the global test creds

Usage Details

Below is a map of only SOME of the values accepted by PayGateXML and how you should submit each to ActiveMerchant

PayGateXML Field ActiveMerchant Use

pgid use :login value to gateway instantiation pwd use :password value to gateway instantiation

cname credit_card.name cc credit_card.number exp credit_card values formatted to YYYYMMDD budp South Africa only - set to 0 if purchase is not on budget amt include as argument to method for your transaction type ver do nothing, always set to current API version

cref provide as :invoice in options, varchar(80) cur 3 char field, currently only ZAR cvv credit_card.verification bno batch processing number, i.e. you supply this

others – not used in this implementation nurl, rurl - must remain blank or absent or they will use an alternative authentication mechanism email, ip - must remain blank or absent or they will use a PayGate extra service call PayProtector threed - must remain blank unless you are using your own 3D Secure server

Constants

API_VERSION
DECLINE_CODES
SUCCESS_CODES
TEST_ID
TEST_ID_3DSECURE

PayGateXML public test account - you can get a private one too

TEST_PWD
TRANSACTION_CODES

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/pay_gate_xml.rb, line 158
def initialize(options = {})
  requires!(options, :login, :password)
  super
end

Public Instance Methods

authorize(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_gate_xml.rb, line 170
def authorize(money, creditcard, options = {})
  action = 'authtx'

  options[:money] = money
  options[:creditcard] = creditcard
  commit(action, build_request(action, options))
end
capture(money, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_gate_xml.rb, line 178
def capture(money, authorization, options = {})
  action = 'settletx'

  options[:money] = money
  options[:authorization] = authorization
  commit(action, build_request(action, options), authorization)
end
purchase(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_gate_xml.rb, line 163
def purchase(money, creditcard, options = {})
  MultiResponse.run do |r|
    r.process { authorize(money, creditcard, options) }
    r.process { capture(money, r.authorization, options) }
  end
end
refund(money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_gate_xml.rb, line 186
def refund(money, authorization, options={})
  action = 'refundtx'

  options[:money] = money
  options[:authorization] = authorization
  commit(action, build_request(action, options))
end

Private Instance Methods

build_authorization(xml, money, creditcard, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_gate_xml.rb, line 223
def build_authorization(xml, money, creditcard, options={})
  xml.tag! 'authtx', {
    :cref  => options[:order_id],
    :cname => creditcard.name,
    :cc    => creditcard.number,
    :exp   => "#{format(creditcard.month, :two_digits)}#{format(creditcard.year, :four_digits)}",
    :budp  => 0,
    :amt   => amount(money),
    :cur   => (options[:currency] || currency(money)),
    :cvv   => creditcard.verification_value,
    :email => options[:email],
    :ip    => options[:ip]
  }
end
build_capture(xml, money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_gate_xml.rb, line 238
def build_capture(xml, money, authorization, options={})
  xml.tag! 'settletx', {
    :tid => authorization
  }
end
build_refund(xml, money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_gate_xml.rb, line 244
def build_refund(xml, money, authorization, options={})
  xml.tag! 'refundtx', {
    :tid => authorization,
    :amt => amount(money)
  }
end
build_request(action, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_gate_xml.rb, line 200
def build_request(action, options={})
  xml = Builder::XmlMarkup.new
  xml.instruct!

  xml.tag! 'protocol', :ver => API_VERSION, :pgid => (test? ? TEST_ID : @options[:login]), :pwd => @options[:password] do |protocol|
    money         = options.delete(:money)
    authorization = options.delete(:authorization)
    creditcard    = options.delete(:creditcard)
    case action
    when 'authtx'
      build_authorization(protocol, money, creditcard, options)
    when 'settletx'
      build_capture(protocol, money, authorization, options)
    when 'refundtx'
      build_refund(protocol, money, authorization, options)
    else
      raise 'no action specified for build_request'
    end
  end

  xml.target!
end
commit(action, request, authorization = nil) click to toggle source
# File lib/active_merchant/billing/gateways/pay_gate_xml.rb, line 267
def commit(action, request, authorization = nil)
  response = parse(action, ssl_post(self.live_url, request))
  Response.new(successful?(response), message_from(response), response,
    :test           => test?,
    :authorization  => authorization || response[:tid]
  )
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/pay_gate_xml.rb, line 275
def message_from(response)
  (response[:rdesc] || response[:edesc])
end
parse(action, body) click to toggle source
# File lib/active_merchant/billing/gateways/pay_gate_xml.rb, line 251
def parse(action, body)
  hash  = {}
  xml   = REXML::Document.new(body)

  response_action = action.gsub(/tx/, 'rx')
  root  = REXML::XPath.first(xml.root, response_action)
  # we might have gotten an error
  if root.nil?
    root  = REXML::XPath.first(xml.root, 'errorrx')
  end
  root.attributes.each do |name, value|
    hash[name.to_sym] = value
  end
  hash
end
successful?(response) click to toggle source
# File lib/active_merchant/billing/gateways/pay_gate_xml.rb, line 196
def successful?(response)
  SUCCESS_CODES.include?(response[:res])
end