class ActiveMerchant::Billing::CredoraxGateway

Constants

ACTIONS
CARD_TYPES
RESPONSE_MESSAGES

Public Class Methods

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

Public Instance Methods

authorize(amount, payment_method, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 142
def authorize(amount, payment_method, options={})
  post = {}
  add_invoice(post, amount, options)
  add_payment_method(post, payment_method)
  add_customer_data(post, options)
  add_email(post, options)
  add_3d_secure(post, options)
  add_echo(post, options)
  add_submerchant_id(post, options)
  add_transaction_type(post, options)

  commit(:authorize, post)
end
capture(amount, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 156
def capture(amount, authorization, options={})
  post = {}
  add_invoice(post, amount, options)
  add_reference(post, authorization)
  add_customer_data(post, options)
  add_echo(post, options)
  add_submerchant_id(post, options)

  commit(:capture, post)
end
credit(amount, payment_method, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 189
def credit(amount, payment_method, options={})
  post = {}
  add_invoice(post, amount, options)
  add_payment_method(post, payment_method)
  add_customer_data(post, options)
  add_email(post, options)
  add_echo(post, options)
  add_submerchant_id(post, options)
  add_transaction_type(post, options)

  commit(:credit, post)
end
purchase(amount, payment_method, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 128
def purchase(amount, payment_method, options={})
  post = {}
  add_invoice(post, amount, options)
  add_payment_method(post, payment_method)
  add_customer_data(post, options)
  add_email(post, options)
  add_3d_secure(post, options)
  add_echo(post, options)
  add_submerchant_id(post, options)
  add_transaction_type(post, options)

  commit(:purchase, post)
end
refund(amount, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 178
def refund(amount, authorization, options={})
  post = {}
  add_invoice(post, amount, options)
  add_reference(post, authorization)
  add_customer_data(post, options)
  add_echo(post, options)
  add_submerchant_id(post, options)

  commit(:refund, post)
end
scrub(transcript) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 213
def scrub(transcript)
  transcript.
    gsub(%r((b1=)\d+), '\1[FILTERED]').
    gsub(%r((b5=)\d+), '\1[FILTERED]')
end
supports_scrubbing?() click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 209
def supports_scrubbing?
  true
end
verify(credit_card, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 202
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/credorax.rb, line 167
def void(authorization, options={})
  post = {}
  add_customer_data(post, options)
  reference_action = add_reference(post, authorization)
  add_echo(post, options)
  add_submerchant_id(post, options)
  post[:a1] = generate_unique_id

  commit(:void, post, reference_action)
end

Private Instance Methods

add_3d_secure(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 270
def add_3d_secure(post, options)
  if options[:eci] && options[:xid]
    add_3d_secure_1_data(post, options)
  elsif options[:three_d_secure]
    add_normalized_3d_secure_2_data(post, options)
  end
end
add_3d_secure_1_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 278
def add_3d_secure_1_data(post, options)
  post[:i8] = build_i8(options[:eci], options[:cavv], options[:xid])
end
add_customer_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 246
def add_customer_data(post, options)
  post[:d1] = options[:ip] || '127.0.0.1'
  if (billing_address = options[:billing_address])
    post[:c5] = billing_address[:address1]
    post[:c7] = billing_address[:city]
    post[:c10] = billing_address[:zip]
    post[:c8] = billing_address[:state]
    post[:c9] = billing_address[:country]
    post[:c2] = billing_address[:phone]
  end
end
add_echo(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 297
def add_echo(post, options)
  # The d2 parameter is used during the certification process
  # See remote tests for full certification test suite
  post[:d2] = options[:echo] unless options[:echo].blank?
end
add_email(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 266
def add_email(post, options)
  post[:c3] = options[:email] || 'unspecified@example.com'
end
add_invoice(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 221
def add_invoice(post, money, options)
  currency = options[:currency] || currency(money)

  post[:a4] = localized_amount(money, currency)
  post[:a1] = generate_unique_id
  post[:a5] = currency
  post[:h9] = options[:order_id]
  post[:i2] = options[:billing_descriptor] if options[:billing_descriptor]
end
add_normalized_3d_secure_2_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 282
def add_normalized_3d_secure_2_data(post, options)
  three_d_secure_options = options[:three_d_secure]

  post[:i8] = build_i8(
    three_d_secure_options[:eci],
    three_d_secure_options[:cavv]
  )
  post[:'3ds_version'] = three_d_secure_options[:version]
  post[:'3ds_dstrxid'] = three_d_secure_options[:ds_transaction_id]
end
add_payment_method(post, payment_method) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 237
def add_payment_method(post, payment_method)
  post[:c1] = payment_method.name
  post[:b2] = CARD_TYPES[payment_method.brand] || ''
  post[:b1] = payment_method.number
  post[:b5] = payment_method.verification_value
  post[:b4] = format(payment_method.year, :two_digits)
  post[:b3] = format(payment_method.month, :two_digits)
end
add_reference(post, authorization) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 258
def add_reference(post, authorization)
  response_id, authorization_code, request_id, action = authorization.split(';')
  post[:g2] = response_id
  post[:g3] = authorization_code
  post[:g4] = request_id
  action || :authorize
end
add_submerchant_id(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 303
def add_submerchant_id(post, options)
  post[:h3] = options[:submerchant_id] if options[:submerchant_id]
end
add_transaction_type(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 307
def add_transaction_type(post, options)
  post[:a9] = options[:transaction_type] if options[:transaction_type]
end
build_i8(eci, cavv=nil, xid=nil) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 293
def build_i8(eci, cavv=nil, xid=nil)
  "#{eci}:#{cavv || 'none'}:#{xid || 'none'}"
end
commit(action, params, reference_action = nil) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 323
def commit(action, params, reference_action = nil)
  raw_response = ssl_post(url, post_data(action, params, reference_action))
  response = parse(raw_response)

  Response.new(
    success_from(response),
    message_from(response),
    response,
    authorization: "#{response["Z1"]};#{response["Z4"]};#{response["A1"]};#{action}",
    avs_result: AVSResult.new(code: response['Z9']),
    cvv_result: CVVResult.new(response['Z14']),
    test: test?
  )
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 373
def message_from(response)
  if success_from(response)
    'Succeeded'
  else
    RESPONSE_MESSAGES[response['Z6']] || response['Z3'] || 'Unable to read error message'
  end
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 365
def parse(body)
  Hash[CGI::parse(body).map { |k, v| [k.upcase, v.first] }]
end
post_data(action, params, reference_action) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 345
def post_data(action, params, reference_action)
  params.keys.each { |key| params[key] = params[key].to_s }
  params[:M] = @options[:merchant_id]
  params[:O] = request_action(action, reference_action)
  params[:K] = sign_request(params)
  params.map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')
end
request_action(action, reference_action) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 353
def request_action(action, reference_action)
  if reference_action
    ACTIONS["#{reference_action}_#{action}".to_sym]
  else
    ACTIONS[action]
  end
end
sign_request(params) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 338
def sign_request(params)
  params = params.sort
  params.each { |param| param[1].gsub!(/[<>()\\]/, ' ') }
  values = params.map { |param| param[1].strip }
  Digest::MD5.hexdigest(values.join + @options[:cipher_key])
end
success_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 369
def success_from(response)
  response['Z2'] == '0'
end
url() click to toggle source
# File lib/active_merchant/billing/gateways/credorax.rb, line 361
def url
  test? ? test_url : live_url
end