class ActiveMerchant::Billing::BpointGateway

Public Class Methods

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

Public Instance Methods

authorize(amount, credit_card, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 37
def authorize(amount, credit_card, options={})
  request_body = soap_request do |xml|
    process_payment(xml) do |payment_xml|
      add_authorize(payment_xml, amount, credit_card, options)
    end
  end
  commit(request_body)
end
capture(amount, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 46
def capture(amount, authorization, options={})
  request_body = soap_request do |xml|
    process_payment(xml) do |payment_xml|
      add_capture(payment_xml, amount, authorization, options)
    end
  end
  commit(request_body)
end
purchase(amount, credit_card, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 28
def purchase(amount, credit_card, options={})
  request_body = soap_request do |xml|
    process_payment(xml) do |payment_xml|
      add_purchase(payment_xml, amount, credit_card, options)
    end
  end
  commit(request_body)
end
refund(amount, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 55
def refund(amount, authorization, options={})
  request_body = soap_request do |xml|
    process_payment(xml) do |payment_xml|
      add_refund(payment_xml, amount, authorization, options)
    end
  end
  commit(request_body)
end
scrub(transcript) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 84
def scrub(transcript)
  transcript.
    gsub(%r((<password>).+(</password>)), '\1[FILTERED]\2').
    gsub(%r((<CardNumber>).+(</CardNumber>)), '\1[FILTERED]\2').
    gsub(%r((<CVC>).+(</CVC>)), '\1[FILTERED]\2')
end
store(credit_card, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 20
def store(credit_card, options={})
  options[:crn1] ||= 'DEFAULT'
  request_body = soap_request do |xml|
    add_token(xml, credit_card, options)
  end
  commit(request_body)
end
supports_scrubbing?() click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 80
def supports_scrubbing?
  true
end
verify(credit_card, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 73
def verify(credit_card, options={})
  MultiResponse.run(:use_first_response) do |r|
    r.process { authorize(100, credit_card, options) }
    r.process(:ignore_result) { void(100, r.authorization, options) }
  end
end
void(amount, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 64
def void(amount, authorization, options={})
  request_body = soap_request do |xml|
    process_payment(xml) do |payment_xml|
      add_void(payment_xml, amount, authorization, options)
    end
  end
  commit(request_body)
end

Private Instance Methods

add_authorize(xml, amount, credit_card, options) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 142
def add_authorize(xml, amount, credit_card, options)
  payment_xml(xml, 'PREAUTH', amount, options)
  credit_card_xml(xml, credit_card)
end
add_capture(xml, amount, transaction_number, options) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 147
def add_capture(xml, amount, transaction_number, options)
  payment_xml(xml, 'CAPTURE', amount, options)
  transaction_number_xml(xml, transaction_number)
end
add_purchase(xml, amount, credit_card, options) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 137
def add_purchase(xml, amount, credit_card, options)
  payment_xml(xml, 'PAYMENT', amount, options)
  credit_card_xml(xml, credit_card)
end
add_refund(xml, amount, transaction_number, options) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 152
def add_refund(xml, amount, transaction_number, options)
  payment_xml(xml, 'REFUND', amount, options)
  transaction_number_xml(xml, transaction_number)
end
add_token(xml, credit_card, options) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 118
def add_token(xml, credit_card, options)
  xml.send('AddToken', { 'xmlns' => 'urn:Eve_1_4_4' }) {
    credentials_xml(xml)
    xml.send('tokenRequest') {
      xml.send('CRN1', options[:crn1])
      xml.send('CRN2', '')
      xml.send('CRN3', '')
      xml.send('CardNumber', credit_card.number)
      xml.send('ExpiryDate', expdate(credit_card))
    }
  }
end
add_void(xml, amount, transaction_number, options) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 157
def add_void(xml, amount, transaction_number, options)
  payment_xml(xml, 'REVERSAL', amount, options)
  transaction_number_xml(xml, transaction_number)
end
commit(request_body) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 183
def commit(request_body)
  parse(ssl_post(live_url, request_body, request_headers))
end
credentials_xml(xml) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 131
def credentials_xml(xml)
  xml.send('username', @options[:username])
  xml.send('password', @options[:password])
  xml.send('merchantNumber', @options[:merchant_number])
end
credit_card_xml(xml, credit_card) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 173
def credit_card_xml(xml, credit_card)
  xml.send('CardNumber', credit_card.number)
  xml.send('ExpiryDate', expdate(credit_card))
  xml.send('CVC', credit_card.verification_value)
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 191
def parse(body)
  response_for(Nokogiri::XML(body).remove_namespaces!)
end
payment_xml(xml, payment_type, amount, options) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 162
def payment_xml(xml, payment_type, amount, options)
  xml.send('PaymentType', payment_type)
  xml.send('TxnType', 'WEB_SHOP')
  xml.send('BillerCode', options.fetch(:biller_code, ''))
  xml.send('MerchantReference', options[:order_id]) if options[:order_id]
  xml.send('CRN1', options[:crn1]) if options[:crn1]
  xml.send('CRN2', options[:crn2]) if options[:crn2]
  xml.send('CRN3', options[:crn3]) if options[:crn3]
  xml.send('Amount', amount)
end
process_payment(xml) { |xml| ... } click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 109
def process_payment(xml)
  xml.send('ProcessPayment', { 'xmlns' => 'urn:Eve_1_4_4' }) {
    credentials_xml(xml)
    xml.send('txnReq') {
      yield(xml) if block_given?
    }
  }
end
request_headers() click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 187
def request_headers
  { 'Content-Type' => 'application/soap+xml; charset=utf-8' }
end
response_for(xml_doc) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 195
def response_for(xml_doc)
  if xml_doc.xpath('//ProcessPaymentResponse').any?
    ProcessPaymentResponse.new(xml_doc, self).to_response
  elsif xml_doc.xpath('//AddTokenResponse').any?
    AddTokenResponse.new(xml_doc, self).to_response
  end
end
soap_envelope_attributes() click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 103
def soap_envelope_attributes
  { 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
    'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
    'xmlns:soap12' => 'http://www.w3.org/2003/05/soap-envelope' }
end
soap_request() { |xml| ... } click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 93
def soap_request
  Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
    xml.send('soap12:Envelope', soap_envelope_attributes) {
      xml.send('soap12:Body') {
        yield(xml) if block_given?
      }
    }
  end.to_xml
end
transaction_number_xml(xml, transaction_number) click to toggle source
# File lib/active_merchant/billing/gateways/bpoint.rb, line 179
def transaction_number_xml(xml, transaction_number)
  xml.send('OriginalTransactionNumber', transaction_number)
end