class HeartlandPortico

Additional Note: No idea what schema version that's for, or if it ever returns anything except latest :(

Constants

SUPPORTED_REQUEST_METHODS

Attributes

credentials[R]

Public Class Methods

new(credentials, test=false) click to toggle source
# File lib/heartland_portico.rb, line 11
def initialize(credentials, test=false)
  @credentials = credentials
  @test = test
end

Private Instance Methods

camelize(string) click to toggle source
# File lib/heartland_portico.rb, line 35
def camelize(string)
  # Couldn't get ActiveSupport to load standalone, rolling my own
  string.to_s.gsub(/(?:^|_)(.)/) { $1.upcase }
end
client() click to toggle source
# File lib/heartland_portico.rb, line 40
def client
  Savon.client do |savon|
    savon.wsdl wsdl_path
    savon.soap_version 2
    savon.endpoint endpoint

    # savon.log_level :debug
    # savon.log true

    savon.convert_request_keys_to :camelcase
    savon.pretty_print_xml true
  end
end
client_call(operation, params) click to toggle source
# File lib/heartland_portico.rb, line 54
def client_call(operation, params)
  message = xml_message(operation) do |xml|
    if pin_block?(operation)
      xml.tag!("tns:Block1") do
        xml_build(xml, params)
      end
    else
      xml_build(xml, params)
    end
  end
  Response.new(operation, client.call(:do_transaction, :message_tag => 'PosRequest', :message => message))
end
endpoint() click to toggle source
# File lib/heartland_portico.rb, line 67
def endpoint
  if @test
    "https://cert.api2.heartlandportico.com/Hps.Exchange.PosGateway/POSGatewayService.asmx"
  else
    "https://api2.heartlandportico.com/Hps.Exchange.PosGateway/PosGatewayService.asmx"
  end
end
pin_block?(operation) click to toggle source
# File lib/heartland_portico.rb, line 75
def pin_block?(operation)
  %w(
    check_sale
    check_void
    credit_account_verify
    credit_auth
    credit_sale
    credit_return
    credit_reversal
  ).include? operation.to_s
end
wsdl_path() click to toggle source

Loaded live in production, or from a local cache for testing

# File lib/heartland_portico.rb, line 88
def wsdl_path
  if @test
    File.expand_path(File.join(__FILE__, '..', 'wsdl.xml'))
  else
    "#{endpoint}?wsdl=wsdl1"
  end
end
xml_build(xml, values) click to toggle source
# File lib/heartland_portico.rb, line 96
def xml_build(xml, values)
  values.keys.sort_by{|k|k.to_s}.each do |key|
    value = values[key]
    tag = "tns:#{camelize(key)}"

    if value.to_s.empty?
      # Skip empty values
    elsif value.kind_of? Hash
      xml.tag!(tag) { xml_build(xml, value) }
    else
      xml.tag!(tag, value)
    end
  end
end
xml_message(operation) { |xml| ... } click to toggle source
# File lib/heartland_portico.rb, line 111
def xml_message(operation)
  xml = Builder::XmlMarkup.new
  xml.tag!("tns:Ver1.0") do
    xml.tag!("tns:Header") do
      xml_build(xml, credentials)
    end
    xml.tag!("tns:Transaction") do
      xml.tag!("tns:#{camelize(operation)}") do
        yield xml
      end
    end
  end
end