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 18 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 41 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 23 def purchase(money, payment, options={}) post = {} post[:TransType] = '1' add_invoice(post, money, options) add_payment_method(post, payment) commit('sale', post) end
refund(money, authorization, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 49 def refund(money, authorization, options={}) post = {} post[:TransType] = '3' add_invoice(post, money, options) add_reference(post, authorization) commit('refund', post) end
void(authorization, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 57 def void(authorization, options={}) post = {} # TransType and TrAmount must match original values from auth or purchase. _, _, _, _, _, transtype, tramount = split_authorization(authorization) post[:TransType] = transtype add_invoice(post, tramount.to_i, options) add_reference(post, authorization) commit('void', post) end
Private Instance Methods
add_invoice(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 73 def add_invoice(post, money, options) post[:TrAmount] = amount(money) post[:TrCurrency] = CURRENCY_CODES[options[:currency] || currency(money)] end
add_payment_method(post, payment_method)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 78 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 86 def add_reference(post, authorization) dateandtime, batch, transaction, rrn, authcode, _, _ = split_authorization(authorization) post[:DateAndTime] = dateandtime post[:Batch] = batch post[:Transaction] = transaction post[:RRN] = rrn post[:AuthCode] = authcode end
build_request(action, post)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 173 def build_request(action, post) mode = (action == 'void') ? 'cancel' : 'get' xml = Builder::XmlMarkup.new :indent => 18 xml.instruct!(:xml, :version => '1.0', :encoding => 'utf-8') xml.tag!("#{mode}Authorization") do post.each do |field, value| xml.tag!(field, value) end end inner = CGI.escapeHTML(xml.target!) envelope(mode).sub(/{{ :body }}/,inner) end
commit(action, post)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 117 def commit(action, post) post[:Version] = '1000' post[:Processor] = @options[:processor] post[:MerchantID] = @options[:merchant_id] post[:TerminalID] = 1 url = (test? ? test_url : live_url) request = build_request(action, post) raw = ssl_post(url(action), request, headers) pairs = parse(raw) success = success_from(pairs) Response.new( success, message_from(success, pairs), pairs, authorization: authorization_from(pairs), test: test? ) end
envelope(mode)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 186 def envelope(mode) <<-EOS <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:aut="http://Borgun/Heimir/pub/ws/Authorization"> <soapenv:Header/> <soapenv:Body> <aut:#{mode}AuthorizationInput> <#{mode}AuthReqXml> {{ :body }} </#{mode}AuthReqXml> </aut:#{mode}AuthorizationInput> </soapenv:Body> </soapenv:Envelope> EOS end
headers()
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 167 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 142 def message_from(succeeded, response) if succeeded "Succeeded" else response[:message] || "Error with ActionCode=#{response[:actioncode]}" end end
parse(xml)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 95 def parse(xml) response = {} doc = Nokogiri::XML(CGI.unescapeHTML(xml)) body = 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 205 def six_random_digits (0...6).map { (48 + rand(10)).chr }.join end
success_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 138 def success_from(response) (response[:actioncode] == '000') end
url(action)
click to toggle source
# File lib/active_merchant/billing/gateways/borgun.rb, line 201 def url(action) (test? ? test_url : live_url) end