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 19
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 32
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 40
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 24
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 48
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 83
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 79
def supports_scrubbing?
  true
end
verify(credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 65
def verify(credit_card, options = {})
  MultiResponse.run(:use_first_response) do |r|
    r.process { authorize(100, credit_card, options) }
    r.process(:ignore_result) { void(r.authorization, options) }
  end
end
verify_credentials() click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 72
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 57
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 129
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 121
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) unless options[:three_d_secure]
  add_payment_method(post, payment_method, options)
  add_three_ds(post, options)
end
add_authorization(post, authorization, options) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 138
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 155
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 134
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 151
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 144
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
add_three_ds(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 261
def add_three_ds(post, options)
  return unless three_d_secure = options[:three_d_secure]

  post.ElectronicCommerceIndicator(formatted_three_ds_eci(three_d_secure[:eci])) if three_d_secure[:eci]
  post.CardHolderAuthenticationID(three_d_secure[:xid]) if three_d_secure[:xid]
  post.CardHolderAuthenticationData(three_d_secure[:cavv]) if three_d_secure[:cavv]
  post.ThreeDSecure_ProtocolVersion(three_d_secure[:version]) if three_d_secure[:version]
  post.ThreeDSecure_DSTransID(three_d_secure[:ds_transaction_id]) if three_d_secure[:ds_transaction_id]
  post.ThreeDSecure_VEResEnrolled(formatted_enrollment(three_d_secure[:enrolled])) if three_d_secure[:enrolled]
end
authorization_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 240
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 109
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 92
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('false')
          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 160
def commit(post)
  raw_response =
    begin
      ssl_post(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 249
def error_code_from(response, succeeded)
  response['result_code'] unless succeeded
end
formatted_enrollment(val) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 272
def formatted_enrollment(val)
  case val
  when 'Y', 'N', 'U' then val
  when true, 'true' then 'Y'
  when false, 'false' then 'N'
  end
end
formatted_three_ds_eci(val) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 280
def formatted_three_ds_eci(val)
  case val
  when '05', '02' then 'ThreeDSecure'
  when '06', '01' then 'ThreeDSecureAttempted'
  when '07' then 'SecureChannel'
  else val
  end
end
headers(post) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 189
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 232
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 181
def mode
  test? ? 'Test' : 'Live'
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 197
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 214
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?
    parsed[underscore(node.name)] = node.text
  else
    node.elements.each { |e| parse_element(parsed, e) }
  end
end
split_auth(authorization) click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 244
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 228
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 253
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
url() click to toggle source
# File lib/active_merchant/billing/gateways/iveri.rb, line 185
def url
  @options[:url_override].to_s == 'iveri' ? iveri_url : live_url
end