class ActiveMerchant::Billing::S5Gateway
Constants
- SUPPORTED_TRANSACTIONS
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/s5.rb, line 25 def initialize(options = {}) requires!(options, :sender, :channel, :login, :password) super end
Public Instance Methods
capture(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 63 def capture(money, authorization, options = {}) request = build_xml_request do |xml| add_identification(xml, options, authorization) add_payment(xml, money, 'capture', options) end commit(request) end
purchase(money, payment, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 30 def purchase(money, payment, options = {}) request = build_xml_request do |xml| add_identification(xml, options) add_payment(xml, money, 'sale', options) add_account(xml, payment) add_customer(xml, payment, options) add_recurrence_mode(xml, options) end commit(request) end
refund(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 42 def refund(money, authorization, options = {}) request = build_xml_request do |xml| add_identification(xml, options, authorization) add_payment(xml, money, 'refund', options) end commit(request) end
scrub(transcript)
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 103 def scrub(transcript) transcript. gsub(%r((pwd=).+?(/>))i, '\1[FILTERED]\2'). gsub(%r((<Number>).+?(</Number>))i, '\1[FILTERED]\2'). gsub(%r((<Verification>).+?(</Verification>))i, '\1[FILTERED]\2') end
store(payment, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 81 def store(payment, options = {}) request = build_xml_request do |xml| xml.Payment(code: SUPPORTED_TRANSACTIONS['store']) add_account(xml, payment) add_customer(xml, payment, options) add_recurrence_mode(xml, options) end commit(request) end
supports_scrubbing?()
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 99 def supports_scrubbing? true end
verify(credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 92 def verify(credit_card, options = {}) MultiResponse.run(:use_first_response) do |r| r.process { authorize(100, credit_card, options) } r.process(:ignore_result) { void(r.authorization, options) } end end
void(authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 72 def void(authorization, options = {}) request = build_xml_request do |xml| add_identification(xml, options, authorization) add_payment(xml, nil, 'void', options) end commit(request) end
Private Instance Methods
add_account(xml, payment_method)
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 130 def add_account(xml, payment_method) if payment_method.respond_to?(:number) xml.Account do xml.Number payment_method.number xml.Holder "#{payment_method.first_name} #{payment_method.last_name}" xml.Brand payment_method.brand xml.Expiry(year: payment_method.year, month: payment_method.month) xml.Verification payment_method.verification_value end else xml.Account(registration: payment_method) end end
add_address(xml, address)
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 163 def add_address(xml, address) return unless address xml.Address do xml.Street "#{address[:address1]} #{address[:address2]}" xml.Zip address[:zip] xml.City address[:city] xml.State address[:state] xml.Country address[:country] end end
add_customer(xml, creditcard, options)
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 144 def add_customer(xml, creditcard, options) return unless creditcard.respond_to?(:number) address = options[:billing_address] xml.Customer do xml.Contact do xml.Email options[:email] xml.Ip options[:ip] xml.Phone address[:phone] if address end add_address(xml, address) xml.Name do xml.Given creditcard.first_name xml.Family creditcard.last_name xml.Company options[:company] end end end
add_identification(xml, options, authorization = nil)
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 112 def add_identification(xml, options, authorization = nil) xml.Identification do xml.TransactionID options[:order_id] if options[:order_id] xml.ReferenceID authorization if authorization end end
add_payment(xml, money, action, options)
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 119 def add_payment(xml, money, action, options) xml.Payment(code: SUPPORTED_TRANSACTIONS[action]) do xml.Memo "return_code=#{options[:memo]}" if options[:memo] xml.Presentation do xml.Amount amount(money) xml.Currency options[:currency] || currency(money) xml.Usage options[:description] end end end
add_recurrence_mode(xml, options)
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 175 def add_recurrence_mode(xml, options) if options[:recurring] == true xml.Recurrence(mode: 'REPEATED') else xml.Recurrence(mode: 'INITIAL') end end
build_xml_request() { |xml| ... }
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 230 def build_xml_request builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| xml.Request(version: '1.0') do xml.Header do xml.Security(sender: @options[:sender]) end xml.Transaction(mode: @options[:mode] || 'LIVE', channel: @options[:channel]) do xml.User(login: @options[:login], pwd: @options[:password]) yield(xml) end end end builder.to_xml end
commit(xml)
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 197 def commit(xml) url = (test? ? test_url : live_url) headers = { 'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8' } response = parse(ssl_post(url, post_data(xml), headers)) Response.new( success_from(response), message_from(response), response, authorization: authorization_from(response), test: test? ) end
message_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 218 def message_from(response) response[:return] end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 183 def parse(body) results = {} xml = Nokogiri::XML(body) resp = xml.xpath('//Response/Transaction/Identification') resp.children.each do |element| results[element.name.downcase.to_sym] = element.text end resp = xml.xpath('//Response/Transaction/Processing') resp.children.each do |element| results[element.name.downcase.to_sym] = element.text end results end
post_data(xml)
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 226 def post_data(xml) "load=#{xml}" end
success_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 214 def success_from(response) response[:result] == 'ACK' end