class ActiveMerchant::Billing::PayWayGateway

Constants

RESPONSE_CODES
SUMMARY_CODES
TRANSACTIONS
URL

Public Class Methods

new(options = {}) click to toggle source

Create a new Payway gateway.

Calls superclass method
# File lib/active_merchant/billing/gateways/pay_way.rb, line 88
def initialize(options = {})
  requires!(options, :username, :password, :pem)
  @options = options
  
  @options[:eci]      ||= 'SSL'
  @options[:currency] ||= default_currency
  @options[:merchant] ||= 'TEST'
  @options[:pem]        = File.read(options[:pem])
  
  @post = {}
  @transaction = {}
  
  super
end

Public Instance Methods

authorize(amount, credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_way.rb, line 118
def authorize(amount, credit_card, options = {})
  requires!(options, :order_number)
  
  @transaction.merge!({ :order_number => options[:order_number] })
  
  process(:authorize, amount, credit_card)
end
capture(amount, credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_way.rb, line 126
def capture(amount, credit_card, options = {})
  requires!(options, :order_number, :original_order_number)
  
  @transaction.merge!({ 
    :order_number           => options[:order_number],
    :original_order_number  => options[:original_order_number]
  })
  
  process(:capture, amount, credit_card)
end
credit(amount, credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_way.rb, line 145
def credit(amount, credit_card, options = {})
  requires!(options, :order_number, :original_order_number)
  
  
  @transaction.merge!({ 
    :order_number           => options[:order_number],
    :original_order_number  => options[:original_order_number]
  })
  
  process(:credit, amount, credit_card)
end
process(action, amount, credit_card) click to toggle source

Build the string and send it

# File lib/active_merchant/billing/gateways/pay_way.rb, line 104
def process(action, amount, credit_card)
  @transaction.merge!({
    :type         => action,
    :amount       => amount,
    :credit_card  => credit_card
  })
  
  build_card
  build_order
  build_customer
  
  send_post
end
purchase(amount, credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_way.rb, line 137
def purchase(amount, credit_card, options = {})
  requires!(options, :order_number)
  
  @transaction.merge!({ :order_number => options[:order_number] })
  
  process(:purchase, amount, credit_card)
end
status(options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/pay_way.rb, line 157
def status(options = {})
  requires!(options, :order_number)
  @transaction = transaction
  @transaction[:type] = TRANSACTIONS[:status]
  
  build_order
  
  send_post
end

Private Instance Methods

build_card() click to toggle source

Adds credit card details to the post hash

# File lib/active_merchant/billing/gateways/pay_way.rb, line 170
def build_card
  card = @transaction[:credit_card]
  @post.merge!({
    'card.cardHolderName' => "#{card.first_name} #{card.last_name}",
    'card.PAN'            => card.number,
    'card.CVN'            => card.verification_value,
    'card.expiryYear'     => card.year.to_s[-2,2],
    'card.expiryMonth'    => sprintf('%02d', card.month),
    'card.currency'       => @options[:currency]
  })
end
build_customer() click to toggle source

Adds the customer arguments to the post hash

# File lib/active_merchant/billing/gateways/pay_way.rb, line 196
def build_customer
  @post.merge!({
    'customer.username'   => @options[:username],
    'customer.password'   => @options[:password],
    'customer.merchant'   => @options[:merchant],
    'customer.orderNumber'=> "#{@transaction[:order_number]} - #{Time.new.to_i.to_s}",
  })
end
build_order() click to toggle source

Adds the order arguments to the post hash

# File lib/active_merchant/billing/gateways/pay_way.rb, line 183
def build_order
  @post.merge!({
    'order.ECI'           => @options[:eci],
    'order.amount'        => @transaction[:amount],
    'order.type'          => TRANSACTIONS[@transaction[:type]]
  })
  
  if @transaction[:original_order_number].present?
    @post['order.originalOrderNumber'] = @transaction[:original_order_number]
  end
end
process_response() click to toggle source
# File lib/active_merchant/billing/gateways/pay_way.rb, line 214
def process_response
  params = {}
  
  @response.split("&").each do |items|
    key, value = items.split("=")
    key = key.split('.')[1]
    params[key.underscore.to_sym] = value
  end
  
  msg     = "#{SUMMARY_CODES[params[:summary_code]]} - #{RESPONSE_CODES[params[:response_code]]}"
  
  success = params[:summary_code].to_s == "0"
  options = { :test => @options[:merchant].to_s == "TEST" }
  
  result = Response.new(success, msg, params, options)
end
send_post() click to toggle source

Creates the request and returns the sumarised result

# File lib/active_merchant/billing/gateways/pay_way.rb, line 206
def send_post
  @request = URI.encode(@post.map {|k,v| "#{k}=#{v}"}.join('&'))
  
  @response = ssl_post(URL, @request)
  
  result = process_response
end