class ActiveMerchant::Billing::PaywayGateway

Constants

RESPONSE_CODES
SUMMARY_CODES
TRANSACTIONS

Public Class Methods

new(options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/payway.rb, line 86
def initialize(options = {})
  @options = options

  @options[:merchant] ||= 'TEST' if test?
  requires!(options, :username, :password, :merchant, :pem)

  @options[:eci] ||= 'SSL'
end

Public Instance Methods

authorize(amount, payment_method, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/payway.rb, line 95
def authorize(amount, payment_method, options = {})
  requires!(options, :order_id)

  post = {}
  add_payment_method(post, payment_method)
  add_order(post, amount, options)
  commit(:authorize, post)
end
capture(amount, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/payway.rb, line 104
def capture(amount, authorization, options = {})
  requires!(options, :order_id)

  post = {}
  add_reference(post, authorization)
  add_order(post, amount, options)
  commit(:capture, post)
end
purchase(amount, payment_method, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/payway.rb, line 113
def purchase(amount, payment_method, options = {})
  requires!(options, :order_id)

  post = {}
  add_payment_method(post, payment_method)
  add_order(post, amount, options)
  commit(:purchase, post)
end
refund(amount, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/payway.rb, line 122
def refund(amount, authorization, options = {})
  requires!(options, :order_id)

  post = {}
  add_reference(post, authorization)
  add_order(post, amount, options)
  commit(:refund, post)
end
status(options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/payway.rb, line 140
def status(options = {})
  requires!(options, :order_id)

  commit(:status, 'customer.orderNumber' => options[:order_id])
end
store(credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/payway.rb, line 131
def store(credit_card, options = {})
  requires!(options, :billing_id)

  post = {}
  add_payment_method(post, credit_card)
  add_payment_method(post, options[:billing_id])
  commit(:store, post)
end

Private Instance Methods

add_auth(post) click to toggle source
# File lib/active_merchant/billing/gateways/payway.rb, line 171
def add_auth(post)
  post['customer.username'] = @options[:username]
  post['customer.password'] = @options[:password]
  post['customer.merchant'] = @options[:merchant]
end
add_order(post, amount, options) click to toggle source
# File lib/active_merchant/billing/gateways/payway.rb, line 164
def add_order(post, amount, options)
  post['order.ECI']            = @options[:eci]
  post['order.amount']         = amount
  post['card.currency']        = (options[:currency] || currency(amount))
  post['customer.orderNumber'] = options[:order_id][0...20]
end
add_payment_method(post, payment_method) click to toggle source
# File lib/active_merchant/billing/gateways/payway.rb, line 148
def add_payment_method(post, payment_method)
  if payment_method.respond_to?(:number)
    post['card.cardHolderName'] = "#{payment_method.first_name} #{payment_method.last_name}"
    post['card.PAN']            = payment_method.number
    post['card.CVN']            = payment_method.verification_value
    post['card.expiryYear']     = payment_method.year.to_s[-2, 2]
    post['card.expiryMonth']    = sprintf('%02d', payment_method.month)
  else
    post['customer.customerReferenceNumber'] = payment_method
  end
end
add_reference(post, reference) click to toggle source
# File lib/active_merchant/billing/gateways/payway.rb, line 160
def add_reference(post, reference)
  post['customer.originalOrderNumber'] = reference
end
commit(action, post) click to toggle source

Creates the request and returns the summarized result

# File lib/active_merchant/billing/gateways/payway.rb, line 178
def commit(action, post)
  add_auth(post)
  post['order.type'] = TRANSACTIONS[action]

  request = post.map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')
  response = ssl_post(self.live_url, request)

  params = {}
  CGI.parse(response).each_pair do |key, value|
    actual_key = key.split('.').last
    params[actual_key.underscore.to_sym] = value[0]
  end

  message = "#{SUMMARY_CODES[params[:summary_code]]} - #{RESPONSE_CODES[params[:response_code]]}"

  success = (params[:summary_code] ? (params[:summary_code] == '0') : (params[:response_code] == '00'))

  Response.new(
    success,
    message,
    params,
    test: (@options[:merchant].to_s == 'TEST'),
    authorization: post[:order_number]
  )
rescue ActiveMerchant::ResponseError => e
  raise unless e.response.code == '403'

  return Response.new(false, 'Invalid credentials', {}, test: test?)
rescue ActiveMerchant::ClientCertificateError
  return Response.new(false, 'Invalid certificate', {}, test: test?)
end