class ActiveMerchant::Billing::PayboxDirectGateway

Constants

API_VERSION

Payment API Version

CURRENCY_CODES
FAILURE_MESSAGE
SUCCESS_CODES
SUCCESS_MESSAGE
TRANSACTIONS

Transactions hash

UNAVAILABILITY_CODES

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 61
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/paybox_direct.rb, line 66
def authorize(money, creditcard, options = {})
  post = {}
  add_invoice(post, options)
  add_creditcard(post, creditcard)
  commit('authorization', money, post)
end
capture(money, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 80
def capture(money, authorization, options = {})
  requires!(options, :order_id)
  post = {}
  add_invoice(post, options)
  post[:numappel] = authorization[0,10]
  post[:numtrans] = authorization[10,10]
  commit('capture', money, post)
end
credit(money, identification, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 99
def credit(money, identification, options = {})
  ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
  refund(money, identification, options)
end
purchase(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 73
def purchase(money, creditcard, options = {})
  post = {}
  add_invoice(post, options)
  add_creditcard(post, creditcard)
  commit('purchase', money, post)
end
refund(money, identification, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 104
def refund(money, identification, options = {})
  post = {}
  add_invoice(post, options)
  add_reference(post, identification)
  commit('refund', money, post)
end
void(identification, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 89
def void(identification, options = {})
  requires!(options, :order_id, :amount)
  post ={}
  add_invoice(post, options)
  add_reference(post, identification)
  post[:porteur] = '000000000000000'
  post[:dateval] = '0000'
  commit('void', options[:amount], post)
end

Private Instance Methods

add_creditcard(post, creditcard) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 117
def add_creditcard(post, creditcard)
  post[:porteur] = creditcard.number
  post[:dateval] = expdate(creditcard)
  post[:cvv] = creditcard.verification_value if creditcard.verification_value?
end
add_invoice(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 113
def add_invoice(post, options)
  post[:reference] = options[:order_id]
end
add_reference(post, identification) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 123
def add_reference(post, identification)
  post[:numappel] = identification[0,10]
  post[:numtrans] = identification[10,10]
end
commit(action, money = nil, parameters = nil) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 137
def commit(action, money = nil, parameters = nil)
  parameters[:montant] = ('0000000000' + (money ? amount(money) : ''))[-10..-1]
  parameters[:devise] = CURRENCY_CODES[options[:currency] || currency(money)]
  request_data = post_data(action,parameters)
  response = parse(ssl_post(test? ? self.test_url : self.live_url, request_data))
  response = parse(ssl_post(self.live_url_backup, request_data)) if service_unavailable?(response) && !test?
  Response.new(success?(response), message_from(response), response.merge(
    :timestamp => parameters[:dateq]),
    :test => test?,
    :authorization => response[:numappel].to_s + response[:numtrans].to_s,
    :fraud_review => false,
    :sent_params => parameters.delete_if{|key,value| ['porteur','dateval','cvv'].include?(key.to_s)}
  )
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 160
def message_from(response)
  success?(response) ? SUCCESS_MESSAGE : (response[:commentaire]  || FAILURE_MESSAGE)
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 128
def parse(body)
  results = {}
  body.split(/&/).each do |pair|
    key,val = pair.split(/\=/)
    results[key.downcase.to_sym] = CGI.unescape(val) if val
  end
  results
end
post_data(action, parameters = {}) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 164
def post_data(action, parameters = {})

  parameters.update(
    :version => API_VERSION,
    :type => TRANSACTIONS[action.to_sym],
    :dateq => Time.now.strftime('%d%m%Y%H%M%S'),
    :numquestion => unique_id(parameters[:order_id]),
    :site => @options[:login].to_s[0,7],
    :rang => @options[:login].to_s[7..-1],
    :cle => @options[:password],
    :pays => '',
    :archivage => parameters[:order_id]
  )

  parameters.collect { |key, value| "#{key.to_s.upcase}=#{CGI.escape(value.to_s)}" }.join("&")
end
service_unavailable?(response) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 156
def service_unavailable?(response)
  UNAVAILABILITY_CODES.include?(response[:codereponse])
end
success?(response) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 152
def success?(response)
  SUCCESS_CODES.include?(response[:codereponse])
end
unique_id(seed = 0) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 181
def unique_id(seed = 0)
  randkey = "#{seed}#{Time.now.usec}".to_i % 2147483647 # Max paybox value for the question number

  "0000000000#{randkey}"[-10..-1]
end