class ActiveMerchant::Billing::BridgePayGateway
Public Class Methods
new(options={})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 16 def initialize(options={}) requires!(options, :user_name, :password) super end
Public Instance Methods
capture(amount, authorization, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 43 def capture(amount, authorization, options={}) post = initialize_required_fields('Force') add_invoice(post, amount, options) add_reference(post, authorization) add_customer_data(post, options) commit(post) end
purchase(amount, payment_method, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 21 def purchase(amount, payment_method, options={}) post = initialize_required_fields('Sale') # Allow the same amount in multiple transactions. post[:ExtData] = '<Force>T</Force>' add_invoice(post, amount, options) add_payment_method(post, payment_method) add_customer_data(post, options) commit(post) end
refund(amount, authorization, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 53 def refund(amount, authorization, options={}) post = initialize_required_fields('Return') add_invoice(post, amount, options) add_reference(post, authorization) commit(post) end
scrub(transcript)
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 92 def scrub(transcript) transcript. gsub(%r((&?CardNum=)[^&]*)i, '\1[FILTERED]'). gsub(%r((&?CVNum=)[^&]*)i, '\1[FILTERED]'). gsub(%r((&?Password=)[^&]*)i, '\1[FILTERED]'). gsub(%r((&?TransitNum=)[^&]*)i, '\1[FILTERED]'). gsub(%r((&?AccountNum=)[^&]*)i, '\1[FILTERED]') end
store(creditcard, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 77 def store(creditcard, options={}) post = initialize_required_fields('') post[:transaction] = 'Create' post[:CardNumber] = creditcard.number post[:CustomerPaymentInfoKey] = '' post[:token] = '' add_payment_method(post, creditcard) commit(post) end
supports_scrubbing?()
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 88 def supports_scrubbing? true end
verify(creditcard, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 70 def verify(creditcard, options = {}) MultiResponse.run(:use_first_response) do |r| r.process { authorize(100, creditcard, options) } r.process(:ignore_result) { void(r.authorization, options) } end end
void(authorization, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 62 def void(authorization, options={}) post = initialize_required_fields('Void') add_reference(post, authorization) commit(post) end
Private Instance Methods
add_customer_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 149 def add_customer_data(post, options) if(billing_address = (options[:billing_address] || options[:address])) post[:Street] = billing_address[:address1] post[:Zip] = billing_address[:zip] end end
add_invoice(post, amount, options)
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 156 def add_invoice(post, amount, options) post[:Amount] = amount(amount) post[:InvNum] = options[:order_id] end
add_payment_method(post, payment_method)
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 103 def add_payment_method(post, payment_method) if payment_method.respond_to? :brand post[:NameOnCard] = payment_method.name if payment_method.name post[:ExpDate] = expdate(payment_method) post[:CardNum] = payment_method.number post[:CVNum] = payment_method.verification_value elsif payment_method.is_a?(String) add_token(post, payment_method) else post[:CheckNum] = payment_method.number post[:TransitNum] = payment_method.routing_number post[:AccountNum] = payment_method.account_number post[:NameOnCheck] = payment_method.name post[:ExtData] = "<AccountType>#{payment_method.account_type.capitalize}</AccountType>" if payment_method.account_type end end
add_reference(post, authorization)
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 230 def add_reference(post, authorization) authcode, pnref = split_authorization(authorization) post[:AuthCode] = authcode post[:PNRef] = pnref end
add_token(post, payment_method)
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 120 def add_token(post, payment_method) payment_method = payment_method.split('|') post[:ExtData] = "<Force>T</Force><CardVault><Transaction>Read</Transaction><CustomerPaymentInfoKey>#{payment_method[1]}</CustomerPaymentInfoKey><Token>#{payment_method[0]}</Token><ExpDate>#{payment_method[2]}</ExpDate></CardVault>" end
base_url()
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 205 def base_url test? ? test_url : live_url end
commit(parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 183 def commit(parameters) data = post_data(parameters) raw = parse(ssl_post(url(parameters), data)) Response.new( success_from(raw), message_from(raw), raw, authorization: authorization_from(raw), test: test? ) end
expdate(creditcard)
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 161 def expdate(creditcard) "#{format(creditcard.month, :two_digits)}#{format(creditcard.year, :two_digits)}" end
initialize_required_fields(transaction_type)
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 125 def initialize_required_fields(transaction_type) post = {} post[:TransType] = transaction_type post[:Amount] = '' post[:PNRef] = '' post[:InvNum] = '' post[:CardNum] = '' post[:ExpDate] = '' post[:MagData] = '' post[:NameOnCard] = '' post[:Zip] = '' post[:Street] = '' post[:CVNum] = '' post[:MagData] = '' post[:ExtData] = '' post[:MICR] = '' post[:DL] = '' post[:SS] = '' post[:DOB] = '' post[:StateCode] = '' post[:CheckType] = '' post end
message_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 213 def message_from(response) response[:respmsg] || response[:message] end
parse(xml)
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 165 def parse(xml) response = {} doc = Nokogiri::XML(xml) doc.root&.xpath('*')&.each do |node| if 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
post_data(post)
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 236 def post_data(post) { :UserName => @options[:user_name], :Password => @options[:password] }.merge(post).collect { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&') end
success_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 209 def success_from(response) response[:result] == '0' end
url(params)
click to toggle source
# File lib/active_merchant/billing/gateways/bridge_pay.rb, line 196 def url(params) if params[:transaction] "#{base_url}/ManageCardVault" else action = params[:TransitNum] ? 'ProcessCheck' : 'ProcessCreditCard' "#{base_url}/#{action}" end end