class ActiveMerchant::Billing::CardConnectGateway

Constants

STANDARD_ERROR_CODE_MAPPING

Public Class Methods

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

Public Instance Methods

authorize(money, payment, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 96
def authorize(money, payment, options = {})
  post = {}
  add_money(post, money)
  add_currency(post, money, options)
  add_invoice(post, options)
  add_payment(post, payment)
  add_address(post, options)
  add_customer_data(post, options)
  add_3DS(post, options)
  commit('auth', post)
end
capture(money, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 108
def capture(money, authorization, options = {})
  post = {}
  add_money(post, money)
  add_reference(post, authorization)
  add_additional_data(post, options)
  commit('capture', post)
end
purchase(money, payment, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 76
def purchase(money, payment, options = {})
  if options[:po_number]
    MultiResponse.run do |r|
      r.process { authorize(money, payment, options) }
      r.process { capture(money, r.authorization, options) }
    end
  else
    post = {}
    add_invoice(post, options)
    add_money(post, money)
    add_payment(post, payment)
    add_currency(post, money, options)
    add_address(post, options)
    add_customer_data(post, options)
    add_3DS(post, options)
    post[:capture] = 'Y'
    commit('auth', post)
  end
end
refund(money, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 116
def refund(money, authorization, options = {})
  post = {}
  add_money(post, money)
  add_reference(post, authorization)
  commit('refund', post)
end
require_valid_domain!(options, param) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 70
def require_valid_domain!(options, param)
  if options[param]
    raise ArgumentError.new('not a valid cardconnect domain') unless /\Dcardconnect.com:\d{1,}\D/ =~ options[param]
  end
end
scrub(transcript) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 152
def scrub(transcript)
  transcript.
    gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
    gsub(%r(("cvv2\\":\\")\d*), '\1[FILTERED]').
    gsub(%r(("merchid\\":\\")\d*), '\1[FILTERED]').
    gsub(%r((&?"account\\":\\")\d*), '\1[FILTERED]').
    gsub(%r((&?"token\\":\\")\d*), '\1[FILTERED]')
end
store(payment, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 133
def store(payment, options = {})
  post = {}
  add_payment(post, payment)
  add_address(post, options)
  add_customer_data(post, options)
  commit('profile', post)
end
supports_scrubbing?() click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 148
def supports_scrubbing?
  true
end
unstore(authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 141
def unstore(authorization, options = {})
  account_id, profile_id = authorization.split('|')
  commit('profile', {},
    verb: :delete,
    path: "/#{profile_id}/#{account_id}/#{@options[:merchant_id]}")
end
verify(credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 129
def verify(credit_card, options = {})
  authorize(0, credit_card, options)
end
void(authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 123
def void(authorization, options = {})
  post = {}
  add_reference(post, authorization)
  commit('void', post)
end

Private Instance Methods

add_3DS(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 241
def add_3DS(post, options)
  post[:secureflag] = options[:secure_flag] if options[:secure_flag]
  post[:securevalue] = options[:secure_value] if options[:secure_value]
  post[:securexid] = options[:secure_xid] if options[:secure_xid]
end
add_additional_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 219
def add_additional_data(post, options)
  post[:ponumber] = options[:po_number]
  post[:taxamnt] = options[:tax_amount] if options[:tax_amount]
  post[:frtamnt] = options[:freight_amount] if options[:freight_amount]
  post[:dutyamnt] = options[:duty_amount] if options[:duty_amount]
  post[:orderdate] = options[:order_date] if options[:order_date]
  post[:shipfromzip] = options[:ship_from_zip] if options[:ship_from_zip]
  if (shipping_address = options[:shipping_address])
    post[:shiptozip] = shipping_address[:zip]
    post[:shiptocountry] = shipping_address[:country]
  end
  if options[:items]
    post[:items] = options[:items].map do |item|
      updated = {}
      item.each_pair do |k, v|
        updated.merge!(k.to_s.gsub(/_/, '') => v)
      end
      updated
    end
  end
end
add_address(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 167
def add_address(post, options)
  if address = options[:billing_address] || options[:address]
    post[:address] = address[:address1] if address[:address1]
    post[:address].concat(" #{address[:address2]}") if address[:address2]
    post[:city] = address[:city] if address[:city]
    post[:region] = address[:state] if address[:state]
    post[:country] = address[:country] if address[:country]
    post[:postal] = address[:zip] if address[:zip]
    post[:phone] = address[:phone] if address[:phone]
  end
end
add_currency(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 183
def add_currency(post, money, options)
  post[:currency] = (options[:currency] || currency(money))
end
add_customer_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 163
def add_customer_data(post, options)
  post[:email] = options[:email] if options[:email]
end
add_echeck(post, payment) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 209
def add_echeck(post, payment)
  post[:accttype] = 'ECHK'
  post[:account] = payment.account_number
  post[:bankaba] = payment.routing_number
end
add_invoice(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 187
def add_invoice(post, options)
  post[:orderid] = options[:order_id]
  post[:ecomind] = (options[:recurring] ? 'R' : 'E')
end
add_money(post, money) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 179
def add_money(post, money)
  post[:amount] = amount(money)
end
add_payment(post, payment) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 192
def add_payment(post, payment)
  if payment.is_a?(String)
    account_id, profile_id = payment.split('|')
    post[:profile] = profile_id
    post[:acctid] = account_id
  else
    post[:name] = payment.name
    if card_brand(payment) == 'check'
      add_echeck(post, payment)
    else
      post[:account] = payment.number
      post[:expiry] = expdate(payment)
      post[:cvv2] = payment.verification_value
    end
  end
end
add_reference(post, authorization) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 215
def add_reference(post, authorization)
  post[:retref] = authorization
end
authorization_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 299
def authorization_from(response)
  if response['profileid']
    "#{response['acctid']}|#{response['profileid']}"
  else
    response['retref']
  end
end
commit(action, parameters, verb: :put, path: '') click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 270
def commit(action, parameters, verb: :put, path: '')
  parameters[:frontendid] = application_id
  parameters[:merchid] = @options[:merchant_id]
  url = url(action, path)
  response = parse(ssl_request(verb, url, post_data(parameters), headers))

  Response.new(
    success_from(response),
    message_from(response),
    response,
    authorization: authorization_from(response),
    avs_result: AVSResult.new(code: response['avsresp']),
    cvv_result: CVVResult.new(response['cvvresp']),
    test: test?,
    error_code: error_code_from(response)
  )
rescue ResponseError => e
  return Response.new(false, 'Unable to authenticate.  Please check your credentials.', {}, :test => test?) if e.response.code == '401'
  raise
end
error_code_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 311
def error_code_from(response)
  STANDARD_ERROR_CODE_MAPPING[response['respcode']] unless success_from(response)
end
expdate(credit_card) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 254
def expdate(credit_card)
  "#{format(credit_card.month, :two_digits)}#{format(credit_card.year, :two_digits)}"
end
headers() click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 247
def headers
  {
    'Authorization' => 'Basic ' + Base64.strict_encode64("#{@options[:username]}:#{@options[:password]}"),
    'Content-Type' => 'application/json'
  }
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 295
def message_from(response)
  response['setlstat'] ? "#{response['resptext']} #{response['setlstat']}" : response['resptext']
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 258
def parse(body)
  JSON.parse(body)
end
post_data(parameters = {}) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 307
def post_data(parameters = {})
  parameters.to_json
end
success_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 291
def success_from(response)
  response['respstat'] == 'A'
end
url(action, path) click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 262
def url(action, path)
  if test?
    test_url + action + path
  else
    (@options[:domain] || live_url) + action + path
  end
end