beanstream 1.0.0.rc1

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.
@@ -0,0 +1,280 @@
1
+ require 'test/unit'
2
+ require 'beanstream'
3
+ require 'shoulda'
4
+
5
+ module Beanstream
6
+
7
+ class PaymentsAPITest < Test::Unit::TestCase
8
+
9
+ should "canery test print out Beanstream!" do
10
+ puts "Beanstream!"
11
+ assert true
12
+ end
13
+
14
+ should "make payment url be the same" do
15
+ assert_equal("/api/v1/payments/", PaymentsAPI.new.make_payment_url())
16
+ end
17
+
18
+ should "make return url be the same" do
19
+ assert_equal("/api/v1/payments/1234/returns", PaymentsAPI.new.payment_returns_url("1234"))
20
+ end
21
+
22
+ should "make void url be the same" do
23
+ assert_equal("/api/v1/payments/1234/void", PaymentsAPI.new.payment_void_url("1234"))
24
+ end
25
+ end
26
+
27
+ class PaymentsAPIIntegrationTest < Test::Unit::TestCase
28
+
29
+ setup do
30
+ Beanstream.merchant_id = "300200578"
31
+ Beanstream.payments_api_key = "4BaD82D9197b4cc4b70a221911eE9f70"
32
+ end
33
+
34
+ #Card purchase
35
+ should "have successful credit card payment" do
36
+
37
+ result = Beanstream.PaymentsAPI.make_payment(
38
+ {
39
+ :order_number => PaymentsAPI.generateRandomOrderId("test"),
40
+ :amount => 100,
41
+ :payment_method => PaymentMethods::CARD,
42
+ :card => {
43
+ :name => "Mr. Card Testerson",
44
+ :number => "4030000010001234",
45
+ :expiry_month => "07",
46
+ :expiry_year => "22",
47
+ :cvd => "123",
48
+ :complete => true
49
+ }
50
+ }
51
+ )
52
+ puts "result: #{result}"
53
+
54
+ assert(PaymentsAPI.payment_approved(result))
55
+ transaction_id = result['id']
56
+ puts "TransactionId: #{transaction_id}"
57
+ end
58
+
59
+ # Token purchase
60
+ should "purchase successfully with a legato token" do
61
+
62
+ token = Beanstream.PaymentsAPI.get_legato_token(
63
+ {
64
+ :number => "4030000010001234",
65
+ :expiry_month => "07",
66
+ :expiry_year => "22",
67
+ :cvd => "123"
68
+ }
69
+ )
70
+ puts "token result: #{token}"
71
+ assert(token != nil)
72
+
73
+ result = Beanstream.PaymentsAPI.make_payment(
74
+ {
75
+ :order_number => PaymentsAPI.generateRandomOrderId("test"),
76
+ :amount => 13.99,
77
+ :payment_method => PaymentMethods::TOKEN,
78
+ :token => {
79
+ :name => "Bobby Test",
80
+ :code => token,
81
+ :complete => true
82
+ }
83
+ }
84
+ )
85
+ puts "result: #{result}"
86
+ assert(PaymentsAPI.payment_approved(result))
87
+
88
+ end
89
+
90
+ #Card decline
91
+ should "have declined credit card payment" do
92
+
93
+ decline = false
94
+ begin
95
+ result = Beanstream.PaymentsAPI.make_payment(
96
+ {
97
+ :order_number => PaymentsAPI.generateRandomOrderId("test"),
98
+ :amount => 100,
99
+ :payment_method => PaymentMethods::CARD,
100
+ :card => {
101
+ :name => "Mr. Card Testerson",
102
+ :number => "4003050500040005", #declined card
103
+ :expiry_month => "07",
104
+ :expiry_year => "22",
105
+ :cvd => "123",
106
+ :complete => true
107
+ }
108
+ })
109
+ rescue BeanstreamException => ex
110
+ decline = true
111
+ puts "Exception: #{ex.user_facing_message}"
112
+ assert(ex.user_facing_message == "DECLINE")
113
+ assert(ex.is_user_error())
114
+ end
115
+
116
+ assert(decline)
117
+
118
+ end
119
+
120
+ #PreAuth card
121
+ should "have successful credit card pre-auth and completion" do
122
+
123
+ result = Beanstream.PaymentsAPI.make_payment(
124
+ {
125
+ :order_number => PaymentsAPI.generateRandomOrderId("test"),
126
+ :amount => 100,
127
+ :payment_method => PaymentMethods::CARD,
128
+ :card => {
129
+ :name => "Mr. Card Testerson",
130
+ :number => "4030000010001234",
131
+ :expiry_month => "07",
132
+ :expiry_year => "22",
133
+ :cvd => "123",
134
+ :complete => false
135
+ }
136
+ }
137
+ )
138
+ puts "result: #{result}"
139
+
140
+ assert(PaymentsAPI.payment_approved(result))
141
+ transaction_id = result['id']
142
+ puts "TransactionId: #{transaction_id}"
143
+
144
+ result = Beanstream.PaymentsAPI.complete_preauth(transaction_id, 59.50)
145
+ puts "completion result: #{result}"
146
+ assert(PaymentsAPI.payment_approved(result))
147
+ end
148
+
149
+ #PreAuth token
150
+ should "pre-auth and complete successfully with a legato token" do
151
+
152
+ # 1) get token
153
+ token = Beanstream.PaymentsAPI.get_legato_token(
154
+ {
155
+ :number => "4030000010001234",
156
+ :expiry_month => "07",
157
+ :expiry_year => "22",
158
+ :cvd => "123"
159
+ }
160
+ )
161
+ puts "token result: #{token}"
162
+ assert(token != nil)
163
+
164
+ # 2) make pre-auth
165
+ result = Beanstream.PaymentsAPI.make_payment(
166
+ {
167
+ :order_number => PaymentsAPI.generateRandomOrderId("test"),
168
+ :amount => 13.99,
169
+ :payment_method => PaymentMethods::TOKEN,
170
+ :token => {
171
+ :name => "Bobby Test",
172
+ :code => token,
173
+ :complete => false
174
+ }
175
+ }
176
+ )
177
+ puts "result: #{result}"
178
+ assert(PaymentsAPI.payment_approved(result))
179
+ transaction_id = result['id']
180
+
181
+ # 3) complete purchase
182
+ result = Beanstream.PaymentsAPI.complete_preauth(transaction_id, 10.33)
183
+ puts "completion result: #{result}"
184
+ assert(PaymentsAPI.payment_approved(result))
185
+ end
186
+
187
+ #Return
188
+ should "have successful credit card payment, then get the payment, then return the payment" do
189
+
190
+ result = Beanstream.PaymentsAPI.make_payment(
191
+ {
192
+ :order_number => PaymentsAPI.generateRandomOrderId("test"),
193
+ :amount => 100,
194
+ :payment_method => PaymentMethods::CARD,
195
+ :card => {
196
+ :name => "Mr. Card Testerson",
197
+ :number => "4030000010001234",
198
+ :expiry_month => "07",
199
+ :expiry_year => "22",
200
+ :cvd => "123",
201
+ :complete => true
202
+ }
203
+ }
204
+ )
205
+
206
+ transaction_id = result['id']
207
+
208
+ # => test get payments
209
+ get_result = Beanstream.PaymentsAPI.get_transaction(transaction_id)
210
+ assert_equal "P", get_result["type"]
211
+ assert_equal "Approved", get_result["message"]
212
+
213
+ # => test return payment
214
+ return_result = Beanstream.PaymentsAPI.return_payment(transaction_id, 100)
215
+ assert_equal "Approved", return_result["message"]
216
+ assert_equal "R", return_result["type"]
217
+ get_after_return = Beanstream.PaymentsAPI.get_transaction(transaction_id)
218
+ assert_equal 100.0, get_after_return["total_refunds"]
219
+
220
+ # => try to void the payment after returning
221
+ assert_raises InvalidRequestException do
222
+ Beanstream.PaymentsAPI.void_payment(transaction_id, 100)
223
+ end
224
+ end
225
+
226
+ #Void
227
+ should "have successful credit card payment, then void the payment" do
228
+
229
+ result = Beanstream.PaymentsAPI.make_payment(
230
+ {
231
+ :order_number => PaymentsAPI.generateRandomOrderId("test"),
232
+ :amount => 100,
233
+ :payment_method => PaymentMethods::CARD,
234
+ :card => {
235
+ :name => "Mr. Card Testerson",
236
+ :number => "4030000010001234",
237
+ :expiry_month => "07",
238
+ :expiry_year => "22",
239
+ :cvd => "123",
240
+ :complete => true
241
+ }
242
+ }
243
+ )
244
+
245
+ transaction_id = result['id']
246
+
247
+ # => test void payment
248
+ void_result = Beanstream.PaymentsAPI.void_payment(transaction_id, 100)
249
+ assert_equal "Approved", void_result["message"]
250
+ assert_equal "VP", void_result["type"]
251
+ get_after_void = Beanstream.PaymentsAPI.get_transaction(transaction_id)
252
+ assert_equal "VP", get_after_void["adjusted_by"][0]["type"]
253
+
254
+ # => try to return the payment after voiding
255
+ assert_raises InvalidRequestException do
256
+ Beanstream.PaymentsAPI.return_payment(transaction_id, 100)
257
+ end
258
+ end
259
+
260
+ should "not get a random transaction id" do
261
+ assert_raises InvalidRequestException do
262
+ Beanstream.PaymentsAPI.get_transaction("500")
263
+ end
264
+ end
265
+
266
+ should "not return a random transaction id" do
267
+ assert_raises InvalidRequestException do
268
+ Beanstream.PaymentsAPI.return_payment("500", 100)
269
+ end
270
+ end
271
+
272
+ should "not void a random transaction id" do
273
+ assert_raises InvalidRequestException do
274
+ Beanstream.PaymentsAPI.void_payment("500", 100)
275
+ end
276
+ end
277
+
278
+ end
279
+
280
+ end
@@ -0,0 +1,261 @@
1
+ require 'test/unit'
2
+ require 'beanstream'
3
+ require 'shoulda'
4
+
5
+ module Beanstream
6
+
7
+ class ProfilesAPITest < Test::Unit::TestCase
8
+
9
+ setup do
10
+ Beanstream.merchant_id = "300200578"
11
+ Beanstream.payments_api_key = "4BaD82D9197b4cc4b70a221911eE9f70"
12
+ Beanstream.profiles_api_key = "D97D3BE1EE964A6193D17A571D9FBC80"
13
+ end
14
+
15
+ should "make profiles url be the same" do
16
+ assert_equal("/api/v1/profiles", ProfilesAPI.new.profile_url())
17
+ end
18
+
19
+ should "make profiles/cards url be the same" do
20
+ assert_equal("/api/v1/profiles/cards", ProfilesAPI.new.profile_cards_url())
21
+ end
22
+ end
23
+
24
+ class ProfilesAPIIntegrationTest < Test::Unit::TestCase
25
+
26
+ setup do
27
+ Beanstream.merchant_id = "300200578"
28
+ Beanstream.payments_api_key = "4BaD82D9197b4cc4b70a221911eE9f70"
29
+ Beanstream.profiles_api_key = "D97D3BE1EE964A6193D17A571D9FBC80"
30
+ @profile = Beanstream.ProfilesAPI.create_profile(
31
+ {
32
+ :billing => {
33
+ :name => "Hilary Test",
34
+ :address_line1 => "123 Fake St.",
35
+ :city => "Victoria",
36
+ :province => "BC",
37
+ :country => "CA",
38
+ :postal_code => "v1v2v2",
39
+ :phone_number => "12505551234",
40
+ :email_address => "fake@example.com"
41
+ }
42
+ })
43
+
44
+ @card1 = {
45
+ :card => {
46
+ :name => "Hilary Test",
47
+ :number => "4030000010001234",
48
+ :expiry_month => "07",
49
+ :expiry_year => "22",
50
+ :cvd => "123"
51
+ }
52
+ }
53
+
54
+ @card2 = {
55
+ :card => {
56
+ :name => "John Doe",
57
+ :number => "5100000010001004",
58
+ :expiry_month => "12",
59
+ :expiry_year => "14",
60
+ :cvd => "123"
61
+ }
62
+ }
63
+
64
+ end
65
+
66
+ # Profile CREATE
67
+ should "have successfully created a profile" do
68
+ result = Beanstream.ProfilesAPI.create_profile(
69
+ {
70
+ :card => {
71
+ :name => "Bob Test",
72
+ :number => "4030000010001234",
73
+ :expiry_month => "07",
74
+ :expiry_year => "22",
75
+ :cvd => "123"
76
+ },
77
+ :billing => {
78
+ :name => "Bob Test",
79
+ :address_line1 => "123 Fake St.",
80
+ :city => "Victoria",
81
+ :province => "BC",
82
+ :country => "CA",
83
+ :postal_code => "v1v2v2",
84
+ :phone_number => "12505551234",
85
+ :email_address => "fake@example.com"
86
+ }
87
+ })
88
+ assert(ProfilesAPI.profile_successfully_created(result))
89
+ profile_id = result['customer_code']
90
+ puts "Created profile with ID: #{profile_id}"
91
+ end
92
+
93
+ # Profile DELETE
94
+ should "have successfully deleted a profile" do
95
+
96
+ Beanstream.merchant_id = "300200578"
97
+ Beanstream.profiles_api_key = "D97D3BE1EE964A6193D17A571D9FBC80"
98
+
99
+ result = Beanstream.ProfilesAPI.create_profile(
100
+ {
101
+ :card => {
102
+ :name => "Jill Test",
103
+ :number => "4030000010001234",
104
+ :expiry_month => "07",
105
+ :expiry_year => "22",
106
+ :cvd => "123"
107
+ },
108
+ :billing => {
109
+ :name => "Jill Test",
110
+ :address_line1 => "123 Fake St.",
111
+ :city => "Victoria",
112
+ :province => "BC",
113
+ :country => "CA",
114
+ :postal_code => "v1v2v2",
115
+ :phone_number => "12505551234",
116
+ :email_address => "fake@example.com"
117
+ }
118
+ })
119
+ assert(ProfilesAPI.profile_successfully_created(result))
120
+ profile_id = result['customer_code']
121
+ puts "Created profile with ID: #{profile_id}"
122
+
123
+ # now delete the profile
124
+ result = Beanstream.ProfilesAPI.delete_profile(profile_id)
125
+ assert(ProfilesAPI.profile_successfully_deleted(result))
126
+ puts "Deleted profile #{result['customer_code']}"
127
+ end
128
+
129
+ # Profile GET
130
+ should "have successfully retrieved a profile" do
131
+
132
+ Beanstream.merchant_id = "300200578"
133
+ Beanstream.profiles_api_key = "D97D3BE1EE964A6193D17A571D9FBC80"
134
+
135
+ result = Beanstream.ProfilesAPI.create_profile(
136
+ {
137
+ :card => {
138
+ :name => "Jill Test",
139
+ :number => "4030000010001234",
140
+ :expiry_month => "07",
141
+ :expiry_year => "22",
142
+ :cvd => "123"
143
+ },
144
+ :billing => {
145
+ :name => "Jill Test",
146
+ :address_line1 => "123 Fake St.",
147
+ :city => "Victoria",
148
+ :province => "BC",
149
+ :country => "CA",
150
+ :postal_code => "v1v2v2",
151
+ :phone_number => "12505551234",
152
+ :email_address => "fake@example.com"
153
+ }
154
+ })
155
+ assert(ProfilesAPI.profile_successfully_created(result))
156
+ profile_id = result['customer_code']
157
+ puts "Created profile with ID: #{profile_id}"
158
+
159
+ # now get that profile
160
+ result = Beanstream.ProfilesAPI.get_profile(profile_id)
161
+ assert(result != nil)
162
+ assert(result['billing']['name'] == "Jill Test")
163
+
164
+ Beanstream.ProfilesAPI.delete_profile(profile_id) #delete it to clean up
165
+ end
166
+
167
+ # Profile UPDATE
168
+ should "have successfully updated a profile" do
169
+
170
+ Beanstream.merchant_id = "300200578"
171
+ Beanstream.profiles_api_key = "D97D3BE1EE964A6193D17A571D9FBC80"
172
+
173
+ result = Beanstream.ProfilesAPI.create_profile(
174
+ {
175
+ :card => {
176
+ :name => "Hilary Test",
177
+ :number => "4030000010001234",
178
+ :expiry_month => "07",
179
+ :expiry_year => "22",
180
+ :cvd => "123"
181
+ },
182
+ :billing => {
183
+ :name => "Hilary Test",
184
+ :address_line1 => "123 Fake St.",
185
+ :city => "Victoria",
186
+ :province => "BC",
187
+ :country => "CA",
188
+ :postal_code => "v1v2v2",
189
+ :phone_number => "12505551234",
190
+ :email_address => "fake@example.com"
191
+ }
192
+ })
193
+ assert(ProfilesAPI.profile_successfully_created(result))
194
+ profile_id = result['customer_code']
195
+ puts "Created profile with ID: #{profile_id}"
196
+
197
+ # now get that profile
198
+ profile1 = Beanstream.ProfilesAPI.get_profile(profile_id)
199
+ assert(profile1 != nil)
200
+ assert(profile1['billing']['name'] == "Hilary Test")
201
+ puts "\n\nRetrieved Profile 1:\n\n #{profile1}"
202
+
203
+ #update profile
204
+ profile1['billing']['name'] = "gizmo test"
205
+ profile1['language'] = "en"
206
+ profile1['comments'] = "test profile"
207
+ profile1['custom']['ref1'] = "i wish"
208
+ profile1['custom']['ref2'] = "i was"
209
+ profile1['custom']['ref3'] = "an oscar"
210
+ profile1['custom']['ref4'] = "mayer"
211
+ profile1['custom']['ref5'] = "weiner"
212
+ result = Beanstream.ProfilesAPI.update_profile(profile1)
213
+
214
+ #get profile again and check the updates
215
+ profile2 = Beanstream.ProfilesAPI.get_profile(profile_id)
216
+ puts "\n\nRetrieved Profile 2:\n\n #{profile2}"
217
+ assert(profile2 != nil)
218
+ assert(profile2['billing']['name'] == "gizmo test")
219
+ assert(profile2['language'] == "en")
220
+ assert(profile2['custom']['ref1'] == "i wish")
221
+ assert(profile2['custom']['ref2'] == "i was")
222
+ assert(profile2['custom']['ref3'] == "an oscar")
223
+ assert(profile2['custom']['ref4'] == "mayer")
224
+ assert(profile2['custom']['ref5'] == "weiner")
225
+
226
+ Beanstream.ProfilesAPI.delete_profile(profile_id) #delete it to clean up
227
+ end
228
+
229
+ should 'Successfully Add Card' do
230
+ insert_card = Beanstream.ProfilesAPI.add_profile_card(@profile,@card1)
231
+ #Retrieve Profile again to check if card added
232
+ profile2 = Beanstream.ProfilesAPI.get_profile(@profile['customer_code'])
233
+ assert(profile2['card'])
234
+ assert(insert_card['message']== 'Operation Successful')
235
+ end
236
+
237
+ should 'Successfully get Card' do
238
+ add_card = Beanstream.ProfilesAPI.add_profile_card(@profile,@card1)
239
+ card = Beanstream.ProfilesAPI.get_profile_card(@profile)
240
+ assert(card)
241
+ assert(card['message']== 'Operation Successful')
242
+ end
243
+
244
+ should 'successfully update card' do
245
+ # Create profile with card 1
246
+ insert_card = Beanstream.ProfilesAPI.add_profile_card(@profile,@card2)
247
+ # Update profile with card 2
248
+ update_card = Beanstream.ProfilesAPI.update_profile_card(@profile,1,@card1)
249
+ profile2 = Beanstream.ProfilesAPI.get_profile(@profile['customer_code'])
250
+ assert(update_card['message']== 'Operation Successful')
251
+ end
252
+
253
+ should 'successfully delete card' do
254
+ # Create profile with card 1
255
+ insert_card = Beanstream.ProfilesAPI.add_profile_card(@profile,@card2)
256
+ # delete card from profile
257
+ delete_card = Beanstream.ProfilesAPI.delete_profile_card(@profile,1)
258
+ assert(delete_card['message']== 'Operation Successful')
259
+ end
260
+ end
261
+ end