hps 2.3.2 → 2.4.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.
- checksums.yaml +4 -4
- data/Gemfile +4 -4
- data/Gemfile.lock +59 -0
- data/LICENSE.md +264 -264
- data/PRIVACY.txt +65 -65
- data/README.md +213 -213
- data/Rakefile +15 -15
- data/examples/sinatra-verify-only/Gemfile +4 -4
- data/examples/sinatra-verify-only/app.rb +32 -32
- data/examples/sinatra-verify-only/views/index.erb +478 -478
- data/examples/sinatra-verify-only/views/result.erb +39 -39
- data/hps.gemspec +28 -27
- data/lib/hps/configuration.rb +17 -17
- 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 +6 -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_check.rb +18 -18
- data/lib/hps/entities/hps_check_holder.rb +10 -10
- data/lib/hps/entities/hps_check_response.rb +45 -45
- data/lib/hps/entities/hps_check_response_details.rb +9 -9
- data/lib/hps/entities/hps_credit_card.rb +34 -34
- data/lib/hps/entities/hps_direct_market_data.rb +5 -5
- data/lib/hps/entities/hps_encryption_data.rb +6 -6
- data/lib/hps/entities/hps_gift_card.rb +133 -133
- data/lib/hps/entities/hps_manage_tokens.rb +8 -8
- 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_track_data.rb +5 -5
- 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 +547 -547
- data/lib/hps/infrastructure/hps_account_type.rb +11 -11
- data/lib/hps/infrastructure/hps_check_exception.rb +13 -13
- data/lib/hps/infrastructure/hps_check_type.rb +11 -11
- data/lib/hps/infrastructure/hps_data_entry_mode.rb +11 -11
- data/lib/hps/infrastructure/hps_exception.rb +25 -25
- data/lib/hps/infrastructure/hps_exception_mapper.rb +145 -145
- data/lib/hps/infrastructure/hps_gateway_response_validation.rb +20 -20
- data/lib/hps/infrastructure/hps_input_validation.rb +13 -13
- data/lib/hps/infrastructure/hps_sdk_codes.rb +48 -48
- data/lib/hps/infrastructure/hps_sec_code.rb +27 -27
- data/lib/hps/infrastructure/hps_track_data_method.rb +6 -6
- 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 +773 -773
- data/lib/hps/services/hps_check_service.rb +110 -110
- data/lib/hps/services/hps_gift_card_service.rb +301 -301
- data/lib/hps/services/hps_service.rb +141 -136
- data/lib/hps/version.rb +3 -3
- data/lib/hps.rb +63 -63
- data/tests/amex_tests.rb +292 -292
- data/tests/cert_tests.rb +80 -80
- data/tests/certification/card_present_spec.rb +320 -320
- data/tests/certification/gift_card_certification_test.rb +106 -106
- data/tests/certification/gift_card_certification_tests.rb +107 -107
- data/tests/check_tests.rb +50 -50
- data/tests/discover_tests.rb +386 -386
- data/tests/exception_mapper_tests.rb +311 -311
- data/tests/general_tests.rb +140 -140
- data/tests/giftcard_tests.rb +212 -212
- data/tests/hps_token_service.rb +56 -56
- data/tests/mastercard_tests.rb +387 -387
- data/tests/secret_key.rb +11 -11
- data/tests/test_check.rb +77 -77
- data/tests/test_data.rb +138 -138
- data/tests/test_helper.rb +179 -179
- data/tests/token_tests.rb +512 -512
- data/tests/visa_tests.rb +445 -445
- metadata +31 -11
data/tests/giftcard_tests.rb
CHANGED
@@ -1,212 +1,212 @@
|
|
1
|
-
require File.join( File.dirname(__FILE__), "test_helper" )
|
2
|
-
|
3
|
-
describe "Giftcard Tests" do
|
4
|
-
|
5
|
-
# Activate a card
|
6
|
-
it "When card is ok, it should activate and return valid response" do
|
7
|
-
response = Hps::TestHelper.activate_valid_gift_card(100.00)
|
8
|
-
expect( response.response_code ).to eql("0")
|
9
|
-
expect( response ).to be_a(Hps::HpsGiftCardActivate)
|
10
|
-
end
|
11
|
-
|
12
|
-
# Add value to a card
|
13
|
-
it "When card is ok, it should add value and return a valid response" do
|
14
|
-
response = Hps::TestHelper.add_value_to_valid_gift_card(100.00)
|
15
|
-
expect( response.response_code ).to eql("0")
|
16
|
-
expect( response ).to be_a(Hps::HpsGiftCardAddValue)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Check the balance on a card
|
20
|
-
it "When card is ok, it should return valid response" do
|
21
|
-
response = Hps::TestHelper.balance_valid_gift_card
|
22
|
-
expect( response.response_code ).to eql("0")
|
23
|
-
expect( response ).to be_a(Hps::HpsGiftCardBalance)
|
24
|
-
end
|
25
|
-
|
26
|
-
# Deactivate a card
|
27
|
-
it "When card is ok, it should deactivate and return a valid response" do
|
28
|
-
response = Hps::TestHelper.deactivate_valid_gift_card
|
29
|
-
expect( response.response_code ).to eql("0")
|
30
|
-
expect( response ).to be_a(Hps::HpsGiftCardDeactivate)
|
31
|
-
end
|
32
|
-
|
33
|
-
# Replace a card
|
34
|
-
it "When card is ok, it should replace it and return a valid response" do
|
35
|
-
response = Hps::TestHelper.replace_valid_gift_card
|
36
|
-
expect( response.response_code ).to eql("0")
|
37
|
-
expect( response ).to be_a(Hps::HpsGiftCardReplace)
|
38
|
-
end
|
39
|
-
|
40
|
-
# Add rewards to a card
|
41
|
-
it "When card is ok, it should add rewards and return a valid response" do
|
42
|
-
["USD", "POINTS"].each do |currency|
|
43
|
-
response = Hps::TestHelper.reward_valid_gift_card(10.00, currency)
|
44
|
-
expect( response.response_code ).to eql("0")
|
45
|
-
expect( response ).to be_a(Hps::HpsGiftCardReward)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Complete a sale
|
50
|
-
it "When card is ok, it should complete a sale and return a valid response" do
|
51
|
-
response = Hps::TestHelper.sale_valid_gift_card(10.00)
|
52
|
-
expect( response.response_code ).to eql("0")
|
53
|
-
expect( response ).to be_a(Hps::HpsGiftCardSale)
|
54
|
-
end
|
55
|
-
|
56
|
-
# Void a transaction
|
57
|
-
it "Should void a transaction" do
|
58
|
-
response = Hps::TestHelper.sale_valid_gift_card(10.00)
|
59
|
-
expect( response.response_code ).to eql("0")
|
60
|
-
void_response = Hps::TestHelper.void_gift_card_sale( response.transaction_id )
|
61
|
-
expect( void_response.response_code ).to eql("0")
|
62
|
-
expect( void_response ).to be_a(Hps::HpsGiftCardVoid)
|
63
|
-
end
|
64
|
-
|
65
|
-
# Reverse a transaction using transaction id
|
66
|
-
it "Should reverse a gift card transaction using the transaction id" do
|
67
|
-
response = Hps::TestHelper.sale_valid_gift_card(10.00)
|
68
|
-
expect( response.response_code ).to eql("0")
|
69
|
-
reverse_response = Hps::TestHelper.reverse_gift_card_sale( 10.00, response.transaction_id )
|
70
|
-
expect( reverse_response.response_code ).to eql("0")
|
71
|
-
expect( reverse_response ).to be_a(Hps::HpsGiftCardReversal)
|
72
|
-
end
|
73
|
-
|
74
|
-
# Reverse transaction using giftcard
|
75
|
-
it "Should reverse a giftcard transaction using the card" do
|
76
|
-
response = Hps::TestHelper.sale_valid_gift_card(10.00, "USD", nil, nil, false)
|
77
|
-
expect( response.response_code ).to eql("0")
|
78
|
-
reverse_response = Hps::TestHelper.reverse_gift_card_sale(10.00)
|
79
|
-
expect( reverse_response.response_code ).to eql("0")
|
80
|
-
expect( reverse_response ).to be_a(Hps::HpsGiftCardReversal)
|
81
|
-
end
|
82
|
-
|
83
|
-
context "exceptions for transactions" do
|
84
|
-
before(:all) do
|
85
|
-
@mapper = Hps::ExceptionMapper.new
|
86
|
-
end
|
87
|
-
|
88
|
-
# Amounts less than zero
|
89
|
-
it "raises an exception for amounts less than zero" do
|
90
|
-
%i{activate add_value reward sale reverse}.each do |method|
|
91
|
-
expect{ Hps::TestHelper.gift_card_transaction_exception(-1.00, method) }.to raise_exception{|e|
|
92
|
-
expect(e).to be_a( Hps::InvalidRequestException )
|
93
|
-
expect(e.message).to eql("Amount must be greater than or equal 0.")
|
94
|
-
}
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# Profile auth fails
|
99
|
-
it "should raise an exception if profile auth fails" do
|
100
|
-
expect{ Hps::TestHelper.gift_card_transaction_exception(2.01) }.to raise_exception {|e|
|
101
|
-
expect(e).to be_a(Hps::CardException)
|
102
|
-
expect(e.message).to eql("ProfileError Subject 'ProfileAuthorizationFailed'.")
|
103
|
-
}
|
104
|
-
end
|
105
|
-
|
106
|
-
# Profile closed
|
107
|
-
it "should raise an exception if profile is closed" do
|
108
|
-
expect{ Hps::TestHelper.gift_card_transaction_exception(2.02) }.to raise_exception {|e|
|
109
|
-
expect(e).to be_a(Hps::CardException)
|
110
|
-
expect(e.message).to eql("ProfileError Subject 'ProfileClosed'.")
|
111
|
-
}
|
112
|
-
end
|
113
|
-
|
114
|
-
# Profile not found
|
115
|
-
it "should raise an exception if profile is not found" do
|
116
|
-
expect{ Hps::TestHelper.gift_card_transaction_exception(2.03) }.to raise_exception {|e|
|
117
|
-
expect(e).to be_a(Hps::CardException)
|
118
|
-
expect(e.message).to eql("ProfileError")
|
119
|
-
}
|
120
|
-
end
|
121
|
-
|
122
|
-
# Profile frozen
|
123
|
-
it "should raise an exception if profile is frozen" do
|
124
|
-
expect{ Hps::TestHelper.gift_card_transaction_exception(2.04) }.to raise_exception {|e|
|
125
|
-
expect(e).to be_a(Hps::CardException)
|
126
|
-
expect(e.message).to eql("ProfileError Subject 'ProfileFrozen'.")
|
127
|
-
}
|
128
|
-
end
|
129
|
-
|
130
|
-
# Insufficient funds - card decline - code 5
|
131
|
-
it "should raise an exception if insufficient funds" do
|
132
|
-
expect{ Hps::TestHelper.gift_card_transaction_exception(3.01) }.to raise_exception {|e|
|
133
|
-
expect(e).to be_a(Hps::CardException)
|
134
|
-
expect(e.message).to eql(message_for_code("Exception_Message_CardDeclined"))
|
135
|
-
}
|
136
|
-
end
|
137
|
-
|
138
|
-
# Insufficient activation amount - card decline - code 5
|
139
|
-
it "should raise an exception if insufficient activation amount" do
|
140
|
-
expect{ Hps::TestHelper.gift_card_transaction_exception(3.02) }.to raise_exception {|e|
|
141
|
-
expect(e).to be_a(Hps::CardException)
|
142
|
-
expect(e.message).to eql(message_for_code("Exception_Message_CardDeclined"))
|
143
|
-
}
|
144
|
-
end
|
145
|
-
|
146
|
-
# Insufficient load amount - card decline - code 5
|
147
|
-
it "should raise an exception if insufficient load amount" do
|
148
|
-
expect{ Hps::TestHelper.gift_card_transaction_exception(3.03) }.to raise_exception {|e|
|
149
|
-
expect(e).to be_a(Hps::CardException)
|
150
|
-
expect(e.message).to eql(message_for_code("Exception_Message_CardDeclined"))
|
151
|
-
}
|
152
|
-
end
|
153
|
-
|
154
|
-
# Invalid Payment Type - unknown gift error - code 1
|
155
|
-
it "should raise an exception if insufficient load amount" do
|
156
|
-
expect{ Hps::TestHelper.gift_card_transaction_exception(3.04) }.to raise_exception {|e|
|
157
|
-
expect(e).to be_a(Hps::CardException)
|
158
|
-
expect(e.message).to eql("SystemError Subject 'InvalidPaymentType'.")
|
159
|
-
}
|
160
|
-
end
|
161
|
-
|
162
|
-
# Provide an invalid PIN - code 14
|
163
|
-
it "Should raise an exception if PIN is invalid" do
|
164
|
-
expect{ Hps::TestHelper.gift_card_transaction_exception(3.05) }.to raise_exception {|e|
|
165
|
-
expect(e).to be_a(Hps::CardException)
|
166
|
-
expect(e.message).to eql(message_for_code("Exception_Message_InvalidPin"))
|
167
|
-
}
|
168
|
-
end
|
169
|
-
|
170
|
-
# Invalid seller ID - unknown gift error - code 1
|
171
|
-
it "should raise an exception if invalid seller profile ID" do
|
172
|
-
expect{ Hps::TestHelper.gift_card_transaction_exception(3.06) }.to raise_exception {|e|
|
173
|
-
expect(e).to be_a(Hps::CardException)
|
174
|
-
expect(e.message).to eql("SystemError")
|
175
|
-
}
|
176
|
-
end
|
177
|
-
|
178
|
-
# Order exists - processing error - code 7
|
179
|
-
it "should raise an exception if invalid seller profile ID" do
|
180
|
-
expect{ Hps::TestHelper.gift_card_transaction_exception(3.07) }.to raise_exception {|e|
|
181
|
-
expect(e).to be_a(Hps::CardException)
|
182
|
-
expect(e.message).to eql(message_for_code("Exception_Message_ProcessingError"))
|
183
|
-
}
|
184
|
-
end
|
185
|
-
|
186
|
-
# Registration required - invalid card data - code 3
|
187
|
-
it "should raise an exception if invalid seller profile ID" do
|
188
|
-
expect{ Hps::TestHelper.gift_card_transaction_exception(3.08) }.to raise_exception {|e|
|
189
|
-
expect(e).to be_a(Hps::CardException)
|
190
|
-
expect(e.message).to eql(message_for_code("Exception_Message_InvalidCardData"))
|
191
|
-
}
|
192
|
-
end
|
193
|
-
|
194
|
-
# Account not active - invalid card data - code 8
|
195
|
-
it "should raise an exception if invalid seller profile ID" do
|
196
|
-
expect{ Hps::TestHelper.gift_card_transaction_exception(3.09) }.to raise_exception {|e|
|
197
|
-
expect(e).to be_a(Hps::CardException)
|
198
|
-
expect(e.message).to eql(message_for_code("Exception_Message_InvalidCardData"))
|
199
|
-
}
|
200
|
-
end
|
201
|
-
|
202
|
-
end
|
203
|
-
end # Giftcard Tests
|
204
|
-
|
205
|
-
# Helper methods
|
206
|
-
def message_for_code(code)
|
207
|
-
mapping = @mapper.exceptions["exception_messages"].detect { |message|
|
208
|
-
message["code"] == code
|
209
|
-
}
|
210
|
-
|
211
|
-
mapping["message"] unless mapping.nil?
|
212
|
-
end
|
1
|
+
require File.join( File.dirname(__FILE__), "test_helper" )
|
2
|
+
|
3
|
+
describe "Giftcard Tests" do
|
4
|
+
|
5
|
+
# Activate a card
|
6
|
+
it "When card is ok, it should activate and return valid response" do
|
7
|
+
response = Hps::TestHelper.activate_valid_gift_card(100.00)
|
8
|
+
expect( response.response_code ).to eql("0")
|
9
|
+
expect( response ).to be_a(Hps::HpsGiftCardActivate)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Add value to a card
|
13
|
+
it "When card is ok, it should add value and return a valid response" do
|
14
|
+
response = Hps::TestHelper.add_value_to_valid_gift_card(100.00)
|
15
|
+
expect( response.response_code ).to eql("0")
|
16
|
+
expect( response ).to be_a(Hps::HpsGiftCardAddValue)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Check the balance on a card
|
20
|
+
it "When card is ok, it should return valid response" do
|
21
|
+
response = Hps::TestHelper.balance_valid_gift_card
|
22
|
+
expect( response.response_code ).to eql("0")
|
23
|
+
expect( response ).to be_a(Hps::HpsGiftCardBalance)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Deactivate a card
|
27
|
+
it "When card is ok, it should deactivate and return a valid response" do
|
28
|
+
response = Hps::TestHelper.deactivate_valid_gift_card
|
29
|
+
expect( response.response_code ).to eql("0")
|
30
|
+
expect( response ).to be_a(Hps::HpsGiftCardDeactivate)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Replace a card
|
34
|
+
it "When card is ok, it should replace it and return a valid response" do
|
35
|
+
response = Hps::TestHelper.replace_valid_gift_card
|
36
|
+
expect( response.response_code ).to eql("0")
|
37
|
+
expect( response ).to be_a(Hps::HpsGiftCardReplace)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Add rewards to a card
|
41
|
+
it "When card is ok, it should add rewards and return a valid response" do
|
42
|
+
["USD", "POINTS"].each do |currency|
|
43
|
+
response = Hps::TestHelper.reward_valid_gift_card(10.00, currency)
|
44
|
+
expect( response.response_code ).to eql("0")
|
45
|
+
expect( response ).to be_a(Hps::HpsGiftCardReward)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Complete a sale
|
50
|
+
it "When card is ok, it should complete a sale and return a valid response" do
|
51
|
+
response = Hps::TestHelper.sale_valid_gift_card(10.00)
|
52
|
+
expect( response.response_code ).to eql("0")
|
53
|
+
expect( response ).to be_a(Hps::HpsGiftCardSale)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Void a transaction
|
57
|
+
it "Should void a transaction" do
|
58
|
+
response = Hps::TestHelper.sale_valid_gift_card(10.00)
|
59
|
+
expect( response.response_code ).to eql("0")
|
60
|
+
void_response = Hps::TestHelper.void_gift_card_sale( response.transaction_id )
|
61
|
+
expect( void_response.response_code ).to eql("0")
|
62
|
+
expect( void_response ).to be_a(Hps::HpsGiftCardVoid)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Reverse a transaction using transaction id
|
66
|
+
it "Should reverse a gift card transaction using the transaction id" do
|
67
|
+
response = Hps::TestHelper.sale_valid_gift_card(10.00)
|
68
|
+
expect( response.response_code ).to eql("0")
|
69
|
+
reverse_response = Hps::TestHelper.reverse_gift_card_sale( 10.00, response.transaction_id )
|
70
|
+
expect( reverse_response.response_code ).to eql("0")
|
71
|
+
expect( reverse_response ).to be_a(Hps::HpsGiftCardReversal)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Reverse transaction using giftcard
|
75
|
+
it "Should reverse a giftcard transaction using the card" do
|
76
|
+
response = Hps::TestHelper.sale_valid_gift_card(10.00, "USD", nil, nil, false)
|
77
|
+
expect( response.response_code ).to eql("0")
|
78
|
+
reverse_response = Hps::TestHelper.reverse_gift_card_sale(10.00)
|
79
|
+
expect( reverse_response.response_code ).to eql("0")
|
80
|
+
expect( reverse_response ).to be_a(Hps::HpsGiftCardReversal)
|
81
|
+
end
|
82
|
+
|
83
|
+
context "exceptions for transactions" do
|
84
|
+
before(:all) do
|
85
|
+
@mapper = Hps::ExceptionMapper.new
|
86
|
+
end
|
87
|
+
|
88
|
+
# Amounts less than zero
|
89
|
+
it "raises an exception for amounts less than zero" do
|
90
|
+
%i{activate add_value reward sale reverse}.each do |method|
|
91
|
+
expect{ Hps::TestHelper.gift_card_transaction_exception(-1.00, method) }.to raise_exception{|e|
|
92
|
+
expect(e).to be_a( Hps::InvalidRequestException )
|
93
|
+
expect(e.message).to eql("Amount must be greater than or equal 0.")
|
94
|
+
}
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Profile auth fails
|
99
|
+
it "should raise an exception if profile auth fails" do
|
100
|
+
expect{ Hps::TestHelper.gift_card_transaction_exception(2.01) }.to raise_exception {|e|
|
101
|
+
expect(e).to be_a(Hps::CardException)
|
102
|
+
expect(e.message).to eql("ProfileError Subject 'ProfileAuthorizationFailed'.")
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
# Profile closed
|
107
|
+
it "should raise an exception if profile is closed" do
|
108
|
+
expect{ Hps::TestHelper.gift_card_transaction_exception(2.02) }.to raise_exception {|e|
|
109
|
+
expect(e).to be_a(Hps::CardException)
|
110
|
+
expect(e.message).to eql("ProfileError Subject 'ProfileClosed'.")
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
# Profile not found
|
115
|
+
it "should raise an exception if profile is not found" do
|
116
|
+
expect{ Hps::TestHelper.gift_card_transaction_exception(2.03) }.to raise_exception {|e|
|
117
|
+
expect(e).to be_a(Hps::CardException)
|
118
|
+
expect(e.message).to eql("ProfileError")
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
# Profile frozen
|
123
|
+
it "should raise an exception if profile is frozen" do
|
124
|
+
expect{ Hps::TestHelper.gift_card_transaction_exception(2.04) }.to raise_exception {|e|
|
125
|
+
expect(e).to be_a(Hps::CardException)
|
126
|
+
expect(e.message).to eql("ProfileError Subject 'ProfileFrozen'.")
|
127
|
+
}
|
128
|
+
end
|
129
|
+
|
130
|
+
# Insufficient funds - card decline - code 5
|
131
|
+
it "should raise an exception if insufficient funds" do
|
132
|
+
expect{ Hps::TestHelper.gift_card_transaction_exception(3.01) }.to raise_exception {|e|
|
133
|
+
expect(e).to be_a(Hps::CardException)
|
134
|
+
expect(e.message).to eql(message_for_code("Exception_Message_CardDeclined"))
|
135
|
+
}
|
136
|
+
end
|
137
|
+
|
138
|
+
# Insufficient activation amount - card decline - code 5
|
139
|
+
it "should raise an exception if insufficient activation amount" do
|
140
|
+
expect{ Hps::TestHelper.gift_card_transaction_exception(3.02) }.to raise_exception {|e|
|
141
|
+
expect(e).to be_a(Hps::CardException)
|
142
|
+
expect(e.message).to eql(message_for_code("Exception_Message_CardDeclined"))
|
143
|
+
}
|
144
|
+
end
|
145
|
+
|
146
|
+
# Insufficient load amount - card decline - code 5
|
147
|
+
it "should raise an exception if insufficient load amount" do
|
148
|
+
expect{ Hps::TestHelper.gift_card_transaction_exception(3.03) }.to raise_exception {|e|
|
149
|
+
expect(e).to be_a(Hps::CardException)
|
150
|
+
expect(e.message).to eql(message_for_code("Exception_Message_CardDeclined"))
|
151
|
+
}
|
152
|
+
end
|
153
|
+
|
154
|
+
# Invalid Payment Type - unknown gift error - code 1
|
155
|
+
it "should raise an exception if insufficient load amount" do
|
156
|
+
expect{ Hps::TestHelper.gift_card_transaction_exception(3.04) }.to raise_exception {|e|
|
157
|
+
expect(e).to be_a(Hps::CardException)
|
158
|
+
expect(e.message).to eql("SystemError Subject 'InvalidPaymentType'.")
|
159
|
+
}
|
160
|
+
end
|
161
|
+
|
162
|
+
# Provide an invalid PIN - code 14
|
163
|
+
it "Should raise an exception if PIN is invalid" do
|
164
|
+
expect{ Hps::TestHelper.gift_card_transaction_exception(3.05) }.to raise_exception {|e|
|
165
|
+
expect(e).to be_a(Hps::CardException)
|
166
|
+
expect(e.message).to eql(message_for_code("Exception_Message_InvalidPin"))
|
167
|
+
}
|
168
|
+
end
|
169
|
+
|
170
|
+
# Invalid seller ID - unknown gift error - code 1
|
171
|
+
it "should raise an exception if invalid seller profile ID" do
|
172
|
+
expect{ Hps::TestHelper.gift_card_transaction_exception(3.06) }.to raise_exception {|e|
|
173
|
+
expect(e).to be_a(Hps::CardException)
|
174
|
+
expect(e.message).to eql("SystemError")
|
175
|
+
}
|
176
|
+
end
|
177
|
+
|
178
|
+
# Order exists - processing error - code 7
|
179
|
+
it "should raise an exception if invalid seller profile ID" do
|
180
|
+
expect{ Hps::TestHelper.gift_card_transaction_exception(3.07) }.to raise_exception {|e|
|
181
|
+
expect(e).to be_a(Hps::CardException)
|
182
|
+
expect(e.message).to eql(message_for_code("Exception_Message_ProcessingError"))
|
183
|
+
}
|
184
|
+
end
|
185
|
+
|
186
|
+
# Registration required - invalid card data - code 3
|
187
|
+
it "should raise an exception if invalid seller profile ID" do
|
188
|
+
expect{ Hps::TestHelper.gift_card_transaction_exception(3.08) }.to raise_exception {|e|
|
189
|
+
expect(e).to be_a(Hps::CardException)
|
190
|
+
expect(e.message).to eql(message_for_code("Exception_Message_InvalidCardData"))
|
191
|
+
}
|
192
|
+
end
|
193
|
+
|
194
|
+
# Account not active - invalid card data - code 8
|
195
|
+
it "should raise an exception if invalid seller profile ID" do
|
196
|
+
expect{ Hps::TestHelper.gift_card_transaction_exception(3.09) }.to raise_exception {|e|
|
197
|
+
expect(e).to be_a(Hps::CardException)
|
198
|
+
expect(e.message).to eql(message_for_code("Exception_Message_InvalidCardData"))
|
199
|
+
}
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
end # Giftcard Tests
|
204
|
+
|
205
|
+
# Helper methods
|
206
|
+
def message_for_code(code)
|
207
|
+
mapping = @mapper.exceptions["exception_messages"].detect { |message|
|
208
|
+
message["code"] == code
|
209
|
+
}
|
210
|
+
|
211
|
+
mapping["message"] unless mapping.nil?
|
212
|
+
end
|
data/tests/hps_token_service.rb
CHANGED
@@ -1,56 +1,56 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'json'
|
5
|
-
|
6
|
-
module Hps
|
7
|
-
class HpsTokenService
|
8
|
-
attr_accessor :public_api_key, :url
|
9
|
-
|
10
|
-
def initialize(public_api_key)
|
11
|
-
@public_api_key = public_api_key
|
12
|
-
if @public_api_key.nil? || @public_api_key.eql?('')
|
13
|
-
raise HpsException.new('Public Key Not Found', '0')
|
14
|
-
end
|
15
|
-
|
16
|
-
components = @public_api_key.split '_'
|
17
|
-
if components.size < 3
|
18
|
-
raise HpsException.new('Public API Key must contain at least two underscores','0')
|
19
|
-
end
|
20
|
-
|
21
|
-
if components[1].downcase.eql? 'prod'
|
22
|
-
@url = 'https://api2.heartlandportico.com/SecureSubmit.v1/api/token'
|
23
|
-
else
|
24
|
-
@url = 'https://cert.api2.heartlandportico.com/Hps.Exchange.PosGateway.Hpf.v1/api/token'
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
def get_token(card_data)
|
30
|
-
data = {
|
31
|
-
'api_key' => @public_api_key,
|
32
|
-
'object' => 'token',
|
33
|
-
'token_type' => 'supt',
|
34
|
-
'_method' => 'post',
|
35
|
-
'card[number]' => card_data.number,
|
36
|
-
'card[cvv]' => card_data.cvv,
|
37
|
-
'card[exp_month]' => card_data.exp_month,
|
38
|
-
'card[exp_year]' => card_data.exp_year
|
39
|
-
}
|
40
|
-
get_result = get(data)
|
41
|
-
JSON.parse(get_result)
|
42
|
-
end
|
43
|
-
|
44
|
-
def get(data)
|
45
|
-
begin
|
46
|
-
uri = URI(@url)
|
47
|
-
uri.query = URI.encode_www_form(data)
|
48
|
-
res = Net::HTTP.get_response(uri)
|
49
|
-
res.body
|
50
|
-
|
51
|
-
rescue Exception => e
|
52
|
-
raise HpsException.new(e.message,'0')
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Hps
|
7
|
+
class HpsTokenService
|
8
|
+
attr_accessor :public_api_key, :url
|
9
|
+
|
10
|
+
def initialize(public_api_key)
|
11
|
+
@public_api_key = public_api_key
|
12
|
+
if @public_api_key.nil? || @public_api_key.eql?('')
|
13
|
+
raise HpsException.new('Public Key Not Found', '0')
|
14
|
+
end
|
15
|
+
|
16
|
+
components = @public_api_key.split '_'
|
17
|
+
if components.size < 3
|
18
|
+
raise HpsException.new('Public API Key must contain at least two underscores','0')
|
19
|
+
end
|
20
|
+
|
21
|
+
if components[1].downcase.eql? 'prod'
|
22
|
+
@url = 'https://api2.heartlandportico.com/SecureSubmit.v1/api/token'
|
23
|
+
else
|
24
|
+
@url = 'https://cert.api2.heartlandportico.com/Hps.Exchange.PosGateway.Hpf.v1/api/token'
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_token(card_data)
|
30
|
+
data = {
|
31
|
+
'api_key' => @public_api_key,
|
32
|
+
'object' => 'token',
|
33
|
+
'token_type' => 'supt',
|
34
|
+
'_method' => 'post',
|
35
|
+
'card[number]' => card_data.number,
|
36
|
+
'card[cvv]' => card_data.cvv,
|
37
|
+
'card[exp_month]' => card_data.exp_month,
|
38
|
+
'card[exp_year]' => card_data.exp_year
|
39
|
+
}
|
40
|
+
get_result = get(data)
|
41
|
+
JSON.parse(get_result)
|
42
|
+
end
|
43
|
+
|
44
|
+
def get(data)
|
45
|
+
begin
|
46
|
+
uri = URI(@url)
|
47
|
+
uri.query = URI.encode_www_form(data)
|
48
|
+
res = Net::HTTP.get_response(uri)
|
49
|
+
res.body
|
50
|
+
|
51
|
+
rescue Exception => e
|
52
|
+
raise HpsException.new(e.message,'0')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|