class ActiveMerchant::Billing::BorgunGateway
Constants
- CURRENCY_CODES
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/borgun.rb, line 19 def initialize(options = {}) requires!(options, :processor, :merchant_id, :username, :password) super end
Public Instance Methods
capture(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 56 def capture(money, authorization, options = {}) post = {} post[:TransType] = '1' add_invoice(post, money, options) add_reference(post, authorization) commit('capture', post) end
purchase(money, payment, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 24 def purchase(money, payment, options = {}) post = {} action = '' if options[:apply_3d_secure] == '1' add_3ds_preauth_fields(post, options) action = '3ds_preauth' else post[:TransType] = '1' add_3ds_fields(post, options) action = 'sale' end add_invoice(post, money, options) add_payment_method(post, payment) commit(action, post, options) end
refund(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 64 def refund(money, authorization, options = {}) post = {} post[:TransType] = '3' add_invoice(post, money, options) add_reference(post, authorization) commit('refund', post) end
scrub(transcript)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 87 def scrub(transcript) transcript.gsub(%r((<PAN>)[^&]*(</PAN>))i, '\1[FILTERED]\2'). gsub(%r((<CVC2>)[^&]*(</CVC2>))i, '\1[FILTERED]\2'). gsub(%r(((?:\r\n)?Authorization: Basic )[^\r\n]+(\r\n)?), '\1[FILTERED]\2') end
supports_scrubbing()
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 83 def supports_scrubbing true end
void(authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 72 def void(authorization, options = {}) post = {} # TransType, TrAmount, and currency must match original values from auth or purchase. _, _, _, _, _, transtype, tramount, currency = split_authorization(authorization) post[:TransType] = transtype options[:currency] = options[:currency] || CURRENCY_CODES.key(currency) add_invoice(post, tramount.to_i, options) add_reference(post, authorization) commit('void', post) end
Private Instance Methods
add_3ds_fields(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 101 def add_3ds_fields(post, options) post[:ThreeDSMessageId] = options[:three_ds_message_id] if options[:three_ds_message_id] post[:ThreeDS_PARes] = options[:three_ds_pares] if options[:three_ds_pares] post[:ThreeDS_CRes] = options[:three_ds_cres] if options[:three_ds_cres] end
add_3ds_preauth_fields(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 107 def add_3ds_preauth_fields(post, options) post[:SaleDescription] = options[:sale_description] || '' post[:MerchantReturnURL] = options[:redirect_url] if options[:redirect_url] end
add_invoice(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 112 def add_invoice(post, money, options) post[:TrAmount] = amount(money) post[:TrCurrency] = CURRENCY_CODES[options[:currency] || currency(money)] # The ISK currency must have a currency exponent of 2 on the 3DS request but not on the auth request if post[:TrCurrency] == '352' && options[:apply_3d_secure] != '1' post[:TrCurrencyExponent] = 0 else post[:TrCurrencyExponent] = 2 end post[:TerminalID] = options[:terminal_id] || '1' end
add_payment_method(post, payment_method)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 124 def add_payment_method(post, payment_method) post[:PAN] = payment_method.number post[:ExpDate] = format(payment_method.year, :two_digits) + format(payment_method.month, :two_digits) post[:CVC2] = payment_method.verification_value post[:DateAndTime] = Time.now.strftime('%y%m%d%H%M%S') post[:RRN] = 'AMRCNT' + six_random_digits end
add_reference(post, authorization)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 132 def add_reference(post, authorization) dateandtime, _batch, transaction, rrn, authcode, = split_authorization(authorization) post[:DateAndTime] = dateandtime post[:Transaction] = transaction post[:RRN] = rrn post[:AuthCode] = authcode end
build_airline_xml(xml, airline_data)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 233 def build_airline_xml(xml, airline_data) xml.tag!('PassengerItineraryData') do xml.tag!('A1') do airline_data.each do |field, value| xml.tag!(field, value) end end end end
build_request(action, post, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 218 def build_request(action, post, options = {}) mode = action == 'void' ? 'cancel' : 'get' transaction_type = action == '3ds_preauth' ? '3DSAuthentication' : 'Authorization' xml = Builder::XmlMarkup.new indent: 18 xml.instruct!(:xml, version: '1.0', encoding: 'utf-8') xml.tag!("#{mode}#{transaction_type}") do post.each do |field, value| xml.tag!(field, value) end build_airline_xml(xml, options[:passenger_itinerary_data]) if options[:passenger_itinerary_data] end inner = CGI.escapeHTML(xml.target!) envelope(mode, action).sub(/{{ :body }}/, inner) end
commit(action, post, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 161 def commit(action, post, options = {}) post[:Version] = '1000' post[:Processor] = @options[:processor] post[:MerchantID] = @options[:merchant_id] request = build_request(action, post, options) raw = ssl_post(url(action), request, headers) pairs = parse(raw, options) success = success_from(pairs) Response.new( success, message_from(success, pairs), pairs, authorization: authorization_from(pairs, options), test: test? ) end
envelope(mode, action)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 243 def envelope(mode, action) if action == '3ds_preauth' transaction_action = "#{mode}3DSAuthentication" request_action = "#{mode}Auth3DSReqXml" else transaction_action = "#{mode}AuthorizationInput" request_action = "#{mode}AuthReqXml" end <<-XML <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:aut="http://Borgun/Heimir/pub/ws/Authorization"> <soapenv:Header/> <soapenv:Body> <aut:#{transaction_action}> <#{request_action}> {{ :body }} </#{request_action}> </aut:#{transaction_action}> </soapenv:Body> </soapenv:Envelope> XML end
headers()
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 212 def headers { 'Authorization' => 'Basic ' + Base64.strict_encode64(@options[:username].to_s + ':' + @options[:password].to_s) } end
message_from(succeeded, response)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 184 def message_from(succeeded, response) if succeeded 'Succeeded' else response[:message] || response[:status_errormessage] || "Error with ActionCode=#{response[:actioncode]}" end end
parse(xml, options = nil)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 140 def parse(xml, options = nil) response = {} doc = Nokogiri::XML(CGI.unescapeHTML(xml)) body = options[:apply_3d_secure] == '1' ? doc.xpath('//get3DSAuthenticationReply') : doc.xpath('//getAuthorizationReply') body = doc.xpath('//cancelAuthorizationReply') if body.length == 0 body.children.each do |node| if node.text? next elsif 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 response end
six_random_digits()
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 269 def six_random_digits (0...6).map { rand(48..57).chr }.join end
success_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 180 def success_from(response) (response[:actioncode] == '000') || (response[:status_resultcode] == '0') end
url(action)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 265 def url(action) (test? ? test_url : live_url) end