class ActiveMerchant::Billing::IatsPaymentsGateway

Constants

ACTIONS

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 26
def initialize(options = {})
  if options[:login]
    ActiveMerchant.deprecated("The 'login' option is deprecated in favor of 'agent_code' and will be removed in a future version.")
    options[:agent_code] = options[:login]
  end

  options[:region] = 'na' unless options[:region]

  requires!(options, :agent_code, :password, :region)
  super
end

Public Instance Methods

purchase(money, payment, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 38
def purchase(money, payment, options = {})
  post = {}
  add_invoice(post, money, options)
  add_payment(post, payment)
  add_address(post, options)
  add_ip(post, options)
  add_description(post, options)
  add_customer_details(post, options)

  commit(determine_purchase_type(payment), post)
end
refund(money, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 50
def refund(money, authorization, options = {})
  post = {}
  transaction_id, payment_type = split_authorization(authorization)
  post[:transaction_id] = transaction_id
  add_invoice(post, -money, options)
  add_ip(post, options)
  add_description(post, options)

  commit((payment_type == 'check' ? :refund_check : :refund), post)
end
scrub(transcript) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 84
def scrub(transcript)
  transcript.
    gsub(%r((<agentCode>).+(</agentCode>)), '\1[FILTERED]\2').
    gsub(%r((<password>).+(</password>)), '\1[FILTERED]\2').
    gsub(%r((<creditCardNum>).+(</creditCardNum>)), '\1[FILTERED]\2').
    gsub(%r((<cvv2>).+(</cvv2>)), '\1[FILTERED]\2').
    gsub(%r((<accountNum>).+(</accountNum>)), '\1[FILTERED]\2')
end
store(credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 61
def store(credit_card, options = {})
  post = {}
  add_payment(post, credit_card)
  add_address(post, options)
  add_ip(post, options)
  add_description(post, options)
  add_store_defaults(post)

  commit(:store, post)
end
supports_scrubbing?() click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 80
def supports_scrubbing?
  true
end
unstore(authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 72
def unstore(authorization, options = {})
  post = {}
  post[:customer_code] = authorization
  add_ip(post, options)

  commit(:unstore, post)
end

Private Instance Methods

add_address(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 109
def add_address(post, options)
  billing_address = options[:billing_address] || options[:address]
  if billing_address
    post[:address] = billing_address[:address1]
    post[:city] = billing_address[:city]
    post[:state] = billing_address[:state]
    post[:zip_code] = billing_address[:zip]
    post[:phone] = billing_address[:phone] if billing_address[:phone]
    post[:email] = billing_address[:email] if billing_address[:email]
    post[:country] = billing_address[:country] if billing_address[:country]
  end
end
add_check(post, payment) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 150
def add_check(post, payment)
  post[:first_name] = payment.first_name
  post[:last_name] = payment.last_name
  post[:account_num] = "#{payment.routing_number}#{payment.account_number}"
  post[:account_type] = payment.account_type.upcase
end
add_credit_card(post, payment) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 141
def add_credit_card(post, payment)
  post[:first_name] = payment.first_name
  post[:last_name] = payment.last_name
  post[:credit_card_num] = payment.number
  post[:credit_card_expiry] = expdate(payment)
  post[:cvv2] = payment.verification_value if payment.verification_value?
  post[:mop] = creditcard_brand(payment.brand)
end
add_customer_details(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 164
def add_customer_details(post, options)
  post[:email] = options[:email] if options[:email]
end
add_description(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 127
def add_description(post, options)
  post[:comment] = options[:description] if options[:description]
end
add_invoice(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 122
def add_invoice(post, money, options)
  post[:invoice_num] = options[:order_id] if options[:order_id]
  post[:total] = amount(money)
end
add_ip(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 105
def add_ip(post, options)
  post[:customer_ip_address] = options[:ip] if options.has_key?(:ip)
end
add_payment(post, payment) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 131
def add_payment(post, payment)
  if payment.is_a?(String)
    post[:customer_code] = payment
  elsif payment.is_a?(Check)
    add_check(post, payment)
  else
    add_credit_card(post, payment)
  end
end
add_store_defaults(post) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 157
def add_store_defaults(post)
  post[:recurring] = false
  post[:begin_date] = Time.now.xmlschema
  post[:end_date] = Time.now.xmlschema
  post[:amount] = 0
end
authorization_from(action, response) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 272
def authorization_from(action, response)
  if %i[store unstore].include?(action)
    response[:customercode]
  elsif [:purchase_check].include?(action)
    response[:transaction_id] ? "#{response[:transaction_id]}|check" : nil
  else
    response[:transaction_id]
  end
end
commit(action, parameters) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 187
def commit(action, parameters)
  response = parse(
    ssl_post(
      url(action),
      post_data(action, parameters),
      { 'Content-Type' => 'application/soap+xml; charset=utf-8' }
    )
  )

  Response.new(
    success_from(response),
    message_from(response),
    response,
    authorization: authorization_from(action, response),
    test: test?
  )
end
creditcard_brand(brand) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 175
def creditcard_brand(brand)
  case brand
  when 'visa' then 'VISA'
  when 'master' then 'MC'
  when 'discover' then 'DSC'
  when 'american_express' then 'AMX'
  when 'maestro' then 'MAESTR'
  else
    raise "Unhandled credit card brand #{brand}"
  end
end
determine_purchase_type(payment) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 95
def determine_purchase_type(payment)
  if payment.is_a?(String)
    :purchase_customer_code
  elsif payment.is_a?(Check)
    :purchase_check
  else
    :purchase
  end
end
dexmlize_param_name(name) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 228
def dexmlize_param_name(name)
  names = {
    'AUTHORIZATIONRESULT' => :authorization_result,
    'SETTLEMENTBATCHDATE' => :settlement_batch_date,
    'SETTLEMENTDATE' => :settlement_date,
    'TRANSACTIONID' => :transaction_id
  }
  names[name] || name.to_s.downcase.intern
end
endpoints() click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 205
def endpoints
  {
    purchase: 'ProcessLinkv3.asmx',
    purchase_check: 'ProcessLinkv3.asmx',
    purchase_customer_code: 'ProcessLinkv3.asmx',
    refund: 'ProcessLinkv3.asmx',
    refund_check: 'ProcessLinkv3.asmx',
    store: 'CustomerLinkv3.asmx',
    unstore: 'CustomerLinkv3.asmx'
  }
end
envelope_namespaces() click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 286
def envelope_namespaces
  {
    'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
    'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
    'xmlns:soap12' => 'http://www.w3.org/2003/05/soap-envelope'
  }
end
expdate(creditcard) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 168
def expdate(creditcard)
  year  = sprintf('%.4i', creditcard.year)
  month = sprintf('%.2i', creditcard.month)

  "#{month}/#{year[-2..-1]}"
end
hashify_xml!(xml, response) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 238
def hashify_xml!(xml, response)
  xml = REXML::Document.new(xml)

  xml.elements.each('//IATSRESPONSE/*') do |node|
    recursively_parse_element(node, response)
  end
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 262
def message_from(response)
  if !successful_result_message?(response) && response[:authorization_result]
    return response[:authorization_result].strip
  elsif response[:status] == 'Failure'
    return response[:errors]
  else
    response[:status]
  end
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 222
def parse(body)
  response = {}
  hashify_xml!(body, response)
  response
end
post_data(action, parameters = {}) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 294
def post_data(action, parameters = {})
  xml = Builder::XmlMarkup.new
  xml.instruct!(:xml, version: '1.0', encoding: 'utf-8')
  xml.tag! 'soap12:Envelope', envelope_namespaces do
    xml.tag! 'soap12:Body' do
      xml.tag! ACTIONS[action], { 'xmlns' => 'https://www.iatspayments.com/NetGate/' } do
        xml.tag!('agentCode', @options[:agent_code])
        xml.tag!('password', @options[:password])
        parameters.each do |name, value|
          xml.tag!(xmlize_param_name(name), value)
        end
      end
    end
  end
  xml.target!
end
recursively_parse_element(node, response) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 246
def recursively_parse_element(node, response)
  if node.has_elements?
    node.elements.each { |n| recursively_parse_element(n, response) }
  else
    response[dexmlize_param_name(node.name)] = (node.text ? node.text.strip : nil)
  end
end
split_authorization(authorization) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 282
def split_authorization(authorization)
  authorization.split('|')
end
success_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 258
def success_from(response)
  response[:status] == 'Success' && successful_result_message?(response)
end
successful_result_message?(response) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 254
def successful_result_message?(response)
  response[:authorization_result] ? response[:authorization_result].start_with?('OK') : false
end
url(action) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 217
def url(action)
  base_url = @options[:region] == 'uk' ? live_uk_url : live_na_url
  "#{base_url}/#{endpoints[action]}?op=#{ACTIONS[action]}"
end
xmlize_param_name(name) click to toggle source
# File lib/active_merchant/billing/gateways/iats_payments.rb, line 311
def xmlize_param_name(name)
  names = { customer_ip_address: 'customerIPAddress' }
  names[name] || name.to_s.camelcase(:lower)
end