class ActiveMerchant::Billing::NcrSecurePayGateway

Public Class Methods

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

Public Instance Methods

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

  commit('preauth', post)
end
capture(money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/ncr_secure_pay.rb, line 39
def capture(money, authorization, options={})
  post = {}
  add_reference(post, authorization)
  add_invoice(post, money, options)

  commit('preauthcomplete', post)
end
purchase(money, payment, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/ncr_secure_pay.rb, line 21
def purchase(money, payment, options={})
  post = {}
  add_invoice(post, money, options)
  add_payment(post, payment)
  add_address(post, payment, options)

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

  commit('credit', post)
end
scrub(transcript) click to toggle source
# File lib/active_merchant/billing/gateways/ncr_secure_pay.rb, line 72
def scrub(transcript)
  transcript.gsub(%r((<password>)[^<]*(</password>))i, '\1[FILTERED]\2').
    gsub(%r((<account>)[^<]*(</account>))i, '\1[FILTERED]\2').
    gsub(%r((<cv>)[^<]*(</cv>))i, '\1[FILTERED]\2')
end
supports_scrubbing?() click to toggle source
# File lib/active_merchant/billing/gateways/ncr_secure_pay.rb, line 68
def supports_scrubbing?
  true
end
verify(credit_card, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/ncr_secure_pay.rb, line 61
def verify(credit_card, options={})
  MultiResponse.run(:use_first_response) do |r|
    r.process { authorize(100, credit_card, options) }
    r.process(:ignore_result) { void(r.authorization, options) }
  end
end
void(authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/ncr_secure_pay.rb, line 55
def void(authorization, options={})
  post = {}
  add_reference(post, authorization)
  commit('void', post)
end

Private Instance Methods

add_address(post, payment, options) click to toggle source
# File lib/active_merchant/billing/gateways/ncr_secure_pay.rb, line 84
def add_address(post, payment, options)
  address = options[:billing_address] || options[:address]
  post[:zip] = address[:zip]
  post[:street] = address[:address1]
end
add_invoice(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/ncr_secure_pay.rb, line 90
def add_invoice(post, money, options)
  post[:amount] = amount(money)
  post[:currency] = (options[:currency] || currency(money))
  post[:descmerch] = options[:merchant] if options[:merchant]
  post[:ordernum] = options[:order_id] if options[:order_id]
  post[:comments] = options[:description] if options[:description]
end
add_payment(post, payment) click to toggle source
# File lib/active_merchant/billing/gateways/ncr_secure_pay.rb, line 98
def add_payment(post, payment)
  post[:cardholdername] = payment.name
  post[:account] = payment.number
  post[:cv] = payment.verification_value
  post[:expdate] = expdate(payment)
end
add_reference(post, reference) click to toggle source
# File lib/active_merchant/billing/gateways/ncr_secure_pay.rb, line 80
def add_reference(post, reference)
  post[:ttid] = reference
end
authorization_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/ncr_secure_pay.rb, line 139
def authorization_from(response)
  response[:ttid]
end
commit(action, parameters) click to toggle source
# File lib/active_merchant/billing/gateways/ncr_secure_pay.rb, line 117
def commit(action, parameters)
  url = (test? ? test_url : live_url)
  response = parse(ssl_post(url, request_body(action, parameters)))

  Response.new(
    success_from(response),
    message_from(response),
    response,
    authorization: authorization_from(response),
    test: test?,
    error_code: error_code_from(response)
  )
end
error_code_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/ncr_secure_pay.rb, line 158
def error_code_from(response)
  unless success_from(response)
    response[:msoft_code] || response[:phard_code]
  end
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/ncr_secure_pay.rb, line 135
def message_from(response)
  response[:verbiage]
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/ncr_secure_pay.rb, line 105
def parse(body)
  doc = Nokogiri::XML(body)
  doc.remove_namespaces!
  response = doc.xpath('/MonetraResp/Resp')[0]
  resp_params = {}

  response.elements.each do |node|
    resp_params[node.name.downcase.to_sym] = node.text
  end
  resp_params
end
request_body(action, parameters = {}) click to toggle source
# File lib/active_merchant/billing/gateways/ncr_secure_pay.rb, line 143
def request_body(action, parameters = {})
  Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
    xml.MonetraTrans do
      xml.Trans(identifier: parameters.delete(:identifier) || '1') do
        xml.username(options[:username])
        xml.password(options[:password])
        xml.action(action)
        parameters.each do |name, value|
          xml.send(name, value)
        end
      end
    end
  end.to_xml
end
success_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/ncr_secure_pay.rb, line 131
def success_from(response)
  response[:code] == 'AUTH'
end