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 24
def initialize(options={})
  requires!(options, :sender, :channel, :login, :password)
  super
end

Public Instance Methods

authorize(money, payment, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 49
def authorize(money, payment, options={})
  request = build_xml_request do |xml|
    add_payment(xml, money, 'authonly', options)
    add_account(xml, payment)
    add_customer(xml, payment, options)
    add_recurrence_mode(xml, options)
  end

  commit(request)
end
capture(money, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 60
def capture(money, authorization, options={})
  request = build_xml_request do |xml|
    add_identification(xml, 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 29
def purchase(money, payment, options={})
  request = build_xml_request do |xml|
    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 40
def refund(money, authorization, options={})
  request = build_xml_request do |xml|
    add_identification(xml, 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 89
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
supports_scrubbing?() click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 85
def supports_scrubbing?
  true
end
verify(credit_card, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 78
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 69
def void(authorization, options={})
  request = build_xml_request do |xml|
    add_identification(xml, authorization)
    add_payment(xml, nil, 'void', options)
  end

  commit(request)
end

Private Instance Methods

add_account(xml, creditcard) click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 115
def add_account(xml, creditcard)
  xml.Account do
    xml.Number        creditcard.number
    xml.Holder        "#{creditcard.first_name} #{creditcard.last_name}"
    xml.Brand         creditcard.brand
    xml.Expiry(year: creditcard.year, month: creditcard.month)
    xml.Verification  creditcard.verification_value
  end
end
add_address(xml, address) click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 142
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 125
def add_customer(xml, creditcard, options)
  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, authorization) click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 98
def add_identification(xml, authorization)
  xml.Identification do
    xml.ReferenceID authorization
  end
end
add_payment(xml, money, action, options) click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 104
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 154
def add_recurrence_mode(xml, options)
  if options[:recurring] == true
    xml.Recurrence(mode: "REPEATED")
  else
    xml.Recurrence(mode: "INITIAL")
  end
end
authorization_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 201
def authorization_from(response)
  response[:uniqueid]
end
build_xml_request() { |xml| ... } click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 209
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 176
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 197
def message_from(response)
  response[:return]
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 162
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 205
def post_data(xml)
  "load=#{xml}"
end
success_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/s5.rb, line 193
def success_from(response)
  response[:result] == 'ACK'
end