class ActiveMerchant::Billing::BridgePayGateway

Public Class Methods

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

Public Instance Methods

authorize(amount, creditcard, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 34
def authorize(amount, creditcard, options={})
  post = post_required_fields("Auth")

  add_invoice(post, amount, options)
  add_creditcard(post, creditcard)
  add_customer_data(post, options)

  commit(post)
end
capture(amount, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 44
def capture(amount, authorization, options={})
  post = post_required_fields("Force")

  add_invoice(post, amount, options)
  add_reference(post, authorization)
  add_customer_data(post, options)

  commit(post)
end
purchase(amount, creditcard, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 22
def purchase(amount, creditcard, options={})
  post = post_required_fields("Sale")

  # Allow the same amount in multiple transactions.
  post[:ExtData] = "<Force>T</Force>"
  add_invoice(post, amount, options)
  add_creditcard(post, creditcard)
  add_customer_data(post, options)

  commit(post)
end
refund(amount, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 54
def refund(amount, authorization, options={})
  post = post_required_fields("Return")

  add_invoice(post, amount, options)
  add_reference(post, authorization)

  commit(post)
end
verify(creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 71
def verify(creditcard, options = {})
  MultiResponse.run(:use_first_response) do |r|
    r.process { authorize(100, creditcard, options) }
    r.process(:ignore_result) { void(r.authorization, options) }
  end
end
void(authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 63
def void(authorization, options={})
  post = post_required_fields("Void")

  add_reference(post, authorization)

  commit(post)
end

Private Instance Methods

add_creditcard(post, creditcard) click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 110
def add_creditcard(post, creditcard)
  post[:NameOnCard] = creditcard.name if creditcard.name
  post[:ExpDate]    = expdate(creditcard)
  post[:CardNum]    = creditcard.number
  post[:CVNum]      = creditcard.verification_value
end
add_customer_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 98
def add_customer_data(post, options)
  if(billing_address = (options[:billing_address] || options[:address]))
    post[:Street] = billing_address[:address1]
    post[:Zip]    = billing_address[:zip]
  end
end
add_invoice(post, amount, options) click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 105
def add_invoice(post, amount, options)
  post[:Amount] = amount(amount)
  post[:InvNum] = options[:order_id]
end
add_reference(post, authorization) click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 175
def add_reference(post, authorization)
  authcode, pnref = split_authorization(authorization)
  post[:AuthCode] = authcode
  post[:PNRef] = pnref
end
authorization_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 166
def authorization_from(response)
  [response[:authcode], response[:pnref]].join("|")
end
commit(parameters) click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 139
def commit(parameters)
  url = (test? ? test_url : live_url)
  data = post_data(parameters)
  raw = parse(ssl_post(url, data))

  Response.new(
    success_from(raw[:respmsg]),
    message_from(raw),
    raw,
    authorization: authorization_from(raw),
    test: test?
  )
end
expdate(creditcard) click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 117
def expdate(creditcard)
  "#{format(creditcard.month, :two_digits)}#{format(creditcard.year, :two_digits)}"
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 162
def message_from(response)
  response[:respmsg]
end
parse(xml) click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 121
def parse(xml)
  response = {}

  doc = Nokogiri::XML(xml)
  doc.root.xpath("*").each do |node|
    if (node.elements.size == 0)
      response[node.name.downcase.to_sym] = node.text
    else
      node.elements.each do |childnode|
        name = "#{node.name.downcase}_#{childnode.name.downcase}"
        response[name.to_sym] = childnode.text
      end
    end
  end unless doc.root.nil?

  response
end
post_data(post) click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 181
def post_data(post)
  {
    :UserName => @options[:user_name],
    :Password => @options[:password]
  }.merge(post).collect{|k,v| "#{k}=#{CGI.escape(v.to_s)}"}.join("&")
end
post_required_fields(transaction_type) click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 80
def post_required_fields(transaction_type)
  post = {}
  post[:TransType] = transaction_type
  post[:Amount] = ""
  post[:PNRef] = ""
  post[:InvNum] = ""
  post[:CardNum] = ""
  post[:ExpDate] = ""
  post[:MagData] = ""
  post[:NameOnCard] = ""
  post[:Zip] = ""
  post[:Street] = ""
  post[:CVNum] = ""
  post[:MagData] = ""
  post[:ExtData] = ""
  post
end
split_authorization(authorization) click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 170
def split_authorization(authorization)
  authcode, pnref = authorization.split("|")
  [authcode, pnref]
end
success_from(result) click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 153
def success_from(result)
  case result
  when "Approved"
    true
  else
    false
  end
end