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 62
def initialize(options = {})
  requires!(options, :login, :password)
  super
end

Public Instance Methods

add_3dsecure(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 67
def add_3dsecure(post, options)
  # ECI=02 => MasterCard success
  # ECI=05 => Visa, Amex or JCB success
  if options[:eci] == '02' || options[:eci] == '05'
    post[:"3DSTATUS"] = 'Y'
    post[:"3DENROLLED"] = 'Y'
    post[:"3DSIGNVAL"] = 'Y'
    post[:"3DERROR"] = '0'
  else
    post[:"3DSTATUS"] = 'N'
    post[:"3DENROLLED"] = 'N'
    post[:"3DSIGNVAL"] = 'N'
    post[:"3DERROR"] = '10000'
  end
  post[:"3DECI"] = options[:eci]
  post[:"3DXID"] = options[:xid]
  post[:"3DCAVV"] = options[:cavv]
  post[:"3DCAVVALGO"] = options[:cavv_algorithm]
end
authorize(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 87
def authorize(money, creditcard, options = {})
  post = {}
  add_invoice(post, options)
  add_creditcard(post, creditcard)
  add_3dsecure(post, options[:three_d_secure]) if options[:three_d_secure]
  add_amount(post, money, options)

  commit('authorization', money, post)
end
capture(money, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 107
def capture(money, authorization, options = {})
  requires!(options, :order_id)
  post = {}
  add_invoice(post, options)
  add_amount(post, money, 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 130
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 97
def purchase(money, creditcard, options = {})
  post = {}
  add_invoice(post, options)
  add_creditcard(post, creditcard)
  add_3dsecure(post, options[:three_d_secure]) if options[:three_d_secure]
  add_amount(post, money, options)

  commit('purchase', money, post)
end
refund(money, identification, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 135
def refund(money, identification, options = {})
  post = {}
  add_invoice(post, options)
  add_reference(post, identification)
  add_amount(post, money, options)
  commit('refund', money, post)
end
void(identification, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 118
def void(identification, options = {})
  requires!(options, :order_id, :amount)
  post = {}
  add_invoice(post, options)
  add_reference(post, identification)
  add_amount(post, options[:amount], options)
  post[:porteur] = '000000000000000'
  post[:dateval] = '0000'

  commit('void', options[:amount], post)
end

Private Instance Methods

add_amount(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 160
def add_amount(post, money, options)
  post[:montant] = ('0000000000' + (money ? amount(money) : ''))[-10..-1]
  post[:devise] = CURRENCY_CODES[options[:currency] || currency(money)]
end
add_creditcard(post, creditcard) click to toggle source
# File lib/active_merchant/billing/gateways/paybox_direct.rb, line 149
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 145
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 155
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 174
def commit(action, money = nil, parameters = nil)
  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| %w[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 197
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 165
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 201
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[: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 193
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 189
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 217
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