class ActiveMerchant::Billing::BamboraApacGateway

Constants

STANDARD_ERROR_CODE_MAPPING

Public Class Methods

new(options={}) click to toggle source
Calls superclass method ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 24
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/bambora_apac.rb, line 42
def authorize(money, payment, options={})
  commit('SubmitSinglePayment') do |xml|
    xml.Transaction do
      xml.CustRef options[:order_id]
      add_amount(xml, money)
      xml.TrnType '2'
      add_payment(xml, payment)
      add_credentials(xml, options)
      xml.TrnSource options[:ip]
    end
  end
end
capture(money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 55
def capture(money, authorization, options={})
  commit('SubmitSingleCapture') do |xml|
    xml.Capture do
      xml.Receipt authorization
      add_amount(xml, money)
      add_credentials(xml, options)
    end
  end
end
purchase(money, payment, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 29
def purchase(money, payment, options={})
  commit('SubmitSinglePayment') do |xml|
    xml.Transaction do
      xml.CustRef options[:order_id]
      add_amount(xml, money)
      xml.TrnType '1'
      add_payment(xml, payment)
      add_credentials(xml, options)
      xml.TrnSource options[:ip]
    end
  end
end
refund(money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 65
def refund(money, authorization, options={})
  commit('SubmitSingleRefund') do |xml|
    xml.Refund do
      xml.Receipt authorization
      add_amount(xml, money)
      add_credentials(xml, options)
    end
  end
end
scrub(transcript) click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 102
def scrub(transcript)
  transcript.
    gsub(%r((<CardNumber>)[^<]+(<))i, '\1[FILTERED]\2').
    gsub(%r((<CVN>)[^<]+(<))i, '\1[FILTERED]\2').
    gsub(%r((<Password>)[^<]+(<))i, '\1[FILTERED]\2')
end
store(payment, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 85
def store(payment, options={})
  commit('TokeniseCreditCard') do |xml|
    xml.TokeniseCreditCard do
      xml.CardNumber payment.number
      xml.ExpM format(payment.month, :two_digits)
      xml.ExpY format(payment.year, :four_digits)
      xml.TokeniseAlgorithmID options[:tokenise_algorithm_id] || 2
      xml.UserName @options[:username]
      xml.Password @options[:password]
    end
  end
end
supports_scrubbing?() click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 98
def supports_scrubbing?
  true
end
void(money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 75
def void(money, authorization, options={})
  commit('SubmitSingleVoid') do |xml|
    xml.Void do
      xml.Receipt authorization
      add_amount(xml, money)
      add_credentials(xml, options)
    end
  end
end

Private Instance Methods

add_amount(xml, money) click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 119
def add_amount(xml, money)
  xml.Amount amount(money)
end
add_credentials(xml, options) click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 111
def add_credentials(xml, options)
  xml.AccountNumber options[:account_number] if options[:account_number]
  xml.Security do
    xml.UserName @options[:username]
    xml.Password @options[:password]
  end
end
add_credit_card(xml, payment) click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 138
def add_credit_card(xml, payment)
  xml.CreditCard :Registered => 'False' do
    xml.CardNumber payment.number
    xml.ExpM format(payment.month, :two_digits)
    xml.ExpY format(payment.year, :four_digits)
    xml.CVN payment.verification_value
    xml.CardHolderName payment.name
  end
end
add_payment(xml, payment) click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 123
def add_payment(xml, payment)
  if payment.is_a?(String)
    add_token(xml, payment)
  else
    add_credit_card(xml, payment)
  end
end
add_token(xml, payment) click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 131
def add_token(xml, payment)
  xml.CreditCard do
    xml.TokeniseAlgorithmID options[:tokenise_algorithm_id] || 2
    xml.CardNumber payment
  end
end
authorization_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 221
def authorization_from(response)
  response[:receipt] || response[:token]
end
commit(action, &block) click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 159
def commit(action, &block)
  headers = {
    'Content-Type' => 'text/xml; charset=utf-8',
    'SOAPAction' => "http://www.ippayments.com.au/interface/api/#{endpoint(action)}/#{action}"
  }
  response = parse(ssl_post("#{commit_url}/#{endpoint(action)}.asmx", new_submit_xml(action, &block), headers))

  Response.new(
    success_from(response),
    message_from(response),
    response,
    authorization: authorization_from(response),
    error_code: error_code_from(response),
    test: test?
  )
end
commit_url() click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 205
def commit_url
  test? ? test_url : live_url
end
endpoint(action) click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 201
def endpoint(action)
  action == 'TokeniseCreditCard' ? 'sipp' : 'dts'
end
error_code_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 213
def error_code_from(response)
  STANDARD_ERROR_CODE_MAPPING[response[:declined_code]]
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 217
def message_from(response)
  success_from(response) ? 'Succeeded' : response[:declined_message]
end
new_submit_xml(action) { |inner_xml| ... } click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 176
def new_submit_xml(action)
  xml = Builder::XmlMarkup.new(indent: 2)
  xml.instruct!
  xml.soap :Envelope, 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema', 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/' do
    xml.soap :Body do
      xml.__send__(action, 'xmlns' => "http://www.ippayments.com.au/interface/api/#{endpoint(action)}") do
        if action == 'TokeniseCreditCard'
          xml.tokeniseCreditCardXML do
            inner_xml = Builder::XmlMarkup.new(indent: 2)
            yield(inner_xml)
            xml.cdata!(inner_xml.target!)
          end
        else
          xml.trnXML do
            inner_xml = Builder::XmlMarkup.new(indent: 2)
            yield(inner_xml)
            xml.cdata!(inner_xml.target!)
          end
        end
      end
    end
  end
  xml.target!
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 148
def parse(body)
  element = Nokogiri::XML(body).root.first_element_child.first_element_child

  response = {}
  doc = Nokogiri::XML(element)
  doc.root.elements.each do |e|
    response[e.name.underscore.to_sym] = e.inner_text
  end
  response
end
success_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/bambora_apac.rb, line 209
def success_from(response)
  response[:response_code] == '0' || response[:return_value] == '0'
end