class ActiveMerchant::Billing::MerchantESolutionsGateway

Constants

SUCCESS_RESPONSE_CODES

Public Class Methods

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

Public Instance Methods

authorize(money, creditcard_or_card_id, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 28
def authorize(money, creditcard_or_card_id, options = {})
  post = {}
  add_invoice(post, options)
  add_payment_source(post, creditcard_or_card_id, options)
  add_address(post, options)
  add_3dsecure_params(post, options)
  add_stored_credentials(post, options)
  commit('P', money, post)
end
capture(money, transaction_id, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 48
def capture(money, transaction_id, options = {})
  post = {}
  post[:transaction_id] = transaction_id
  post[:client_reference_number] = options[:customer] if options.has_key?(:customer)
  add_invoice(post, options)
  add_3dsecure_params(post, options)
  commit('S', money, post)
end
credit(money, creditcard_or_card_id, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 80
def credit(money, creditcard_or_card_id, options = {})
  post = {}
  post[:client_reference_number] = options[:customer] if options.has_key?(:customer)
  add_invoice(post, options)
  add_payment_source(post, creditcard_or_card_id, options)
  commit('C', money, post)
end
purchase(money, creditcard_or_card_id, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 38
def purchase(money, creditcard_or_card_id, options = {})
  post = {}
  add_invoice(post, options)
  add_payment_source(post, creditcard_or_card_id, options)
  add_address(post, options)
  add_3dsecure_params(post, options)
  add_stored_credentials(post, options)
  commit('D', money, post)
end
refund(money, identification, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 71
def refund(money, identification, options = {})
  post = {}
  post[:transaction_id] = identification
  post[:client_reference_number] = options[:customer] if options.has_key?(:customer)
  options.delete(:customer)
  options.delete(:billing_address)
  commit('U', money, options.merge(post))
end
scrub(transcript) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 108
def scrub(transcript)
  transcript.
    gsub(%r((&?profile_key=)\w*(&?)), '\1[FILTERED]\2').
    gsub(%r((&?card_number=)\d*(&?)), '\1[FILTERED]\2').
    gsub(%r((&?cvv2=)\d*(&?)), '\1[FILTERED]\2')
end
store(creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 57
def store(creditcard, options = {})
  MultiResponse.run do |r|
    r.process { temporary_store(creditcard, options) }
    r.process { verify(r.authorization, { store_card: 'y' }) }
  end
end
supports_scrubbing?() click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 104
def supports_scrubbing?
  true
end
unstore(card_id, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 64
def unstore(card_id, options = {})
  post = {}
  post[:client_reference_number] = options[:customer] if options.has_key?(:customer)
  post[:card_id] = card_id
  commit('X', nil, post)
end
verify(credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 97
def verify(credit_card, options = {})
  post = {}
  post[:store_card] = options[:store_card] if options[:store_card]
  add_payment_source(post, credit_card, options)
  commit('A', 0, post)
end
void(transaction_id, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 88
def void(transaction_id, options = {})
  post = {}
  post[:transaction_id] = transaction_id
  post[:client_reference_number] = options[:customer] if options.has_key?(:customer)
  options.delete(:customer)
  options.delete(:billing_address)
  commit('V', nil, options.merge(post))
end

Private Instance Methods

add_3dsecure_params(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 155
def add_3dsecure_params(post, options)
  post[:xid] = options[:xid] unless empty?(options[:xid])
  post[:cavv] = options[:cavv] unless empty?(options[:cavv])
  post[:ucaf_collection_ind] = options[:ucaf_collection_ind] unless empty?(options[:ucaf_collection_ind])
  post[:ucaf_auth_data] = options[:ucaf_auth_data] unless empty?(options[:ucaf_auth_data])
end
add_address(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 124
def add_address(post, options)
  if address = options[:billing_address] || options[:address]
    post[:cardholder_street_address] = address[:address1].to_s.gsub(/[^\w.]/, '+')
    post[:cardholder_zip] = address[:zip].to_s
  end
end
add_creditcard(post, creditcard, options) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 149
def add_creditcard(post, creditcard, options)
  post[:card_number] = creditcard.number
  post[:cvv2] = creditcard.verification_value if creditcard.verification_value?
  post[:card_exp_date] = expdate(creditcard)
end
add_invoice(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 131
def add_invoice(post, options)
  if options.has_key? :order_id
    order_id = options[:order_id].to_s.gsub(/[^\w.]/, '')
    post[:invoice_number] = truncate(order_id, 17)
  end
end
add_payment_source(post, creditcard_or_card_id, options) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 138
def add_payment_source(post, creditcard_or_card_id, options)
  if creditcard_or_card_id.is_a?(String)
    # using stored card
    post[:card_id] = creditcard_or_card_id
    post[:card_exp_date] = options[:expiration_date] if options[:expiration_date]
  else
    # card info is provided
    add_creditcard(post, creditcard_or_card_id, options)
  end
end
add_stored_credentials(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 162
def add_stored_credentials(post, options)
  post[:client_reference_number] = options[:client_reference_number] if options[:client_reference_number]
  post[:moto_ecommerce_ind] = options[:moto_ecommerce_ind] if options[:moto_ecommerce_ind]
  post[:recurring_pmt_num] = options[:recurring_pmt_num] if options[:recurring_pmt_num]
  post[:recurring_pmt_count] = options[:recurring_pmt_count] if options[:recurring_pmt_count]
  post[:card_on_file] = options[:card_on_file] if options[:card_on_file]
  post[:cit_mit_indicator] = options[:cit_mit_indicator] if options[:cit_mit_indicator]
  post[:account_data_source] = options[:account_data_source] if options[:account_data_source]
end
authorization_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 203
def authorization_from(response)
  return response['card_id'] if response['card_id']

  response['transaction_id']
end
commit(action, money, parameters) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 181
def commit(action, money, parameters)
  url = test? ? self.test_url : self.live_url
  parameters[:transaction_amount] = amount(money) if !(action == 'V') && money

  response =
    begin
      parse(ssl_post(url, post_data(action, parameters)))
    rescue ActiveMerchant::ResponseError => e
      { 'error_code' => '404', 'auth_response_text' => e.to_s }
    end

  Response.new(
    success_from(response),
    message_from(response),
    response,
    authorization: authorization_from(response),
    test: test?,
    cvv_result: response['cvv2_result'],
    avs_result: { code: response['avs_result'] }
  )
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 213
def message_from(response)
  if response['error_code'] == '000'
    'This transaction has been approved'
  else
    response['auth_response_text']
  end
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 172
def parse(body)
  results = {}
  body.split(/&/).each do |pair|
    key, val = pair.split(/=/)
    results[key] = val
  end
  results
end
post_data(action, parameters = {}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 221
def post_data(action, parameters = {})
  post = {}
  post[:profile_id] = @options[:login]
  post[:profile_key] = @options[:password]
  post[:transaction_type] = action if action

  post.merge(parameters).map { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join('&')
end
success_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 209
def success_from(response)
  SUCCESS_RESPONSE_CODES.include?(response['error_code'])
end
temporary_store(creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/merchant_e_solutions.rb, line 117
def temporary_store(creditcard, options = {})
  post = {}
  post[:client_reference_number] = options[:customer] if options.has_key?(:customer)
  add_creditcard(post, creditcard, options)
  commit('T', nil, post)
end