class ActiveMerchant::Billing::Flo2cashGateway
Constants
- BRAND_MAP
- CURRENCY_CODES
- 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/flo2cash.rb, line 22 def initialize(options={}) requires!(options, :username, :password, :account_id) super end
Public Instance Methods
capture(amount, authorization, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/flo2cash.rb, line 43 def capture(amount, authorization, options={}) post = {} add_invoice(post, amount, options) add_reference(post, authorization) add_customer_data(post, options) commit('ProcessCapture', post) end
purchase(amount, payment_method, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/flo2cash.rb, line 27 def purchase(amount, payment_method, options={}) MultiResponse.run do |r| r.process { authorize(amount, payment_method, options) } r.process { capture(amount, r.authorization, options) } end end
refund(amount, authorization, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/flo2cash.rb, line 52 def refund(amount, authorization, options={}) post = {} add_invoice(post, amount, options) add_reference(post, authorization) add_customer_data(post, options) commit('ProcessRefund', post) end
scrub(transcript)
click to toggle source
# File lib/active_merchant/billing/gateways/flo2cash.rb, line 65 def scrub(transcript) transcript. gsub(%r((<Password>)[^<]+(<))i, '\1[FILTERED]\2'). gsub(%r((<CardNumber>)[^<]+(<))i, '\1[FILTERED]\2'). gsub(%r((<CardCSC>)[^<]+(<))i, '\1[FILTERED]\2') end
supports_scrubbing?()
click to toggle source
# File lib/active_merchant/billing/gateways/flo2cash.rb, line 61 def supports_scrubbing? true end
Private Instance Methods
add_customer_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/flo2cash.rb, line 91 def add_customer_data(post, options) if(billing_address = (options[:billing_address] || options[:address])) post[:Email] = billing_address[:email] end end
add_invoice(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/flo2cash.rb, line 77 def add_invoice(post, money, options) post[:Amount] = amount(money) post[:Reference] = options[:order_id] post[:Particular] = options[:description] end
add_payment_method(post, payment_method)
click to toggle source
# File lib/active_merchant/billing/gateways/flo2cash.rb, line 83 def add_payment_method(post, payment_method) post[:CardNumber] = payment_method.number post[:CardType] = BRAND_MAP[payment_method.brand.to_s] post[:CardExpiry] = format(payment_method.month, :two_digits) + format(payment_method.year, :two_digits) post[:CardHolderName] = payment_method.name post[:CardCSC] = payment_method.verification_value end
add_reference(post, authorization)
click to toggle source
# File lib/active_merchant/billing/gateways/flo2cash.rb, line 97 def add_reference(post, authorization) post[:OriginalTransactionId] = authorization end
build_request(action, post)
click to toggle source
# File lib/active_merchant/billing/gateways/flo2cash.rb, line 135 def build_request(action, post) xml = Builder::XmlMarkup.new :indent => 2 post.each do |field, value| xml.tag!(field, value) end body = xml.target! envelope_wrap(action, body) end
commit(action, post)
click to toggle source
# File lib/active_merchant/billing/gateways/flo2cash.rb, line 101 def commit(action, post) post[:Username] = @options[:username] post[:Password] = @options[:password] post[:AccountId] = @options[:account_id] data = build_request(action, post) begin raw = parse(ssl_post(url, data, headers(action)), action) rescue ActiveMerchant::ResponseError => e if(e.response.code == '500' && e.response.body.start_with?('<?xml')) raw = parse(e.response.body, action) else raise end end succeeded = success_from(raw[:status]) Response.new( succeeded, message_from(succeeded, raw), raw, :authorization => authorization_from(action, raw[:transaction_id], post[:OriginalTransactionId]), :error_code => error_code_from(succeeded, raw), :test => test? ) end
envelope_wrap(action, body)
click to toggle source
# File lib/active_merchant/billing/gateways/flo2cash.rb, line 144 def envelope_wrap(action, body) <<-EOS <soap12:Envelope 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"> <soap12:Body> <#{action} xmlns="http://www.flo2cash.co.nz/webservices/paymentwebservice"> #{body} </#{action}> </soap12:Body> </soap12:Envelope> EOS end
error_code_from(succeeded, response)
click to toggle source
# File lib/active_merchant/billing/gateways/flo2cash.rb, line 210 def error_code_from(succeeded, response) succeeded ? nil : STANDARD_ERROR_CODE_MAPPING[response[:message]] end
headers(action)
click to toggle source
# File lib/active_merchant/billing/gateways/flo2cash.rb, line 128 def headers(action) { 'Content-Type' => 'application/soap+xml; charset=utf-8', 'SOAPAction' => %{"http://www.flo2cash.co.nz/webservices/paymentwebservice/#{action}"} } end
message_from(succeeded, response)
click to toggle source
# File lib/active_merchant/billing/gateways/flo2cash.rb, line 185 def message_from(succeeded, response) if succeeded 'Succeeded' else response[:message] || response[:errormessage] || 'Unable to read error message' end end
parse(body, action)
click to toggle source
# File lib/active_merchant/billing/gateways/flo2cash.rb, line 161 def parse(body, action) response = {} xml = REXML::Document.new(body) root = (REXML::XPath.first(xml, "//#{action}Response") || REXML::XPath.first(xml, '//detail')) root.elements.to_a.each do |node| parse_element(response, node) end if root response end
parse_element(response, node)
click to toggle source
# File lib/active_merchant/billing/gateways/flo2cash.rb, line 173 def parse_element(response, node) if node.has_elements? node.elements.each { |element| parse_element(response, element) } else response[node.name.underscore.to_sym] = node.text end end
success_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/flo2cash.rb, line 181 def success_from(response) response == 'SUCCESSFUL' end
url()
click to toggle source
# File lib/active_merchant/billing/gateways/flo2cash.rb, line 157 def url (test? ? test_url : live_url) end