hps 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +8 -8
- data/LICENSE.txt +32 -32
- data/PRIVACY.txt +65 -65
- data/README.md +40 -40
- data/Rakefile +15 -15
- data/hps.gemspec +26 -26
- data/lib/hps/configuration.rb +16 -16
- data/lib/hps/entities/hps_account_verify.rb +8 -8
- data/lib/hps/entities/hps_address.rb +6 -6
- data/lib/hps/entities/hps_authorization.rb +12 -12
- data/lib/hps/entities/hps_batch.rb +6 -6
- data/lib/hps/entities/hps_cardholder.rb +10 -6
- data/lib/hps/entities/hps_charge.rb +8 -8
- data/lib/hps/entities/hps_charge_exceptions.rb +6 -6
- data/lib/hps/entities/hps_credit_card.rb +32 -32
- data/lib/hps/entities/hps_refund.rb +8 -8
- data/lib/hps/entities/hps_report_transaction_details.rb +10 -10
- data/lib/hps/entities/hps_report_transaction_summary.rb +6 -6
- data/lib/hps/entities/hps_reversal.rb +10 -10
- data/lib/hps/entities/hps_token_data.rb +10 -10
- data/lib/hps/entities/hps_transaction.rb +161 -161
- data/lib/hps/entities/hps_transaction_details.rb +6 -6
- data/lib/hps/entities/hps_transaction_header.rb +8 -8
- data/lib/hps/entities/hps_transaction_type.rb +16 -16
- data/lib/hps/entities/hps_void.rb +8 -8
- data/lib/hps/infrastructure/api_connection_exception.rb +11 -11
- data/lib/hps/infrastructure/authentication_exception.rb +11 -11
- data/lib/hps/infrastructure/card_exception.rb +15 -15
- data/lib/hps/infrastructure/exceptions.json +468 -468
- data/lib/hps/infrastructure/hps_exception.rb +25 -25
- data/lib/hps/infrastructure/hps_exception_mapper.rb +134 -134
- data/lib/hps/infrastructure/hps_sdk_codes.rb +48 -48
- data/lib/hps/infrastructure/invalid_request_exception.rb +15 -15
- data/lib/hps/services/hps_batch_service.rb +29 -29
- data/lib/hps/services/hps_charge_service.rb +634 -634
- data/lib/hps/services/hps_service.rb +128 -128
- data/lib/hps/version.rb +3 -3
- data/lib/hps.rb +45 -45
- data/tests/amex_tests.rb +230 -230
- data/tests/cert_tests.rb +80 -80
- data/tests/discover_tests.rb +324 -324
- data/tests/exception_mapper_tests.rb +244 -244
- data/tests/general_tests.rb +58 -58
- data/tests/hps_token_service.rb +56 -56
- data/tests/mastercard_tests.rb +325 -325
- data/tests/secret_key.rb +11 -11
- data/tests/test_data.rb +127 -127
- data/tests/test_helper.rb +108 -92
- data/tests/token_tests.rb +513 -513
- data/tests/visa_tests.rb +378 -378
- metadata +4 -6
- data/.DS_Store +0 -0
- data/.gitignore +0 -24
@@ -1,25 +1,25 @@
|
|
1
|
-
module Hps
|
2
|
-
class HpsException < StandardError
|
3
|
-
|
4
|
-
attr_accessor :code, :inner_exception, :response_code, :response_text
|
5
|
-
|
6
|
-
|
7
|
-
def initialize(message, code, inner_exception = nil)
|
8
|
-
|
9
|
-
@code=code
|
10
|
-
@inner_exception = inner_exception
|
11
|
-
super(message)
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
def code
|
16
|
-
if @code.nil?
|
17
|
-
"unknown"
|
18
|
-
else
|
19
|
-
@code
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
1
|
+
module Hps
|
2
|
+
class HpsException < StandardError
|
3
|
+
|
4
|
+
attr_accessor :code, :inner_exception, :response_code, :response_text
|
5
|
+
|
6
|
+
|
7
|
+
def initialize(message, code, inner_exception = nil)
|
8
|
+
|
9
|
+
@code=code
|
10
|
+
@inner_exception = inner_exception
|
11
|
+
super(message)
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def code
|
16
|
+
if @code.nil?
|
17
|
+
"unknown"
|
18
|
+
else
|
19
|
+
@code
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -1,135 +1,135 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
module Hps
|
4
|
-
class ExceptionMapper
|
5
|
-
|
6
|
-
attr_reader :exceptions
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
path = File.join( File.dirname(__FILE__), "exceptions.json")
|
10
|
-
|
11
|
-
File.open(path, "r") do |f|
|
12
|
-
@exceptions = JSON.load(f)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def version_number
|
17
|
-
@exceptions["version"]
|
18
|
-
end
|
19
|
-
|
20
|
-
def map_issuer_exception(transaction_id, response_code, response_text)
|
21
|
-
|
22
|
-
mapping = exception_for_category_and_code("issuer", response_code)
|
23
|
-
|
24
|
-
unless mapping.nil?
|
25
|
-
message = message_for_mapping(mapping, response_text)
|
26
|
-
code = mapping["mapping_code"]
|
27
|
-
return CardException.new(transaction_id, code, message)
|
28
|
-
else
|
29
|
-
return CardException.new(transaction_id, "unknown_card_exception", response_text)
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
def map_gateway_exception(transaction_id, response_code, response_text)
|
35
|
-
|
36
|
-
mapping = exception_for_category_and_code("gateway", response_code)
|
37
|
-
message = message_for_mapping(mapping, response_text)
|
38
|
-
|
39
|
-
unless mapping.nil?
|
40
|
-
|
41
|
-
code = mapping["mapping_code"]
|
42
|
-
exception_type = mapping["mapping_type"]
|
43
|
-
|
44
|
-
if exception_type == "AuthenticationException"
|
45
|
-
|
46
|
-
return AuthenticationException.new(message)
|
47
|
-
|
48
|
-
elsif exception_type == "CardException"
|
49
|
-
|
50
|
-
return CardException.new(transaction_id, code, message)
|
51
|
-
|
52
|
-
elsif exception_type == "InvalidRequestException"
|
53
|
-
|
54
|
-
return InvalidRequestException.new(message, mapping["param"], code)
|
55
|
-
|
56
|
-
elsif !code.nil?
|
57
|
-
|
58
|
-
return HpsException.new(response_text, code)
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
HpsException.new(message, "unknown")
|
65
|
-
end
|
66
|
-
|
67
|
-
def map_sdk_exception(error_code, inner_exception = nil)
|
68
|
-
|
69
|
-
mapping = exception_for_category_and_code("sdk", error_code)
|
70
|
-
sdk_code_name = SdkCodes.instance_methods.detect { |m| SdkCodes.send(m) == error_code }
|
71
|
-
|
72
|
-
if sdk_code_name.nil?
|
73
|
-
response_text = "unknown"
|
74
|
-
else
|
75
|
-
response_text = sdk_code_name
|
76
|
-
end
|
77
|
-
|
78
|
-
unless mapping.nil?
|
79
|
-
|
80
|
-
message = message_for_mapping(mapping, response_text)
|
81
|
-
code = mapping["mapping_code"]
|
82
|
-
exception_type = mapping["mapping_type"]
|
83
|
-
|
84
|
-
if exception_type == "InvalidRequestException"
|
85
|
-
|
86
|
-
return InvalidRequestException.new(message, mapping["param"], code)
|
87
|
-
|
88
|
-
elsif exception_type == "ApiConnectionException"
|
89
|
-
|
90
|
-
return ApiConnectionException.new(message, inner_exception, code)
|
91
|
-
|
92
|
-
elsif !code.nil?
|
93
|
-
|
94
|
-
return HpsException.new(message, code)
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
HpsException.new("unknown", "unknown", inner_exception)
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
private
|
105
|
-
|
106
|
-
def message_for_mapping(mapping, original_message)
|
107
|
-
|
108
|
-
return original_message if mapping.nil?
|
109
|
-
|
110
|
-
message = mapping["mapping_message"]
|
111
|
-
|
112
|
-
unless message.nil?
|
113
|
-
|
114
|
-
mapping_message = @exceptions["exception_messages"].detect { |m|
|
115
|
-
m["code"] == message
|
116
|
-
}
|
117
|
-
|
118
|
-
return mapping_message["message"] unless mapping_message["message"].nil?
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
original_message
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
def exception_for_category_and_code(category, code)
|
127
|
-
|
128
|
-
@exceptions["exception_mappings"].detect { |m|
|
129
|
-
m["category"] == category and m["exception_codes"].include?(code.to_s)
|
130
|
-
}
|
131
|
-
|
132
|
-
end
|
133
|
-
|
134
|
-
end
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Hps
|
4
|
+
class ExceptionMapper
|
5
|
+
|
6
|
+
attr_reader :exceptions
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
path = File.join( File.dirname(__FILE__), "exceptions.json")
|
10
|
+
|
11
|
+
File.open(path, "r") do |f|
|
12
|
+
@exceptions = JSON.load(f)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def version_number
|
17
|
+
@exceptions["version"]
|
18
|
+
end
|
19
|
+
|
20
|
+
def map_issuer_exception(transaction_id, response_code, response_text)
|
21
|
+
|
22
|
+
mapping = exception_for_category_and_code("issuer", response_code)
|
23
|
+
|
24
|
+
unless mapping.nil?
|
25
|
+
message = message_for_mapping(mapping, response_text)
|
26
|
+
code = mapping["mapping_code"]
|
27
|
+
return CardException.new(transaction_id, code, message)
|
28
|
+
else
|
29
|
+
return CardException.new(transaction_id, "unknown_card_exception", response_text)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def map_gateway_exception(transaction_id, response_code, response_text)
|
35
|
+
|
36
|
+
mapping = exception_for_category_and_code("gateway", response_code)
|
37
|
+
message = message_for_mapping(mapping, response_text)
|
38
|
+
|
39
|
+
unless mapping.nil?
|
40
|
+
|
41
|
+
code = mapping["mapping_code"]
|
42
|
+
exception_type = mapping["mapping_type"]
|
43
|
+
|
44
|
+
if exception_type == "AuthenticationException"
|
45
|
+
|
46
|
+
return AuthenticationException.new(message)
|
47
|
+
|
48
|
+
elsif exception_type == "CardException"
|
49
|
+
|
50
|
+
return CardException.new(transaction_id, code, message)
|
51
|
+
|
52
|
+
elsif exception_type == "InvalidRequestException"
|
53
|
+
|
54
|
+
return InvalidRequestException.new(message, mapping["param"], code)
|
55
|
+
|
56
|
+
elsif !code.nil?
|
57
|
+
|
58
|
+
return HpsException.new(response_text, code)
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
HpsException.new(message, "unknown")
|
65
|
+
end
|
66
|
+
|
67
|
+
def map_sdk_exception(error_code, inner_exception = nil)
|
68
|
+
|
69
|
+
mapping = exception_for_category_and_code("sdk", error_code)
|
70
|
+
sdk_code_name = SdkCodes.instance_methods.detect { |m| SdkCodes.send(m) == error_code }
|
71
|
+
|
72
|
+
if sdk_code_name.nil?
|
73
|
+
response_text = "unknown"
|
74
|
+
else
|
75
|
+
response_text = sdk_code_name
|
76
|
+
end
|
77
|
+
|
78
|
+
unless mapping.nil?
|
79
|
+
|
80
|
+
message = message_for_mapping(mapping, response_text)
|
81
|
+
code = mapping["mapping_code"]
|
82
|
+
exception_type = mapping["mapping_type"]
|
83
|
+
|
84
|
+
if exception_type == "InvalidRequestException"
|
85
|
+
|
86
|
+
return InvalidRequestException.new(message, mapping["param"], code)
|
87
|
+
|
88
|
+
elsif exception_type == "ApiConnectionException"
|
89
|
+
|
90
|
+
return ApiConnectionException.new(message, inner_exception, code)
|
91
|
+
|
92
|
+
elsif !code.nil?
|
93
|
+
|
94
|
+
return HpsException.new(message, code)
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
HpsException.new("unknown", "unknown", inner_exception)
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def message_for_mapping(mapping, original_message)
|
107
|
+
|
108
|
+
return original_message if mapping.nil?
|
109
|
+
|
110
|
+
message = mapping["mapping_message"]
|
111
|
+
|
112
|
+
unless message.nil?
|
113
|
+
|
114
|
+
mapping_message = @exceptions["exception_messages"].detect { |m|
|
115
|
+
m["code"] == message
|
116
|
+
}
|
117
|
+
|
118
|
+
return mapping_message["message"] unless mapping_message["message"].nil?
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
original_message
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
def exception_for_category_and_code(category, code)
|
127
|
+
|
128
|
+
@exceptions["exception_mappings"].detect { |m|
|
129
|
+
m["category"] == category and m["exception_codes"].include?(code.to_s)
|
130
|
+
}
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
135
|
end
|
@@ -1,49 +1,49 @@
|
|
1
|
-
module Hps
|
2
|
-
module SdkCodes
|
3
|
-
|
4
|
-
def self.invalid_transaction_id
|
5
|
-
"0"
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.invalid_gateway_url
|
9
|
-
"1"
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.unable_to_process_transaction
|
13
|
-
"2"
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.invalid_start_date
|
17
|
-
"3"
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.invalid_end_date
|
21
|
-
"4"
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.missing_currency
|
25
|
-
"5"
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.invalid_currency
|
29
|
-
"6"
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.invalid_amount
|
33
|
-
"7"
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.reversal_error_after_gateway_timeout
|
37
|
-
"8"
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.reversal_error_after_issuer_timeout
|
41
|
-
"9"
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.processing_error
|
45
|
-
"10"
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
1
|
+
module Hps
|
2
|
+
module SdkCodes
|
3
|
+
|
4
|
+
def self.invalid_transaction_id
|
5
|
+
"0"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.invalid_gateway_url
|
9
|
+
"1"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.unable_to_process_transaction
|
13
|
+
"2"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.invalid_start_date
|
17
|
+
"3"
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.invalid_end_date
|
21
|
+
"4"
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.missing_currency
|
25
|
+
"5"
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.invalid_currency
|
29
|
+
"6"
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.invalid_amount
|
33
|
+
"7"
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.reversal_error_after_gateway_timeout
|
37
|
+
"8"
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.reversal_error_after_issuer_timeout
|
41
|
+
"9"
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.processing_error
|
45
|
+
"10"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
49
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
module Hps
|
2
|
-
class InvalidRequestException < HpsException
|
3
|
-
|
4
|
-
attr_accessor :param
|
5
|
-
|
6
|
-
def initialize(message, param = nil, code = nil)
|
7
|
-
|
8
|
-
@param = param
|
9
|
-
|
10
|
-
super(message, code)
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
1
|
+
module Hps
|
2
|
+
class InvalidRequestException < HpsException
|
3
|
+
|
4
|
+
attr_accessor :param
|
5
|
+
|
6
|
+
def initialize(message, param = nil, code = nil)
|
7
|
+
|
8
|
+
@param = param
|
9
|
+
|
10
|
+
super(message, code)
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -1,30 +1,30 @@
|
|
1
|
-
module Hps
|
2
|
-
class HpsBatchService < HpsService
|
3
|
-
|
4
|
-
def close_batch()
|
5
|
-
|
6
|
-
xml = Builder::XmlMarkup.new
|
7
|
-
|
8
|
-
xml.hps :Transaction do
|
9
|
-
xml.hps :BatchClose, "BatchClose"
|
10
|
-
end
|
11
|
-
|
12
|
-
response = doTransaction(xml.target!)
|
13
|
-
header = response["Header"]
|
14
|
-
|
15
|
-
unless header["GatewayRspCode"].eql? "0"
|
16
|
-
raise @exception_mapper.map_gateway_exception(header["GatewayTxnId"], header["GatewayRspCode"], header["GatewayRspMsg"])
|
17
|
-
end
|
18
|
-
|
19
|
-
batch_close = response["Transaction"]["BatchClose"]
|
20
|
-
result = HpsBatch.new()
|
21
|
-
result.id = batch_close["BatchId"]
|
22
|
-
result.sequence_number = batch_close["BatchSeqNbr"]
|
23
|
-
result.total_amount = batch_close["TotalAmt"]
|
24
|
-
result.transaction_count = batch_close["TxnCnt"]
|
25
|
-
|
26
|
-
result
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
1
|
+
module Hps
|
2
|
+
class HpsBatchService < HpsService
|
3
|
+
|
4
|
+
def close_batch()
|
5
|
+
|
6
|
+
xml = Builder::XmlMarkup.new
|
7
|
+
|
8
|
+
xml.hps :Transaction do
|
9
|
+
xml.hps :BatchClose, "BatchClose"
|
10
|
+
end
|
11
|
+
|
12
|
+
response = doTransaction(xml.target!)
|
13
|
+
header = response["Header"]
|
14
|
+
|
15
|
+
unless header["GatewayRspCode"].eql? "0"
|
16
|
+
raise @exception_mapper.map_gateway_exception(header["GatewayTxnId"], header["GatewayRspCode"], header["GatewayRspMsg"])
|
17
|
+
end
|
18
|
+
|
19
|
+
batch_close = response["Transaction"]["BatchClose"]
|
20
|
+
result = HpsBatch.new()
|
21
|
+
result.id = batch_close["BatchId"]
|
22
|
+
result.sequence_number = batch_close["BatchSeqNbr"]
|
23
|
+
result.total_amount = batch_close["TotalAmt"]
|
24
|
+
result.transaction_count = batch_close["TxnCnt"]
|
25
|
+
|
26
|
+
result
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
30
|
end
|