class ActiveMerchant::Billing::EfsnetGateway

Constants

ACTIONS
CREDIT_CARD_FIELDS

Public Class Methods

new(options = {}) click to toggle source

login is your Store ID password is your Store Key

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

Public Instance Methods

authorize(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 21
def authorize(money, creditcard, options = {})
  request = build_credit_card_request(money, creditcard, options)
  commit(:credit_card_authorize, request)
end
capture(money, identification, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 31
def capture(money, identification, options = {})
  request = build_refund_or_settle_request(money, identification, options)
  commit(:credit_card_settle, request)
end
credit(money, identification_or_credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 36
def credit(money, identification_or_credit_card, options = {})
  if identification_or_credit_card.is_a?(String)
    ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
    # Perform authorization reversal
    refund(money, identification_or_credit_card, options)
  else
    # Perform credit
    request = build_credit_card_request(money, identification_or_credit_card, options)
    commit(:credit_card_credit, request)
  end
end
force(money, authorization_code, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 66
def force(money, authorization_code, creditcard, options = {})
  options[:authorization_number] = authorization_code
  request = build_credit_card_request(money, creditcard, options)
  commit(:credit_card_capture, request)
end
purchase(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 26
def purchase(money, creditcard, options = {})
  request = build_credit_card_request(money, creditcard, options)
  commit(:credit_card_charge, request)
end
refund(money, reference, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 48
def refund(money, reference, options = {})
  # Perform authorization reversal
  request = build_refund_or_settle_request(money, reference, options)
  commit(:credit_card_refund, request)
end
system_check() click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 72
def system_check
  commit(:system_check, {})
end
voice_authorize(money, authorization_code, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 60
def voice_authorize(money, authorization_code, creditcard, options = {})
  options[:authorization_number] = authorization_code
  request = build_credit_card_request(money, creditcard, options)
  commit(:credit_card_voice_authorize, request)
end
void(identification, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 54
def void(identification, options = {})
  requires!(options, :order_id)
  original_transaction_id, = identification.split(';')
  commit(:void_transaction, { reference_number: format_reference_number(options[:order_id]), transaction_id: original_transaction_id })
end

Private Instance Methods

actions() click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 200
def actions
  ACTIONS
end
add_address(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 111
def add_address(post, options)
  if address = options[:billing_address] || options[:address]
    if address[:address2]
      post[:billing_address]    = address[:address1].to_s << ' ' << address[:address2].to_s
    else
      post[:billing_address]    = address[:address1].to_s
    end
    post[:billing_city]         = address[:city].to_s
    post[:billing_state]        = address[:state].blank? ? 'n/a' : address[:state]
    post[:billing_postal_code]  = address[:zip].to_s
    post[:billing_country]      = address[:country].to_s
  end

  if address = options[:shipping_address]
    if address[:address2]
      post[:shipping_address]   = address[:address1].to_s << ' ' << address[:address2].to_s
    else
      post[:shipping_address]   = address[:address1].to_s
    end
    post[:shipping_city]        = address[:city].to_s
    post[:shipping_state]       = address[:state].blank? ? 'n/a' : address[:state]
    post[:shipping_postal_code] = address[:zip].to_s
    post[:shipping_country]     = address[:country].to_s
  end
end
add_creditcard(post, creditcard) click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 137
def add_creditcard(post, creditcard)
  post[:billing_name] = creditcard.name if creditcard.name
  post[:account_number] = creditcard.number
  post[:card_verification_value] = creditcard.verification_value if creditcard.verification_value?
  post[:expiration_month] = sprintf('%.2i', creditcard.month)
  post[:expiration_year] = sprintf('%.4i', creditcard.year)[-2..-1]
end
authorization_from(response, params) click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 163
def authorization_from(response, params)
  [response[:transaction_id], params[:transaction_amount]].compact.join(';')
end
build_credit_card_request(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 92
def build_credit_card_request(money, creditcard, options = {})
  requires!(options, :order_id)

  post = {
    reference_number: format_reference_number(options[:order_id]),
    authorization_number: options[:authorization_number],
    transaction_amount: amount(money),
    client_ip_address: options[:ip]

  }
  add_creditcard(post, creditcard)
  add_address(post, options)
  post
end
build_refund_or_settle_request(money, identification, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 78
def build_refund_or_settle_request(money, identification, options = {})
  original_transaction_id, original_transaction_amount = identification.split(';')

  requires!(options, :order_id)

  {
    reference_number: format_reference_number(options[:order_id]),
    transaction_amount: amount(money),
    original_transaction_amount: original_transaction_amount,
    original_transaction_id: original_transaction_id,
    client_ip_address: options[:ip]
  }
end
commit(action, parameters) click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 145
def commit(action, parameters)
  response = parse(ssl_post(test? ? self.test_url : self.live_url, post_data(action, parameters), 'Content-Type' => 'text/xml'))

  Response.new(
    success?(response),
    message_from(response[:result_message]),
    response,
    test: test?,
    authorization: authorization_from(response, parameters),
    avs_result: { code: response[:avs_response_code] },
    cvv_result: response[:cvv_response_code]
  )
end
format_reference_number(number) click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 107
def format_reference_number(number)
  number.to_s.slice(0, 12)
end
message_from(message) click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 194
def message_from(message)
  return 'Unspecified error' if message.blank?

  message.gsub(/[^\w]/, ' ').split.join(' ').capitalize
end
parse(xml) click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 167
def parse(xml)
  response = {}

  xml = REXML::Document.new(xml)

  xml.elements.each('//Reply//TransactionReply/*') do |node|
    response[node.name.underscore.to_sym] = normalize(node.text)
  end unless xml.root.nil?

  response
end
post_data(action, parameters = {}) click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 179
def post_data(action, parameters = {})
  xml   = REXML::Document.new("<?xml version='1.0' encoding='UTF-8'?>")
  root  = xml.add_element('Request')
  root.attributes['StoreID'] = options[:login]
  root.attributes['StoreKey'] = options[:password]
  root.attributes['ApplicationID'] = 'ot 1.0'
  transaction = root.add_element(action.to_s.camelize)

  actions[action].each do |key|
    transaction.add_element(key).text = parameters[key.underscore.to_sym] unless parameters[key.underscore.to_sym].blank?
  end

  xml.to_s
end
success?(response) click to toggle source
# File lib/active_merchant/billing/gateways/efsnet.rb, line 159
def success?(response)
  response[:response_code] == '0'
end