hps 2.2.5 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +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
@@ -2,9 +2,9 @@ require 'hps'
2
2
 
3
3
  module Hps
4
4
  module TestData
5
-
5
+
6
6
  # card holders
7
-
7
+
8
8
  def self.valid_cardholder
9
9
  result = HpsCardHolder.new()
10
10
  result.first_name = "Bill"
@@ -17,7 +17,7 @@ module Hps
17
17
  result.address.country = "United States"
18
18
  result
19
19
  end
20
-
20
+
21
21
  def self.cert_cardholder_shortzip
22
22
  result = HpsCardHolder.new()
23
23
  result.first_name = "Bill"
@@ -27,10 +27,10 @@ module Hps
27
27
  result.address.city = "Irvine"
28
28
  result.address.state = "TX"
29
29
  result.address.zip = "75024"
30
- result.address.country = "United States"
31
- result
30
+ result.address.country = "United States"
31
+ result
32
32
  end
33
-
33
+
34
34
  def self.cert_cardholder_shortzip_no_street
35
35
  result = HpsCardHolder.new()
36
36
  result.first_name = "Bill"
@@ -39,10 +39,10 @@ module Hps
39
39
  result.address.city = "Irvine"
40
40
  result.address.state = "TX"
41
41
  result.address.zip = "75024"
42
- result.address.country = "United States"
43
- result
42
+ result.address.country = "United States"
43
+ result
44
44
  end
45
-
45
+
46
46
  def self.cert_cardholder_longzip
47
47
  result = HpsCardHolder.new()
48
48
  result.first_name = "Bill"
@@ -52,10 +52,10 @@ module Hps
52
52
  result.address.city = "Irvine"
53
53
  result.address.state = "TX"
54
54
  result.address.zip = "750241234"
55
- result.address.country = "United States"
56
- result
55
+ result.address.country = "United States"
56
+ result
57
57
  end
58
-
58
+
59
59
  def self.cert_cardholder_longzip_no_street
60
60
  result = HpsCardHolder.new()
61
61
  result.first_name = "Bill"
@@ -64,12 +64,12 @@ module Hps
64
64
  result.address.city = "Irvine"
65
65
  result.address.state = "TX"
66
66
  result.address.zip = "750241234"
67
- result.address.country = "United States"
68
- result
67
+ result.address.country = "United States"
68
+ result
69
69
  end
70
-
70
+
71
71
  # credit cards
72
-
72
+
73
73
  def self.valid_visa
74
74
  result = HpsCreditCard.new
75
75
  result.cvv = 123
@@ -78,7 +78,7 @@ module Hps
78
78
  result.number = 4012002000060016
79
79
  result
80
80
  end
81
-
81
+
82
82
  def self.valid_mastercard
83
83
  result = HpsCreditCard.new
84
84
  result.cvv = 123
@@ -87,7 +87,7 @@ module Hps
87
87
  result.number = 5473500000000014
88
88
  result
89
89
  end
90
-
90
+
91
91
  def self.valid_discover
92
92
  result = HpsCreditCard.new
93
93
  result.cvv = 123
@@ -96,7 +96,7 @@ module Hps
96
96
  result.number = 6011000990156527
97
97
  result
98
98
  end
99
-
99
+
100
100
  def self.valid_amex
101
101
  result = HpsCreditCard.new
102
102
  result.cvv = 1234
@@ -105,7 +105,7 @@ module Hps
105
105
  result.number = 372700699251018
106
106
  result
107
107
  end
108
-
108
+
109
109
  def self.valid_jcb
110
110
  result = HpsCreditCard.new
111
111
  result.cvv = 123
@@ -114,7 +114,7 @@ module Hps
114
114
  result.number = 3566007770007321
115
115
  result
116
116
  end
117
-
117
+
118
118
  def self.invalid_card
119
119
  result = HpsCreditCard.new
120
120
  result.cvv = 123
@@ -123,6 +123,16 @@ module Hps
123
123
  result.number = 12345
124
124
  result
125
125
  end
126
-
126
+
127
+ # =============
128
+ # = Giftcards =
129
+ # =============
130
+ TEST_CARD_NUMBERS = (6277200000000001..6277200000000099)
131
+
132
+ def self.valid_gift_card_not_encrypted(random = true)
133
+ return HpsGiftCard.new(Random.rand(TEST_CARD_NUMBERS)) if random
134
+ return HpsGiftCard.new(TEST_CARD_NUMBERS.first) if !random
135
+ end # valid_gift_card_not_encrypted
136
+
127
137
  end
128
138
  end
@@ -112,5 +112,68 @@ module Hps
112
112
  end
113
113
  end
114
114
 
115
+ # =============
116
+ # = Giftcards =
117
+ # =============
118
+ def self.balance_valid_gift_card
119
+ TestHelper.valid_multi_use_config
120
+ service = Hps::HpsGiftCardService.new
121
+ service.balance( TestData.valid_gift_card_not_encrypted )
122
+ end # balance_valid_gift_card
123
+
124
+ def self.activate_valid_gift_card(amount)
125
+ TestHelper.valid_multi_use_config
126
+ service = Hps::HpsGiftCardService.new
127
+ service.activate( TestData.valid_gift_card_not_encrypted, amount, 'USD' )
128
+ end # activate_valid_gift_card
129
+
130
+ def self.add_value_to_valid_gift_card(amount)
131
+ TestHelper.valid_multi_use_config
132
+ service = Hps::HpsGiftCardService.new
133
+ service.add_value( TestData.valid_gift_card_not_encrypted, amount, 'USD' )
134
+ end # add_value_to_valid_gift_card
135
+
136
+ def self.deactivate_valid_gift_card
137
+ TestHelper.valid_multi_use_config
138
+ service = Hps::HpsGiftCardService.new
139
+ service.deactivate( TestData.valid_gift_card_not_encrypted )
140
+ end # deactivate_valid_gift_card
141
+
142
+ def self.replace_valid_gift_card
143
+ TestHelper.valid_multi_use_config
144
+ service = Hps::HpsGiftCardService.new
145
+ service.replace( TestData.valid_gift_card_not_encrypted, TestData.valid_gift_card_not_encrypted )
146
+ end # replace_valid_gift_card
147
+
148
+ def self.reward_valid_gift_card(amount, currency = "USD", gratuity = nil, tax = nil)
149
+ TestHelper.valid_multi_use_config
150
+ service = Hps::HpsGiftCardService.new
151
+ service.reward( TestData.valid_gift_card_not_encrypted, amount, 'USD', gratuity, tax )
152
+ end # reward_valid_gift_card
153
+
154
+ def self.sale_valid_gift_card(amount, currency = "USD", gratuity = nil, tax = nil, random_card = true)
155
+ TestHelper.valid_multi_use_config
156
+ service = Hps::HpsGiftCardService.new
157
+ service.sale( TestData.valid_gift_card_not_encrypted(random_card), amount, currency, gratuity, tax)
158
+ end # sale_valid_gift_card
159
+
160
+ def self.void_gift_card_sale(txn_id)
161
+ TestHelper.valid_multi_use_config
162
+ service = Hps::HpsGiftCardService.new
163
+ service.void( txn_id )
164
+ end # void_gift_card_sale
165
+
166
+ def self.reverse_gift_card_sale(amount, txn_id = TestData.valid_gift_card_not_encrypted(false))
167
+ TestHelper.valid_multi_use_config
168
+ service = Hps::HpsGiftCardService.new
169
+ service.reverse( txn_id, amount )
170
+ end # reverse_gift_card_sale
171
+
172
+ # Testing exceptions from transactions
173
+ def self.gift_card_transaction_exception(amount, method = :sale)
174
+ TestHelper.valid_multi_use_config
175
+ service = Hps::HpsGiftCardService.new
176
+ service.send(method, TestData.valid_gift_card_not_encrypted, amount )
177
+ end # gift_card_sale_with_invaid_pin
115
178
  end
116
179
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hps
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.5
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Heartland Payment Systems
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-19 00:00:00.000000000 Z
11
+ date: 2018-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -93,9 +93,9 @@ dependencies:
93
93
  - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: 2.3.14
96
- - - "<"
96
+ - - "<="
97
97
  - !ruby/object:Gem::Version
98
- version: 5.0.0
98
+ version: 5.0.1
99
99
  type: :runtime
100
100
  prerelease: false
101
101
  version_requirements: !ruby/object:Gem::Requirement
@@ -103,9 +103,9 @@ dependencies:
103
103
  - - ">="
104
104
  - !ruby/object:Gem::Version
105
105
  version: 2.3.14
106
- - - "<"
106
+ - - "<="
107
107
  - !ruby/object:Gem::Version
108
- version: 5.0.0
108
+ version: 5.0.1
109
109
  description: Ruby SDK for processing payments via Portico Gateway
110
110
  email:
111
111
  - IntegrationSupportTeam@e-hps.com
@@ -114,7 +114,7 @@ extensions: []
114
114
  extra_rdoc_files: []
115
115
  files:
116
116
  - Gemfile
117
- - LICENSE.txt
117
+ - LICENSE.md
118
118
  - PRIVACY.txt
119
119
  - README.md
120
120
  - Rakefile
@@ -155,6 +155,7 @@ files:
155
155
  - lib/hps/entities/hps_credit_card.rb
156
156
  - lib/hps/entities/hps_direct_market_data.rb
157
157
  - lib/hps/entities/hps_encryption_data.rb
158
+ - lib/hps/entities/hps_gift_card.rb
158
159
  - lib/hps/entities/hps_manage_tokens.rb
159
160
  - lib/hps/entities/hps_refund.rb
160
161
  - lib/hps/entities/hps_report_transaction_details.rb
@@ -186,15 +187,19 @@ files:
186
187
  - lib/hps/services/hps_batch_service.rb
187
188
  - lib/hps/services/hps_charge_service.rb
188
189
  - lib/hps/services/hps_check_service.rb
190
+ - lib/hps/services/hps_gift_card_service.rb
189
191
  - lib/hps/services/hps_service.rb
190
192
  - lib/hps/version.rb
191
193
  - tests/amex_tests.rb
192
194
  - tests/cert_tests.rb
193
195
  - tests/certification/card_present_spec.rb
196
+ - tests/certification/gift_card_certification_test.rb
197
+ - tests/certification/gift_card_certification_tests.rb
194
198
  - tests/check_tests.rb
195
199
  - tests/discover_tests.rb
196
200
  - tests/exception_mapper_tests.rb
197
201
  - tests/general_tests.rb
202
+ - tests/giftcard_tests.rb
198
203
  - tests/hps_token_service.rb
199
204
  - tests/mastercard_tests.rb
200
205
  - tests/secret_key.rb
@@ -205,7 +210,7 @@ files:
205
210
  - tests/visa_tests.rb
206
211
  homepage: ''
207
212
  licenses:
208
- - MIT
213
+ - GPL-2.0
209
214
  metadata: {}
210
215
  post_install_message:
211
216
  rdoc_options: []
@@ -223,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
228
  version: '0'
224
229
  requirements: []
225
230
  rubyforge_project:
226
- rubygems_version: 2.6.13
231
+ rubygems_version: 2.7.6
227
232
  signing_key:
228
233
  specification_version: 4
229
234
  summary: Heartland Payment Systems - Portico Gateway SDK