class Hps::HpsService

Attributes

exception_mapper[RW]

Public Class Methods

new(options={}) click to toggle source
# File lib/hps/services/hps_service.rb, line 10
          def initialize(options={})

merged_options = Hps.options.merge(options)

Configuration::VALID_CONFIG_KEYS.each do |key|
  send("#{key}=", merged_options[key])
end

                  @exception_mapper = Hps::ExceptionMapper.new
          end

Public Instance Methods

doTransaction(transaction, client_txn_id = nil) click to toggle source

protected

# File lib/hps/services/hps_service.rb, line 23
          def doTransaction(transaction, client_txn_id = nil)

                  if configuration_invalid
  raise @exception_mapper.map_sdk_exception(SdkCodes.invalid_transaction_id)
                  end

xml = Builder::XmlMarkup.new
xml.instruct!(:xml, :encoding => "UTF-8")
xml.SOAP :Envelope, {
  'xmlns:SOAP' => 'http://schemas.xmlsoap.org/soap/envelope/',
  'xmlns:hps' => 'http://Hps.Exchange.PosGateway' } do
  xml.SOAP :Body do
    xml.hps :PosRequest do
      xml.hps 'Ver1.0'.to_sym do
        xml.hps :Header do
          if self.secret_api_key
            self.service_uri = gateway_url_for_key self.secret_api_key
            xml.hps :SecretAPIKey, self.secret_api_key.strip
          else
                          xml.hps :UserName, self.user_name
                          xml.hps :Password, self.password
                          xml.hps :DeviceId, self.device_id
                          xml.hps :LicenseId, self.license_id
                          xml.hps :SiteId, self.site_id
          end
                          xml.hps :DeveloperID, self.developer_id if self.developer_id
                          xml.hps :VersionNbr, self.version_number if self.version_number
                          xml.hps :SiteTrace, self.site_trace if self.site_trace
          xml.hps :ClientTxnId, client_txn_id if client_txn_id
        end

        xml << transaction

      end
    end
  end
end

                  begin

  uri = URI.parse(self.service_uri)
  http = Net::HTTP.new uri.host, uri.port
  http.use_ssl = true

  # allow SSL verification as opt-in
  if self.http_options && self.http_options.verify_mode
    http.verify_mode = self.http_options.verify_mode
    http.ca_file = self.http_options.ca_file if self.http_options.ca_file
  else
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end

  data = xml.target!

  response = http.post(uri.path, data, 'Content-type' => 'text/xml')
  # NOTE: If the HTTP request was successful
  if response.is_a? Net::HTTPOK

    # NOTE: Convert XML to a Hash
    soap_hash = Hash.from_xml(response.body)
    # NOTE: Peel away the layers and return only the PosRespose
    soap_hash["Envelope"]["Body"]["PosResponse"]["Ver1.0"]

  else
                          raise @exception_mapper.map_sdk_exception(SdkCodes.unable_to_process_transaction)
  end

                  rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
 Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
                          raise @exception_mapper.map_sdk_exception(SdkCodes.unable_to_process_transaction, e)
                  end

          end
gateway_url_for_key(api_key) click to toggle source
# File lib/hps/services/hps_service.rb, line 97
def gateway_url_for_key(api_key)

  gateway_url = "https://api2.heartlandportico.com/Hps.Exchange.PosGateway/PosGatewayService.asmx?wsdl"

  if api_key.include? "_uat_"

    gateway_url = "https://posgateway.uat.secureexchange.net/Hps.Exchange.PosGateway/PosGatewayService.asmx?wsdl"

  elsif api_key.include? "_cert_"

    gateway_url = "https://cert.api2.heartlandportico.com/Hps.Exchange.PosGateway/PosGatewayService.asmx?wsdl"
  end

  gateway_url
end
hydrate_transaction_header(header) click to toggle source
# File lib/hps/services/hps_service.rb, line 113
def hydrate_transaction_header(header)
        result = HpsTransactionHeader.new
        result.gateway_response_code = header["GatewayRspCode"]
        result.gateway_response_message = header["GatewayRspMsg"]
        result.response_dt = header["RspDT"]
        result.client_txn_id = header["GatewayTxnId"]
        result
end

Private Instance Methods

configuration_invalid() click to toggle source
# File lib/hps/services/hps_service.rb, line 124
          def configuration_invalid
self.secret_api_key.nil? and (
                  self.service_uri.nil? or
                  self.user_name.nil? or
                  self.password.nil? or
                  self.license_id.nil? or
                  self.device_id.nil? or
                  self.site_id.nil?
)
          end