class ActiveMerchant::Billing::GlobalTransportGateway

Public Class Methods

new(options={}) click to toggle source

Public: Create a new Global Transport gateway.

options - A hash of options:

:global_user_name - Your Global user name
:global_password  - Your Global password
:term_type        - 3 character field assigned by Global Transport after
                  - your application is certified.
Calls superclass method ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/global_transport.rb, line 23
def initialize(options={})
  requires!(options, :global_user_name, :global_password, :term_type)
  super
end

Public Instance Methods

authorize(money, payment_method, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 37
def authorize(money, payment_method, options={})
  post = {}
  add_invoice(post, money, options)
  add_payment_method(post, payment_method)
  add_address(post, options)

  commit('Auth', post, options)
end
capture(money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 46
def capture(money, authorization, options={})
  post = {}
  add_invoice(post, money, options)
  add_auth(post, authorization)

  commit('Force', post, options)
end
purchase(money, payment_method, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 28
def purchase(money, payment_method, options={})
  post = {}
  add_invoice(post, money, options)
  add_payment_method(post, payment_method)
  add_address(post, options)

  commit('Sale', post, options)
end
refund(money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 54
def refund(money, authorization, options={})
  post = {}
  add_invoice(post, money, options)
  add_auth(post, authorization)

  commit('Return', post, options)
end
scrub(transcript) click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 81
def scrub(transcript)
  transcript.
    gsub(%r((&?CardNum=)[^&]*)i, '\1[FILTERED]').
    gsub(%r((&?CVNum=)[^&]*)i, '\1[FILTERED]').
    gsub(%r((&?GlobalPassword=)[^&]*)i, '\1[FILTERED]')
end
supports_scrubbing?() click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 77
def supports_scrubbing?
  true
end
verify(payment_method, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 69
def verify(payment_method, options={})
  post = {}
  add_payment_method(post, payment_method)
  add_address(post, options)

  commit('CardVerify', post, options)
end
void(authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 62
def void(authorization, options={})
  post = {}
  add_auth(post, authorization)

  commit('Void', post, options)
end

Private Instance Methods

add_address(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 90
def add_address(post, options)
  if address = (options[:billing_address] || options[:address])
    post[:Street] = address[:address1]
    post[:Zip] = address[:zip]
  end
end
add_auth(post, authorization) click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 97
def add_auth(post, authorization)
  post[:PNRef] = authorization
end
add_invoice(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 101
def add_invoice(post, money, options)
  currency = (options[:currency] || currency(money))

  post[:Amount] = localized_amount(money, currency)
  post[:InvNum] = truncate(options[:order_id], 16)
end
add_payment_method(post, payment_method) click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 108
def add_payment_method(post, payment_method)
  post[:CardNum] = payment_method.number
  post[:ExpDate] = expdate(payment_method)
  post[:NameOnCard] = payment_method.name
  post[:CVNum] = payment_method.verification_value
end
authorization_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 164
def authorization_from(response)
  response[:pnref]
end
avs_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 168
def avs_from(response)
  { code: response[:getavsresult] }
end
commit(action, parameters, options) click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 129
def commit(action, parameters, options)
  raw = parse(ssl_post(url, post_data(action, parameters, options)))
  Response.new(
    success_from(raw),
    message_from(raw),
    raw,
    authorization: authorization_from(raw),
    test: test?,
    avs_result: avs_from(raw),
    cvv_result: cvv_from(raw)
  )
end
cvv_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 172
def cvv_from(response)
  response[:getcvresult]
end
default_params() click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 176
def default_params
  {
    CardNum: '',
    ExpDate: '',
    NameOnCard: '',
    Amount: '',
    PNRef: '',
    Zip: '',
    Street: '',
    CVNum: '',
    MagData: '',
    InvNum: '',
    ExtData: ''
  }
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 160
def message_from(response)
  response[:respmsg]
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 115
def parse(body)
  response = {}

  Nokogiri::XML(body).root.xpath('*').each do |node|
    response[node.name.downcase.to_sym] = node.text
  end

  ext_data = Nokogiri::HTML.parse(response[:extdata])
  response[:approved_amount] = ext_data.xpath('//approvedamount').text
  response[:balance_due] = ext_data.xpath('//balancedue').text

  response
end
post_data(action, params, options) click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 142
def post_data(action, params, options)
  post = default_params
  post[:GlobalUserName] = @options[:global_user_name]
  post[:GlobalPassword] = @options[:global_password]
  post[:TransType] = action
  post[:ExtData] = "<TermType>#{@options[:term_type]}</TermType>"

  post.merge(params).map { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join('&')
end
success_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 156
def success_from(response)
  response[:result] == '0' || response[:result] == '200'
end
url() click to toggle source
# File lib/active_merchant/billing/gateways/global_transport.rb, line 152
def url
  (test? ? test_url : live_url)
end