class ActiveMerchant::Billing::ArgusGateway

For more information visit Argus Payments

Written by Piers Chambers (Varyonic.com)

Constants

STANDARD_ERROR_CODE_MAPPING

Public Class Methods

new(options={}) click to toggle source
Calls superclass method
# File lib/active_merchant/billing/gateways/argus.rb, line 30
def initialize(options={})
  requires!(options, :site_id, :req_username, :req_password)
  super
end

Public Instance Methods

authorize(money, payment, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 46
def authorize(money, payment, options={})
  post = PostData.new
  add_invoice(post, money, options)
  add_payment(post, payment)
  add_address(post, payment, options)
  add_customer_data(post, options)
  add_3ds_auth(post, options)

  commit('CCAUTHORIZE', post)
end
capture(money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 57
def capture(money, authorization, options={})
  post = PostData.new
  post[:li_value_1] = amount(money)
  post[:request_ref_po_id] = authorization
  commit('CCCAPTURE', post)
end
purchase(money, payment, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 35
def purchase(money, payment, options={})
  post = PostData.new
  add_invoice(post, money, options)
  add_payment(post, payment)
  add_address(post, payment, options)
  add_customer_data(post, options)
  add_3ds_auth(post, options)

  commit('CCAUTHCAP', post)
end
refund(money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 64
def refund(money, authorization, options={})
  post = PostData.new
  post[:li_value_1] = amount(money)
  post[:request_ref_po_id] = authorization
  commit('CCCREDIT', post)
end
scrub(transcript) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 88
def scrub(transcript)
  transcript.gsub(%r((&?pmt_numb=)[^&]*)i, '\1[FILTERED]').
    gsub(%r((&?pmt_key=)[^&]*)i, '\1[FILTERED]').
    gsub(%r((&?req_password=)[^&]*)i, '\1[FILTERED]')
end
supports_scrubbing?() click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 84
def supports_scrubbing?
  true
end
verify(credit_card, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 77
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
void(authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 71
def void(authorization, options={})
  post = PostData.new
  post[:request_ref_po_id] = authorization
  commit('CCREVERSE', post)
end

Private Instance Methods

add_3ds_auth(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 96
def add_3ds_auth(post, options)
  if options[:three_d_secure]
    post[:p3ds_eci] = options.dig(:three_d_secure, :eci)
    post[:p3ds_cavv] = options.dig(:three_d_secure, :cavv)
    post[:p3ds_xid] = options.dig(:three_d_secure, :xid)
  end
end
add_address(post, creditcard, options) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 112
def add_address(post, creditcard, options)
  address = options[:billing_address] || options[:address] || {}
  post[:bill_addr] = truncate(address[:address1], 60)
  post[:bill_addr_city] = truncate(address[:city], 40)
  post[:bill_addr_country] = truncate(address[:country], 60)
  post[:bill_addr_state] = empty?(address[:state]) ? 'n/a' : truncate(address[:state], 40)
  post[:bill_addr_zip] = truncate((address[:zip] || options[:zip]), 20)
end
add_customer_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 104
def add_customer_data(post, options)
  post[:cust_email] = options[:email] unless empty?(options[:email])
  post[:cust_fname] = options[:first_name]
  post[:cust_lname] = options[:last_name]
  # TODO: first_name, last_name = split_names(address[:name])
  add_shipping_address(post, options)
end
add_invoice(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 132
def add_invoice(post, money, options)
  post[:amount] = amount(money)
  post[:currency] = (options[:currency] || currency(money))
  post[:li_prod_id_1] = options[:li_prod_id_1] # 'Dynamic Amount Product ID'
  post[:li_value_1] = amount(money)
end
add_payment(post, payment) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 139
def add_payment(post, payment)
  post[:pmt_expiry] = sprintf('%02d/%04d', payment.month, payment.year)
  post[:pmt_key] = payment.verification_value
  post[:pmt_numb] = truncate(payment.number, 16)
  post[:request_currency] = 'USD'
  post[:merch_acct_id] = @options[:merch_acct_id]
end
add_shipping_address(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 121
def add_shipping_address(post, options)
  address = options[:shipping_address] || options[:address]
  return unless address

  post[:ship_addr] = truncate(address[:address1], 60)
  post[:ship_addr_city] = truncate(address[:city], 40)
  post[:ship_addr_country] = truncate(address[:country], 60)
  post[:ship_addr_state] = empty?(address[:state]) ? 'n/a' : truncate(address[:state], 40)
  post[:ship_addr_zip] = truncate((address[:zip] || options[:zip]), 20)
end
authorization_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 196
def authorization_from(response)
  response['PO_ID'].to_s
end
commit(action, parameters) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 162
def commit(action, parameters)
  url = (test? ? test_url : live_url)
  response = parse(ssl_post(url, post_data(action, parameters)))

  Response.new(
    success_from(response),
    message_from(response),
    response,
    authorization: authorization_from(response),
    avs_result: AVSResult.new(code: response['AVS_RESPONSE']),
    cvv_result: CVVResult.new(response['CVV_RESPONSE']),
    test: test?,
    error_code: error_code_from(response)
  )
end
credentials() click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 207
def credentials
  {
    site_id: @options[:site_id],
    req_username: @options[:req_username],
    req_password: @options[:req_password]
  }
end
error_code_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 215
def error_code_from(response)
  unless success_from(response)
    STANDARD_ERROR_CODE_MAPPING[response['SERVICE_RESPONSE'].to_s]
  end
end
format_error_fields(response, code, message) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 192
def format_error_fields(response, code, message)
  "(#{response[code]}) #{response[message]}" unless ['', '0'].include? response[code].to_s
end
json_error(body) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 153
def json_error(body)
  {
    'error' => {
      'message' => "Invalid JSON response body: #{body})",
      'raw_response' => scrub(body)
    }
  }
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 182
def message_from(response)
  error = [
    format_error_fields(response, 'API_RESPONSE', 'API_ADVICE'), # e.g. missing/invalid credentials or data
    format_error_fields(response, 'SERVICE_RESPONSE', 'SERVICE_ADVICE'), # e.g. expired card
    (response['REF_FIELD'] unless empty?(response['REF_FIELD']))
  ].compact.join(': ')

  empty?(error) ? response['TRANS_STATUS_NAME'] : error
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 147
def parse(body)
  JSON.parse(body)
rescue JSON::ParserError
  json_error(body)
end
post_data(action, parameters = {}) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 200
def post_data(action, parameters = {})
  parameters[:request_action] = action
  parameters[:request_api_version] = 3.6,
                                     parameters[:request_response_format] = 'JSON'
  parameters.merge!(credentials).to_post_data
end
success_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/argus.rb, line 178
def success_from(response)
  response['TRANS_STATUS_NAME'] == 'APPROVED'
end