class ActiveMerchant::Billing::FirstPayGateway

Public Class Methods

new(options={}) click to toggle source
Calls superclass method ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/first_pay.rb, line 16
def initialize(options={})
  requires!(options, :transaction_center_id, :gateway_id)
  super
end

Public Instance Methods

authorize(money, payment, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/first_pay.rb, line 31
def authorize(money, payment, options={})
  post = {}
  add_invoice(post, money, options)
  add_payment(post, payment)
  add_address(post, payment, options)
  add_customer_data(post, options)

  commit('auth', post)
end
capture(money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/first_pay.rb, line 41
def capture(money, authorization, options={})
  post = {}
  add_reference(post, 'settle', money, authorization)
  commit('settle', post)
end
purchase(money, payment, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/first_pay.rb, line 21
def purchase(money, payment, options={})
  post = {}
  add_invoice(post, money, options)
  add_payment(post, payment)
  add_address(post, payment, options)
  add_customer_data(post, options)

  commit('sale', post)
end
refund(money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/first_pay.rb, line 47
def refund(money, authorization, options={})
  post = {}
  add_reference(post, 'credit', money, authorization)
  commit('credit', post)
end
void(authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/first_pay.rb, line 53
def void(authorization, options={})
  post = {}
  add_reference(post, 'void', nil, authorization)
  commit('void', post)
end

Private Instance Methods

add_address(post, creditcard, options) click to toggle source
# File lib/active_merchant/billing/gateways/first_pay.rb, line 71
def add_address(post, creditcard, options)
  address = options[:billing_address] || options[:address]
  post[:owner_name] = address[:name]
  post[:owner_street] = address[:address1]
  post[:owner_street2] = address[:address2] if address[:address2]
  post[:owner_city] = address[:city]
  post[:owner_state] = address[:state]
  post[:owner_zip] = address[:zip]
  post[:owner_country] = address[:country]
  post[:owner_phone] = address[:phone] if address[:phone]
end
add_authentication(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/first_pay.rb, line 61
def add_authentication(post, options)
  post[:transaction_center_id] = options[:transaction_center_id]
  post[:gateway_id] = options[:gateway_id]
end
add_customer_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/first_pay.rb, line 66
def add_customer_data(post, options)
  post[:owner_email] = options[:email] if options[:email]
  post[:remote_ip_address] = options[:ip] if options[:ip]
end
add_invoice(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/first_pay.rb, line 83
def add_invoice(post, money, options)
  post[:order_id] = options[:order_id]
  post[:total] = amount(money)
end
add_payment(post, payment) click to toggle source
# File lib/active_merchant/billing/gateways/first_pay.rb, line 88
def add_payment(post, payment)
  post[:card_name] = payment.brand # Unclear if need to map to known names or open text field??
  post[:card_number] = payment.number
  post[:card_exp] = expdate(payment)
  post[:cvv2] = payment.verification_value
end
add_reference(post, action, money, authorization) click to toggle source
# File lib/active_merchant/billing/gateways/first_pay.rb, line 95
def add_reference(post, action, money, authorization)
  post[:"#{action}_amount1"] = amount(money) if money
  post[:total_number_transactions] = 1
  post[:reference_number1] = authorization
end
authorization_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/first_pay.rb, line 137
def authorization_from(response)
  response['reference_number'] || response['reference_number1']
end
commit(action, parameters) click to toggle source
# File lib/active_merchant/billing/gateways/first_pay.rb, line 112
def commit(action, parameters)
  response = parse(ssl_post(live_url, post_data(action, parameters)))

  Response.new(
    success_from(response),
    message_from(response),
    response,
    authorization: authorization_from(response),
    test: test?
  )
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/first_pay.rb, line 131
def message_from(response)
  # Silly inconsistent gateway. Always make capitalized (but not all caps)
  msg = (response['auth_response'] || response['response1'])
  msg.downcase.capitalize if msg
end
parse(xml) click to toggle source
# File lib/active_merchant/billing/gateways/first_pay.rb, line 101
def parse(xml)
  response = {}

  doc = Nokogiri::XML(xml)
  doc.root.xpath("//RESPONSE/FIELDS/FIELD").each do |field|
    response[field['KEY']] = field.text
  end unless doc.root.nil?

  response
end
post_data(action, parameters = {}) click to toggle source
# File lib/active_merchant/billing/gateways/first_pay.rb, line 141
def post_data(action, parameters = {})
  parameters[:transaction_center_id] = @options[:transaction_center_id]
  parameters[:gateway_id] = @options[:gateway_id]

  parameters[:operation_type] = action

  xml = Builder::XmlMarkup.new
  xml.instruct!
  xml.tag! 'TRANSACTION' do
    xml.tag! 'FIELDS' do
      parameters.each do |key, value|
        xml.tag! 'FIELD', value, { 'KEY' => key }
      end
    end
  end
  xml.target!
end
success_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/first_pay.rb, line 124
def success_from(response)
  (
    (response['status'] == '1') ||
    (response['status1'] == '1')
  )
end