class ActiveMerchant::Billing::BankFrickGateway

For more information visit Bank Frick Acquiring Services

Written by Piers Chambers (Varyonic.com)

Constants

SUPPORTED_TRANSACTIONS

The set of supported transactions for this gateway. More operations are supported by the gateway itself, but are not supported in this library.

Public Class Methods

new(options={}) click to toggle source
Calls superclass method ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/bank_frick.rb, line 30
def initialize(options={})
  requires!(options, :sender, :channel, :userid, :userpwd)
  super
end

Public Instance Methods

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

  commit('authonly', post)
end
capture(money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bank_frick.rb, line 55
def capture(money, authorization, options={})
  post = {}
  post[:authorization] = authorization
  add_invoice(post, money, options)

  commit('capture', post)
end
purchase(money, payment, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bank_frick.rb, line 35
def purchase(money, payment, options={})
  post = {}
  add_invoice(post, money, options)
  add_payment(post, payment)
  add_address(post, payment, options)
  add_customer_data(post, options)

  commit('sale', post)
end
refund(money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bank_frick.rb, line 63
def refund(money, authorization, options={})
  post = {}
  post[:authorization] = authorization
  add_invoice(post, money, options)

  commit('refund', post)
end
verify(credit_card, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bank_frick.rb, line 78
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/bank_frick.rb, line 71
def void(authorization, options={})
  post = {}
  post[:authorization] = authorization

  commit('void', post)
end

Private Instance Methods

add_address(post, creditcard, options) click to toggle source
# File lib/active_merchant/billing/gateways/bank_frick.rb, line 92
def add_address(post, creditcard, options)
  if address = options[:billing_address] || options[:address]
    post[:address] = address[:address1].to_s
    post[:company] = address[:company].to_s
    post[:phone]   = address[:phone].to_s.gsub(/[^0-9]/, '') || "0000000"
    post[:zip]     = address[:zip].to_s
    post[:city]    = address[:city].to_s
    post[:country] = address[:country].to_s
    post[:state]   = address[:state].blank?  ? 'n/a' : address[:state]
  end
end
add_customer_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/bank_frick.rb, line 87
def add_customer_data(post, options)
  post[:email] = options[:email] || 'noone@example.com'
  post[:ip] = options[:ip] || '0.0.0.0'
end
add_invoice(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/bank_frick.rb, line 104
def add_invoice(post, money, options)
  post[:order_id]    = options[:order_id] if post.has_key? :order_id
  post[:amount]      = amount(money)
  post[:currency]    = (options[:currency] || currency(money))
  post[:description] = options[:description]
end
add_payment(post, payment) click to toggle source
# File lib/active_merchant/billing/gateways/bank_frick.rb, line 111
def add_payment(post, payment)
  post[:first_name] = payment.first_name
  post[:last_name]  = payment.last_name
  post[:brand]      = payment.brand
  post[:card_num]   = payment.number
  post[:card_code]  = payment.verification_value if payment.verification_value?
  post[:exp_year]   = payment.year
  post[:exp_month]  = payment.month
end
authorization_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/bank_frick.rb, line 159
def authorization_from(response)
  response[:uniqueid]
end
build_xml_request(action, data) click to toggle source
# File lib/active_merchant/billing/gateways/bank_frick.rb, line 168
def build_xml_request(action, data)
  xml = Builder::XmlMarkup.new :indent => 2
  xml.Request(version: '1.0') do
    xml.Header do
      xml.Security(sender: @options[:sender], type: 'MERCHANT')
    end
    xml.Transaction(response: 'SYNC', channel: @options[:channel], mode: 'LIVE') do
      xml.User(pwd: @options[:userpwd], login: @options[:userid])
      xml.Identification do
        xml.TransactionID data[:order_id] if data.has_key? :order_id
        xml.ReferenceID   data[:authorization] if data.has_key? :authorization
      end
      xml.Account do
        xml.Holder        "#{data[:first_name]} #{data[:last_name]}"
        xml.Brand         data[:brand]
        xml.Number        data[:card_num]
        xml.Bank          data[:bankname]
        xml.Country       data[:country]
        xml.Authorization data[:authorization]
        xml.Verification  data[:card_code]
        xml.Year          data[:exp_year]
        xml.Month         data[:exp_month]
      end if data.has_key? :card_num
      xml.Payment(code: SUPPORTED_TRANSACTIONS[action]) do
        xml.Presentation do
          xml.Amount     data[:amount]
          xml.Currency   data[:currency]
          xml.Usage      data[:description]
        end
      end
      xml.Customer do
        xml.Contact do
          xml.Email      data[:email]
          xml.Mobile     data[:mobile]
          xml.Ip         data[:ip]
          xml.Phone      data[:phone]
        end
        xml.Address do
          xml.Street     data[:address]
          xml.Zip        data[:zip]
          xml.City       data[:city]
          xml.State      data[:state]
          xml.Country    data[:country]
        end
        xml.Name do
          xml.Salutation data[:salutation]
          xml.Title      data[:title]
          xml.Given      data[:first_name]
          xml.Family     data[:last_name]
          xml.Company    data[:company]
        end
      end if data.has_key? :last_name
    end
  end
end
commit(action, parameters) click to toggle source
# File lib/active_merchant/billing/gateways/bank_frick.rb, line 135
def commit(action, parameters)
  url = (test? ? test_url : live_url)
  headers = {
    'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8'
  }
  response = parse(ssl_post(url, post_data(action, parameters), headers))

  Response.new(
    success_from(response),
    message_from(response),
    response,
    authorization: authorization_from(response),
    test: test?
  )
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/bank_frick.rb, line 155
def message_from(response)
  response[:return]
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/bank_frick.rb, line 121
def parse(body)
  results  = {}
  xml = Nokogiri::XML(body)
  resp = xml.xpath("//Response/Transaction/Identification")
  resp.children.each do |element|
    results[element.name.downcase.to_sym] = element.text
  end
  resp = xml.xpath("//Response/Transaction/Processing")
  resp.children.each do |element|
    results[element.name.downcase.to_sym] = element.text
  end
  results
end
post_data(action, parameters = {}) click to toggle source
# File lib/active_merchant/billing/gateways/bank_frick.rb, line 163
def post_data(action, parameters = {})
  xml = build_xml_request(action, parameters)
  "load=#{CGI.escape(xml)}"
end
success_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/bank_frick.rb, line 151
def success_from(response)
  response[:result] == 'ACK'
end