lib/active_merchant/billing/gateways/bambora_apac.rb in activemerchant-1.91.0 vs lib/active_merchant/billing/gateways/bambora_apac.rb in activemerchant-1.92.0
- old
+ new
@@ -1,12 +1,12 @@
require 'nokogiri'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class BamboraApacGateway < Gateway
- self.live_url = 'https://www.bambora.co.nz/interface/api/dts.asmx'
- self.test_url = 'https://demo.bambora.co.nz/interface/api/dts.asmx'
+ self.live_url = 'https://www.bambora.co.nz/interface/api'
+ self.test_url = 'https://demo.bambora.co.nz/interface/api'
self.supported_countries = ['AU', 'NZ']
self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :jcb]
self.homepage_url = 'http://www.bambora.com/'
@@ -30,11 +30,11 @@
commit('SubmitSinglePayment') do |xml|
xml.Transaction do
xml.CustRef options[:order_id]
add_amount(xml, money)
xml.TrnType '1'
- add_credit_card(xml, payment)
+ add_payment(xml, payment)
add_credentials(xml, options)
xml.TrnSource options[:ip]
end
end
end
@@ -43,11 +43,11 @@
commit('SubmitSinglePayment') do |xml|
xml.Transaction do
xml.CustRef options[:order_id]
add_amount(xml, money)
xml.TrnType '2'
- add_credit_card(xml, payment)
+ add_payment(xml, payment)
add_credentials(xml, options)
xml.TrnSource options[:ip]
end
end
end
@@ -80,10 +80,23 @@
add_credentials(xml, options)
end
end
end
+ 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
+
def supports_scrubbing?
true
end
def scrub(transcript)
@@ -105,10 +118,25 @@
def add_amount(xml, money)
xml.Amount amount(money)
end
+ def add_payment(xml, payment)
+ if payment.is_a?(String)
+ add_token(xml, payment)
+ else
+ add_credit_card(xml, payment)
+ end
+ end
+
+ def add_token(xml, payment)
+ xml.CreditCard do
+ xml.TokeniseAlgorithmID options[:tokenise_algorithm_id] || 2
+ xml.CardNumber payment
+ end
+ end
+
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)
@@ -129,13 +157,13 @@
end
def commit(action, &block)
headers = {
'Content-Type' => 'text/xml; charset=utf-8',
- 'SOAPAction' => "http://www.ippayments.com.au/interface/api/dts/#{action}",
+ 'SOAPAction' => "http://www.ippayments.com.au/interface/api/#{endpoint(action)}/#{action}"
}
- response = parse(ssl_post(commit_url, new_submit_xml(action, &block), headers))
+ response = parse(ssl_post("#{commit_url}/#{endpoint(action)}.asmx", new_submit_xml(action, &block), headers))
Response.new(
success_from(response),
message_from(response),
response,
@@ -148,39 +176,51 @@
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/dts') do
- xml.trnXML do
- inner_xml = Builder::XmlMarkup.new(indent: 2)
- yield(inner_xml)
- xml.cdata!(inner_xml.target!)
+ 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
+ def endpoint(action)
+ action == 'TokeniseCreditCard' ? 'sipp' : 'dts'
+ end
+
def commit_url
test? ? test_url : live_url
end
def success_from(response)
- response[:response_code] == '0'
+ response[:response_code] == '0' || response[:return_value] == '0'
end
def error_code_from(response)
STANDARD_ERROR_CODE_MAPPING[response[:declined_code]]
end
def message_from(response)
- response[:declined_message]
+ success_from(response) ? 'Succeeded' : response[:declined_message]
end
def authorization_from(response)
- response[:receipt]
+ response[:receipt] || response[:token]
end
end
end
end