hps 2.3.2 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +2 -0
  3. data/Gemfile +4 -4
  4. data/Gemfile.lock +77 -0
  5. data/LICENSE.md +264 -264
  6. data/PRIVACY.txt +65 -65
  7. data/README.md +213 -213
  8. data/Rakefile +15 -15
  9. data/examples/sinatra-verify-only/Gemfile +4 -4
  10. data/examples/sinatra-verify-only/app.rb +32 -32
  11. data/examples/sinatra-verify-only/views/index.erb +478 -478
  12. data/examples/sinatra-verify-only/views/result.erb +39 -39
  13. data/hps.gemspec +28 -27
  14. data/lib/hps/configuration.rb +17 -17
  15. data/lib/hps/entities/hps_account_verify.rb +8 -8
  16. data/lib/hps/entities/hps_address.rb +6 -6
  17. data/lib/hps/entities/hps_authorization.rb +12 -12
  18. data/lib/hps/entities/hps_batch.rb +6 -6
  19. data/lib/hps/entities/hps_cardholder.rb +6 -6
  20. data/lib/hps/entities/hps_charge.rb +8 -8
  21. data/lib/hps/entities/hps_charge_exceptions.rb +6 -6
  22. data/lib/hps/entities/hps_check.rb +18 -18
  23. data/lib/hps/entities/hps_check_holder.rb +10 -10
  24. data/lib/hps/entities/hps_check_response.rb +45 -45
  25. data/lib/hps/entities/hps_check_response_details.rb +9 -9
  26. data/lib/hps/entities/hps_credit_card.rb +34 -34
  27. data/lib/hps/entities/hps_direct_market_data.rb +5 -5
  28. data/lib/hps/entities/hps_encryption_data.rb +6 -6
  29. data/lib/hps/entities/hps_gift_card.rb +133 -133
  30. data/lib/hps/entities/hps_manage_tokens.rb +8 -8
  31. data/lib/hps/entities/hps_refund.rb +8 -8
  32. data/lib/hps/entities/hps_report_transaction_details.rb +10 -10
  33. data/lib/hps/entities/hps_report_transaction_summary.rb +6 -6
  34. data/lib/hps/entities/hps_reversal.rb +10 -10
  35. data/lib/hps/entities/hps_token_data.rb +10 -10
  36. data/lib/hps/entities/hps_track_data.rb +5 -5
  37. data/lib/hps/entities/hps_transaction.rb +161 -161
  38. data/lib/hps/entities/hps_transaction_details.rb +6 -6
  39. data/lib/hps/entities/hps_transaction_header.rb +8 -8
  40. data/lib/hps/entities/hps_transaction_type.rb +16 -16
  41. data/lib/hps/entities/hps_void.rb +8 -8
  42. data/lib/hps/infrastructure/api_connection_exception.rb +11 -11
  43. data/lib/hps/infrastructure/authentication_exception.rb +11 -11
  44. data/lib/hps/infrastructure/card_exception.rb +15 -15
  45. data/lib/hps/infrastructure/exceptions.json +547 -547
  46. data/lib/hps/infrastructure/hps_account_type.rb +11 -11
  47. data/lib/hps/infrastructure/hps_check_exception.rb +13 -13
  48. data/lib/hps/infrastructure/hps_check_type.rb +11 -11
  49. data/lib/hps/infrastructure/hps_data_entry_mode.rb +11 -11
  50. data/lib/hps/infrastructure/hps_exception.rb +25 -25
  51. data/lib/hps/infrastructure/hps_exception_mapper.rb +145 -145
  52. data/lib/hps/infrastructure/hps_gateway_response_validation.rb +20 -20
  53. data/lib/hps/infrastructure/hps_input_validation.rb +13 -13
  54. data/lib/hps/infrastructure/hps_sdk_codes.rb +48 -48
  55. data/lib/hps/infrastructure/hps_sec_code.rb +27 -27
  56. data/lib/hps/infrastructure/hps_track_data_method.rb +6 -6
  57. data/lib/hps/infrastructure/invalid_request_exception.rb +15 -15
  58. data/lib/hps/services/hps_batch_service.rb +29 -29
  59. data/lib/hps/services/hps_charge_service.rb +773 -773
  60. data/lib/hps/services/hps_check_service.rb +110 -110
  61. data/lib/hps/services/hps_gift_card_service.rb +301 -301
  62. data/lib/hps/services/hps_service.rb +140 -136
  63. data/lib/hps/version.rb +3 -3
  64. data/lib/hps.rb +63 -63
  65. data/tests/amex_tests.rb +292 -292
  66. data/tests/cert_tests.rb +80 -80
  67. data/tests/certification/card_present_spec.rb +320 -320
  68. data/tests/certification/gift_card_certification_test.rb +106 -106
  69. data/tests/certification/gift_card_certification_tests.rb +107 -107
  70. data/tests/check_tests.rb +50 -50
  71. data/tests/discover_tests.rb +386 -386
  72. data/tests/exception_mapper_tests.rb +311 -311
  73. data/tests/general_tests.rb +140 -140
  74. data/tests/giftcard_tests.rb +212 -212
  75. data/tests/hps_token_service.rb +56 -56
  76. data/tests/mastercard_tests.rb +387 -387
  77. data/tests/secret_key.rb +11 -11
  78. data/tests/test_check.rb +77 -77
  79. data/tests/test_data.rb +138 -138
  80. data/tests/test_helper.rb +179 -179
  81. data/tests/token_tests.rb +512 -512
  82. data/tests/visa_tests.rb +445 -445
  83. metadata +31 -13
@@ -1,136 +1,140 @@
1
- require 'active_support/core_ext/hash/conversions'
2
-
3
- module Hps
4
- class HpsService
5
-
6
- attr_accessor :exception_mapper
7
-
8
- attr_accessor *Configuration::VALID_CONFIG_KEYS
9
-
10
- def initialize(options={})
11
-
12
- merged_options = Hps.options.merge(options)
13
-
14
- Configuration::VALID_CONFIG_KEYS.each do |key|
15
- send("#{key}=", merged_options[key])
16
- end
17
-
18
- @exception_mapper = Hps::ExceptionMapper.new
19
- end
20
-
21
- #protected
22
-
23
- def doTransaction(transaction, client_txn_id = nil)
24
-
25
- if configuration_invalid
26
- raise @exception_mapper.map_sdk_exception(SdkCodes.invalid_transaction_id)
27
- end
28
-
29
- xml = Builder::XmlMarkup.new
30
- xml.instruct!(:xml, :encoding => "UTF-8")
31
- xml.SOAP :Envelope, {
32
- 'xmlns:SOAP' => 'http://schemas.xmlsoap.org/soap/envelope/',
33
- 'xmlns:hps' => 'http://Hps.Exchange.PosGateway' } do
34
- xml.SOAP :Body do
35
- xml.hps :PosRequest do
36
- xml.hps 'Ver1.0'.to_sym do
37
- xml.hps :Header do
38
- if self.secret_api_key
39
- self.service_uri = gateway_url_for_key self.secret_api_key
40
- xml.hps :SecretAPIKey, self.secret_api_key.strip
41
- else
42
- xml.hps :UserName, self.user_name
43
- xml.hps :Password, self.password
44
- xml.hps :DeviceId, self.device_id
45
- xml.hps :LicenseId, self.license_id
46
- xml.hps :SiteId, self.site_id
47
- end
48
- xml.hps :DeveloperID, self.developer_id if self.developer_id
49
- xml.hps :VersionNbr, self.version_number if self.version_number
50
- xml.hps :SiteTrace, self.site_trace if self.site_trace
51
- xml.hps :ClientTxnId, client_txn_id if client_txn_id
52
- end
53
-
54
- xml << transaction
55
-
56
- end
57
- end
58
- end
59
- end
60
-
61
- begin
62
-
63
- uri = URI.parse(self.service_uri)
64
- http = Net::HTTP.new uri.host, uri.port
65
- http.use_ssl = true
66
-
67
- # allow SSL verification as opt-in
68
- if self.http_options && self.http_options.verify_mode
69
- http.verify_mode = self.http_options.verify_mode
70
- http.ca_file = self.http_options.ca_file if self.http_options.ca_file
71
- else
72
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
73
- end
74
-
75
- data = xml.target!
76
-
77
- response = http.post(uri.path, data, 'Content-type' => 'text/xml')
78
- # NOTE: If the HTTP request was successful
79
- if response.is_a? Net::HTTPOK
80
-
81
- # NOTE: Convert XML to a Hash
82
- soap_hash = Hash.from_xml(response.body)
83
- # NOTE: Peel away the layers and return only the PosRespose
84
- soap_hash["Envelope"]["Body"]["PosResponse"]["Ver1.0"]
85
-
86
- else
87
- raise @exception_mapper.map_sdk_exception(SdkCodes.unable_to_process_transaction)
88
- end
89
-
90
- rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
91
- Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
92
- raise @exception_mapper.map_sdk_exception(SdkCodes.unable_to_process_transaction, e)
93
- end
94
-
95
- end
96
-
97
- def gateway_url_for_key(api_key)
98
-
99
- gateway_url = "https://api2.heartlandportico.com/Hps.Exchange.PosGateway/PosGatewayService.asmx?wsdl"
100
-
101
- if api_key.include? "_uat_"
102
-
103
- gateway_url = "https://posgateway.uat.secureexchange.net/Hps.Exchange.PosGateway/PosGatewayService.asmx?wsdl"
104
-
105
- elsif api_key.include? "_cert_"
106
-
107
- gateway_url = "https://cert.api2.heartlandportico.com/Hps.Exchange.PosGateway/PosGatewayService.asmx?wsdl"
108
- end
109
-
110
- gateway_url
111
- end
112
-
113
- def hydrate_transaction_header(header)
114
- result = HpsTransactionHeader.new
115
- result.gateway_response_code = header["GatewayRspCode"]
116
- result.gateway_response_message = header["GatewayRspMsg"]
117
- result.response_dt = header["RspDT"]
118
- result.client_txn_id = header["GatewayTxnId"]
119
- result
120
- end
121
-
122
- private
123
-
124
- def configuration_invalid
125
- self.secret_api_key.nil? and (
126
- self.service_uri.nil? or
127
- self.user_name.nil? or
128
- self.password.nil? or
129
- self.license_id.nil? or
130
- self.device_id.nil? or
131
- self.site_id.nil?
132
- )
133
- end
134
-
135
- end
136
- end
1
+ require "time"
2
+ require "active_support"
3
+ require "active_support/core_ext/hash/conversions"
4
+ require "active_support/core_ext/date_time/calculations"
5
+
6
+ module Hps
7
+ class HpsService
8
+
9
+ attr_accessor :exception_mapper
10
+
11
+ attr_accessor *Configuration::VALID_CONFIG_KEYS
12
+
13
+ def initialize(options={})
14
+
15
+ merged_options = Hps.options.merge(options)
16
+
17
+ Configuration::VALID_CONFIG_KEYS.each do |key|
18
+ send("#{key}=", merged_options[key])
19
+ end
20
+
21
+ @exception_mapper = Hps::ExceptionMapper.new
22
+ end
23
+
24
+ #protected
25
+
26
+ def doTransaction(transaction, client_txn_id = nil)
27
+
28
+ if configuration_invalid
29
+ raise @exception_mapper.map_sdk_exception(SdkCodes.invalid_transaction_id)
30
+ end
31
+
32
+ xml = Builder::XmlMarkup.new
33
+ xml.instruct!(:xml, :encoding => "UTF-8")
34
+ xml.SOAP :Envelope, {
35
+ 'xmlns:SOAP' => 'http://schemas.xmlsoap.org/soap/envelope/',
36
+ 'xmlns:hps' => 'http://Hps.Exchange.PosGateway' } do
37
+ xml.SOAP :Body do
38
+ xml.hps :PosRequest do
39
+ xml.hps 'Ver1.0'.to_sym do
40
+ xml.hps :Header do
41
+ if self.secret_api_key
42
+ self.service_uri = gateway_url_for_key self.secret_api_key
43
+ xml.hps :SecretAPIKey, self.secret_api_key.strip
44
+ else
45
+ xml.hps :UserName, self.user_name
46
+ xml.hps :Password, self.password
47
+ xml.hps :DeviceId, self.device_id
48
+ xml.hps :LicenseId, self.license_id
49
+ xml.hps :SiteId, self.site_id
50
+ end
51
+ xml.hps :DeveloperID, self.developer_id if self.developer_id
52
+ xml.hps :VersionNbr, self.version_number if self.version_number
53
+ xml.hps :SiteTrace, self.site_trace if self.site_trace
54
+ xml.hps :ClientTxnId, client_txn_id if client_txn_id
55
+ xml.hps :SDKNameVersion, "ruby;version=#{Hps::VERSION}"
56
+ end
57
+
58
+ xml << transaction
59
+
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ begin
66
+
67
+ uri = URI.parse(self.service_uri)
68
+ http = Net::HTTP.new uri.host, uri.port
69
+ http.use_ssl = true
70
+
71
+ # allow SSL verification as opt-in
72
+ if self.http_options && self.http_options.verify_mode
73
+ http.verify_mode = self.http_options.verify_mode
74
+ http.ca_file = self.http_options.ca_file if self.http_options.ca_file
75
+ else
76
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
77
+ end
78
+
79
+ data = xml.target!
80
+
81
+ response = http.post(uri.path, data, 'Content-type' => 'text/xml')
82
+ # NOTE: If the HTTP request was successful
83
+ if response.is_a? Net::HTTPOK
84
+
85
+ # NOTE: Convert XML to a Hash
86
+ soap_hash = Hash.from_xml(response.body)
87
+ # NOTE: Peel away the layers and return only the PosRespose
88
+ soap_hash["Envelope"]["Body"]["PosResponse"]["Ver1.0"]
89
+
90
+ else
91
+ raise @exception_mapper.map_sdk_exception(SdkCodes.unable_to_process_transaction)
92
+ end
93
+
94
+ rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
95
+ Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
96
+ raise @exception_mapper.map_sdk_exception(SdkCodes.unable_to_process_transaction, e)
97
+ end
98
+
99
+ end
100
+
101
+ def gateway_url_for_key(api_key)
102
+
103
+ gateway_url = "https://api2.heartlandportico.com/Hps.Exchange.PosGateway/PosGatewayService.asmx?wsdl"
104
+
105
+ if api_key.include? "_uat_"
106
+
107
+ gateway_url = "https://posgateway.uat.secureexchange.net/Hps.Exchange.PosGateway/PosGatewayService.asmx?wsdl"
108
+
109
+ elsif api_key.include? "_cert_"
110
+
111
+ gateway_url = "https://cert.api2.heartlandportico.com/Hps.Exchange.PosGateway/PosGatewayService.asmx?wsdl"
112
+ end
113
+
114
+ gateway_url
115
+ end
116
+
117
+ def hydrate_transaction_header(header)
118
+ result = HpsTransactionHeader.new
119
+ result.gateway_response_code = header["GatewayRspCode"]
120
+ result.gateway_response_message = header["GatewayRspMsg"]
121
+ result.response_dt = header["RspDT"]
122
+ result.client_txn_id = header["GatewayTxnId"]
123
+ result
124
+ end
125
+
126
+ private
127
+
128
+ def configuration_invalid
129
+ self.secret_api_key.nil? and (
130
+ self.service_uri.nil? or
131
+ self.user_name.nil? or
132
+ self.password.nil? or
133
+ self.license_id.nil? or
134
+ self.device_id.nil? or
135
+ self.site_id.nil?
136
+ )
137
+ end
138
+
139
+ end
140
+ end
data/lib/hps/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module Hps
2
- VERSION = "2.3.2"
3
- end
1
+ module Hps
2
+ VERSION = "2.5.0"
3
+ end
data/lib/hps.rb CHANGED
@@ -1,63 +1,63 @@
1
- require 'builder'
2
- require 'net/http'
3
- require 'net/https'
4
- require "hps/version"
5
- require "hps/configuration"
6
-
7
- # Entities
8
- require "hps/entities/hps_transaction"
9
- require "hps/entities/hps_authorization"
10
- require "hps/entities/hps_account_verify"
11
- require "hps/entities/hps_address"
12
- require "hps/entities/hps_batch"
13
- require "hps/entities/hps_cardholder"
14
- require "hps/entities/hps_charge"
15
- require "hps/entities/hps_charge_exceptions"
16
- require "hps/entities/hps_credit_card"
17
- require "hps/entities/hps_encryption_data"
18
- require "hps/entities/hps_refund"
19
- require "hps/entities/hps_report_transaction_details"
20
- require "hps/entities/hps_report_transaction_summary"
21
- require "hps/entities/hps_reversal"
22
- require "hps/entities/hps_token_data"
23
- require "hps/entities/hps_track_data"
24
- require "hps/entities/hps_transaction_header"
25
- require "hps/entities/hps_transaction_type"
26
- require "hps/entities/hps_transaction_details"
27
- require "hps/entities/hps_void"
28
- require "hps/entities/hps_check"
29
- require "hps/entities/hps_check_holder"
30
- require "hps/entities/hps_check_response"
31
- require "hps/entities/hps_check_response_details"
32
- require "hps/entities/hps_manage_tokens"
33
- require "hps/entities/hps_gift_card"
34
-
35
- # Infrastructure
36
- require "hps/infrastructure/hps_sdk_codes"
37
- require "hps/infrastructure/hps_exception"
38
- require "hps/infrastructure/api_connection_exception"
39
- require "hps/infrastructure/authentication_exception"
40
- require "hps/infrastructure/card_exception"
41
- require "hps/infrastructure/invalid_request_exception"
42
- require "hps/infrastructure/hps_exception_mapper"
43
- require "hps/infrastructure/hps_track_data_method"
44
- require "hps/infrastructure/hps_account_type"
45
- require "hps/infrastructure/hps_check_type"
46
- require "hps/infrastructure/hps_data_entry_mode"
47
- require "hps/infrastructure/hps_sec_code"
48
- require "hps/infrastructure/hps_input_validation"
49
- require "hps/infrastructure/hps_gateway_response_validation"
50
- require "hps/infrastructure/hps_check_exception"
51
-
52
- # Services
53
- require "hps/services/hps_service"
54
- require "hps/services/hps_charge_service"
55
- require "hps/services/hps_check_service"
56
- require "hps/services/hps_batch_service"
57
- require "hps/services/hps_gift_card_service"
58
-
59
- module Hps
60
-
61
- extend Configuration
62
-
63
- end
1
+ require 'builder'
2
+ require 'net/http'
3
+ require 'net/https'
4
+ require "hps/version"
5
+ require "hps/configuration"
6
+
7
+ # Entities
8
+ require "hps/entities/hps_transaction"
9
+ require "hps/entities/hps_authorization"
10
+ require "hps/entities/hps_account_verify"
11
+ require "hps/entities/hps_address"
12
+ require "hps/entities/hps_batch"
13
+ require "hps/entities/hps_cardholder"
14
+ require "hps/entities/hps_charge"
15
+ require "hps/entities/hps_charge_exceptions"
16
+ require "hps/entities/hps_credit_card"
17
+ require "hps/entities/hps_encryption_data"
18
+ require "hps/entities/hps_refund"
19
+ require "hps/entities/hps_report_transaction_details"
20
+ require "hps/entities/hps_report_transaction_summary"
21
+ require "hps/entities/hps_reversal"
22
+ require "hps/entities/hps_token_data"
23
+ require "hps/entities/hps_track_data"
24
+ require "hps/entities/hps_transaction_header"
25
+ require "hps/entities/hps_transaction_type"
26
+ require "hps/entities/hps_transaction_details"
27
+ require "hps/entities/hps_void"
28
+ require "hps/entities/hps_check"
29
+ require "hps/entities/hps_check_holder"
30
+ require "hps/entities/hps_check_response"
31
+ require "hps/entities/hps_check_response_details"
32
+ require "hps/entities/hps_manage_tokens"
33
+ require "hps/entities/hps_gift_card"
34
+
35
+ # Infrastructure
36
+ require "hps/infrastructure/hps_sdk_codes"
37
+ require "hps/infrastructure/hps_exception"
38
+ require "hps/infrastructure/api_connection_exception"
39
+ require "hps/infrastructure/authentication_exception"
40
+ require "hps/infrastructure/card_exception"
41
+ require "hps/infrastructure/invalid_request_exception"
42
+ require "hps/infrastructure/hps_exception_mapper"
43
+ require "hps/infrastructure/hps_track_data_method"
44
+ require "hps/infrastructure/hps_account_type"
45
+ require "hps/infrastructure/hps_check_type"
46
+ require "hps/infrastructure/hps_data_entry_mode"
47
+ require "hps/infrastructure/hps_sec_code"
48
+ require "hps/infrastructure/hps_input_validation"
49
+ require "hps/infrastructure/hps_gateway_response_validation"
50
+ require "hps/infrastructure/hps_check_exception"
51
+
52
+ # Services
53
+ require "hps/services/hps_service"
54
+ require "hps/services/hps_charge_service"
55
+ require "hps/services/hps_check_service"
56
+ require "hps/services/hps_batch_service"
57
+ require "hps/services/hps_gift_card_service"
58
+
59
+ module Hps
60
+
61
+ extend Configuration
62
+
63
+ end