class ActiveMerchant::Billing::Be2billGateway

Public Class Methods

new(options = {}) click to toggle source

These options are mandatory on be2bill (cf. tests) :

options = { :order_id => order.id,

:customer_id => user.id,
:description => "Some description",
:referrer    => request.env['HTTP_REFERER'],
:user_agent  => request.env['HTTP_USER_AGENT'],
:ip          => request.remote_ip,
:email       => user.email }
Calls superclass method ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/be2bill.rb, line 26
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/be2bill.rb, line 31
def authorize(money, creditcard, options = {})
  post = {}
  add_invoice(post, options)
  add_creditcard(post, creditcard)
  add_customer_data(post, options)

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

  commit('capture', money, post)
end
purchase(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/be2bill.rb, line 40
def purchase(money, creditcard, options = {})
  post = {}
  add_invoice(post, options)
  add_creditcard(post, creditcard)
  add_customer_data(post, options)

  commit('payment', money, post)
end

Private Instance Methods

add_creditcard(post, creditcard) click to toggle source
# File lib/active_merchant/billing/gateways/be2bill.rb, line 72
def add_creditcard(post, creditcard)
  post[:CARDFULLNAME]     = creditcard ? creditcard.name : ''
  post[:CARDCODE]         = creditcard ? creditcard.number : ''
  post[:CARDVALIDITYDATE] = creditcard ? '%02d-%02s' % [creditcard.month, creditcard.year.to_s[-2..-1]] : ''
  post[:CARDCVV]          = creditcard ? creditcard.verification_value : ''
end
add_customer_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/be2bill.rb, line 59
def add_customer_data(post, options)
  post[:CLIENTREFERRER]  = options[:referrer]
  post[:CLIENTUSERAGENT] = options[:user_agent]
  post[:CLIENTIP]        = options[:ip]
  post[:CLIENTEMAIL]     = options[:email]
  post[:CLIENTIDENT]     = options[:customer_id]
end
add_invoice(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/be2bill.rb, line 67
def add_invoice(post, options)
  post[:ORDERID]     = options[:order_id]
  post[:DESCRIPTION] = options[:description]
end
commit(action, money, parameters) click to toggle source
# File lib/active_merchant/billing/gateways/be2bill.rb, line 83
def commit(action, money, parameters)
  parameters[:IDENTIFIER] = @options[:login]
  parameters[:AMOUNT]     = amount(money)
  parameters[:VERSION]    = '2.0'

  url = (test? ? self.test_url : self.live_url)
  response = parse(ssl_post(url, post_data(action, parameters)))

  Response.new(
    successful?(response),
    message_from(response),
    response,
    :authorization => response['TRANSACTIONID'],
    :test          => test?
  )
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/be2bill.rb, line 104
def message_from(response)
  if successful?(response)
    "Approved : #{response['MESSAGE']}"
  else
    "Declined (#{response['EXECCODE']} - #{response['MESSAGE']}"
  end
end
parse(response) click to toggle source
# File lib/active_merchant/billing/gateways/be2bill.rb, line 79
def parse(response)
  ActiveSupport::JSON.decode(response)
end
post_data(action, parameters = {}) click to toggle source
# File lib/active_merchant/billing/gateways/be2bill.rb, line 112
def post_data(action, parameters = {})
  {
    :method => action,
    :params => parameters.merge(HASH: signature(parameters, action))
  }.to_query
end
signature(parameters, action) click to toggle source
# File lib/active_merchant/billing/gateways/be2bill.rb, line 119
def signature(parameters, action)
  parameters[:OPERATIONTYPE] = action unless parameters[:OPERATIONTYPE]

  signature = @options[:password]
  parameters.sort.each do |key, value|
    signature += ("#{key.upcase}=#{value}" + @options[:password])
  end

  Digest::SHA256.hexdigest(signature)
end
successful?(response) click to toggle source
# File lib/active_merchant/billing/gateways/be2bill.rb, line 100
def successful?(response)
  %w(0000 0001).include?(response['EXECCODE'])
end