class ActiveMerchant::Billing::IveriGateway

Public Class Methods

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

Public Instance Methods

authorize(money, payment_method, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 29
def authorize(money, payment_method, options={})
  post = build_vxml_request('Authorisation', options) do |xml|
    add_auth_purchase_params(xml, money, payment_method, options)
  end

  commit(post)
end
capture(money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 37
def capture(money, authorization, options={})
  post = build_vxml_request('Debit', options) do |xml|
    add_authorization(xml, authorization, options)
  end

  commit(post)
end
purchase(money, payment_method, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 21
def purchase(money, payment_method, options={})
  post = build_vxml_request('Debit', options) do |xml|
    add_auth_purchase_params(xml, money, payment_method, options)
  end

  commit(post)
end
refund(money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 45
def refund(money, authorization, options={})
  post = build_vxml_request('Credit', options) do |xml|
    add_amount(xml, money, options)
    add_authorization(xml, authorization, options)
  end

  commit(post)
end
scrub(transcript) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 76
def scrub(transcript)
  transcript.
    gsub(%r((CertificateID=\\\")[^\\]*), '\1[FILTERED]').
    gsub(%r((<PAN>)[^&]*), '\1[FILTERED]').
    gsub(%r((<CardSecurityCode>)[^&]*), '\1[FILTERED]')
end
supports_scrubbing?() click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 72
def supports_scrubbing?
  true
end
verify(credit_card, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 62
def verify(credit_card, options={})
  authorize(0, credit_card, options)
end
verify_credentials() click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 66
def verify_credentials
  void = void('', options)
  return true if void.message ==  'Missing OriginalMerchantTrace'
  false
end
void(authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 54
def void(authorization, options={})
  post = build_vxml_request('Void', options) do |xml|
    add_authorization(xml, authorization, options)
  end

  commit(post)
end

Private Instance Methods

add_amount(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 121
def add_amount(post, money, options)
  post.Amount(amount(money))
  post.Currency(options[:currency] || default_currency)
end
add_auth_purchase_params(post, money, payment_method, options) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 114
def add_auth_purchase_params(post, money, payment_method, options)
  add_card_holder_authentication(post, options)
  add_amount(post, money, options)
  add_electronic_commerce_indicator(post, options)
  add_payment_method(post, payment_method, options)
end
add_authorization(post, authorization, options) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 130
def add_authorization(post, authorization, options)
  post.MerchantReference(split_auth(authorization)[2])
  post.TransactionIndex(split_auth(authorization)[1])
  post.OriginalRequestID(split_auth(authorization)[0])
end
add_card_holder_authentication(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 147
def add_card_holder_authentication(post, options)
  post.CardHolderAuthenticationID(options[:xid]) if options[:xid]
  post.CardHolderAuthenticationData(options[:cavv]) if options[:cavv]
end
add_electronic_commerce_indicator(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 126
def add_electronic_commerce_indicator(post, options)
  post.ElectronicCommerceIndicator(options[:eci]) if options[:eci]
end
add_new_reference(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 143
def add_new_reference(post, options)
  post.MerchantReference(options[:order_id] || generate_unique_id)
end
add_payment_method(post, payment_method, options) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 136
def add_payment_method(post, payment_method, options)
  post.ExpiryDate("#{format(payment_method.month, :two_digits)}#{payment_method.year}")
  add_new_reference(post, options)
  post.CardSecurityCode(payment_method.verification_value)
  post.PAN(payment_method.number)
end
authorization_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 227
def authorization_from(response)
  "#{response['transaction_request_id']}|#{response['transaction_index']}|#{response['merchant_reference']}"
end
build_vxml_request(action, options) { |xml| ... } click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 102
def build_vxml_request(action, options)
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.V_XML('Version' => '2.0', 'CertificateID' => @options[:cert_id], 'Direction' => 'Request') do
      xml.Transaction('ApplicationID' => @options[:app_id], 'Command' => action, 'Mode' => mode) do
        yield(xml)
      end
    end
  end

  builder.doc.root.to_xml
end
build_xml_envelope(vxml) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 85
def build_xml_envelope(vxml)
  builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
    xml[:soap].Envelope 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema', 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/' do
      xml[:soap].Body do
        xml.Execute 'xmlns' => 'http://iveri.com/' do
          xml.validateRequest 'true'
          xml.protocol 'V_XML'
          xml.protocolVersion '2.0'
          xml.request vxml
        end
      end
    end
  end

  builder.to_xml
end
commit(post) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 152
def commit(post)
  raw_response = begin
    ssl_post(live_url, build_xml_envelope(post), headers(post))
  rescue ActiveMerchant::ResponseError => e
    e.response.body
  end

  parsed = parse(raw_response)
  succeeded = success_from(parsed)

  Response.new(
    succeeded,
    message_from(parsed, succeeded),
    parsed,
    authorization: authorization_from(parsed),
    error_code: error_code_from(parsed, succeeded),
    test: test?
  )
end
error_code_from(response, succeeded) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 236
def error_code_from(response, succeeded)
  unless succeeded
    response['result_code']
  end
end
headers(post) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 176
def headers(post)
  {
    'Content-Type' => 'text/xml; charset=utf-8',
    'Content-Length' => post.size.to_s,
    'SOAPAction' => 'http://iveri.com/Execute'
  }
end
message_from(response, succeeded) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 219
def message_from(response, succeeded)
  if succeeded
    'Succeeded'
  else
    response['result_description'] || response['result_acquirer_description']
  end
end
mode() click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 172
def mode
  test? ? 'Test' : 'Live'
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 184
def parse(body)
  parsed = {}

  vxml = Nokogiri::XML(body).remove_namespaces!.xpath('//Envelope/Body/ExecuteResponse/ExecuteResult').inner_text
  doc = Nokogiri::XML(vxml)
  doc.xpath('*').each do |node|
    if node.elements.empty?
      parsed[underscore(node.name)] = node.text
    else
      node.elements.each do |childnode|
        parse_element(parsed, childnode)
      end
    end
  end
  parsed
end
parse_element(parsed, node) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 201
def parse_element(parsed, node)
  if !node.attributes.empty?
    node.attributes.each do |a|
      parsed[underscore(node.name)+ '_' + underscore(a[1].name)] = a[1].value
    end
  end

  if !node.elements.empty?
    node.elements.each { |e| parse_element(parsed, e) }
  else
    parsed[underscore(node.name)] = node.text
  end
end
split_auth(authorization) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 231
def split_auth(authorization)
  request_id, transaction_index, merchant_reference = authorization.to_s.split('|')
  [request_id, transaction_index, merchant_reference]
end
success_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 215
def success_from(response)
  response['result_status'] == '0'
end
underscore(camel_cased_word) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 242
def underscore(camel_cased_word)
  camel_cased_word.to_s.gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
    gsub(/([a-z\d])([A-Z])/, '\1_\2').
    tr('-', '_').
    downcase
end