Class: Hps::HpsService
- Inherits:
-
Object
- Object
- Hps::HpsService
- Defined in:
- lib/hps/services/hps_service.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#exception_mapper ⇒ Object
Returns the value of attribute exception_mapper.
Instance Method Summary collapse
-
#doTransaction(transaction, client_txn_id = nil) ⇒ Object
protected.
- #gateway_url_for_key(api_key) ⇒ Object
- #hydrate_transaction_header(header) ⇒ Object
-
#initialize(options = {}) ⇒ HpsService
constructor
A new instance of HpsService.
Constructor Details
#initialize(options = {}) ⇒ HpsService
Returns a new instance of HpsService.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/hps/services/hps_service.rb', line 10 def initialize(={}) = Hps..merge() Configuration::VALID_CONFIG_KEYS.each do |key| send("#{key}=", [key]) end @exception_mapper = Hps::ExceptionMapper.new end |
Instance Attribute Details
#exception_mapper ⇒ Object
Returns the value of attribute exception_mapper.
6 7 8 |
# File 'lib/hps/services/hps_service.rb', line 6 def exception_mapper @exception_mapper end |
Instance Method Details
#doTransaction(transaction, client_txn_id = nil) ⇒ Object
protected
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# 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. && self..verify_mode http.verify_mode = self..verify_mode http.ca_file = self..ca_file if self..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) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# 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) ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/hps/services/hps_service.rb', line 113 def hydrate_transaction_header(header) result = HpsTransactionHeader.new result.gateway_response_code = header["GatewayRspCode"] result. = header["GatewayRspMsg"] result.response_dt = header["RspDT"] result.client_txn_id = header["GatewayTxnId"] result end |