beanstream 1.0.0.rc1 → 1.0.0.rc2
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/beanstream.gemspec +2 -2
- data/lib/beanstream/payments_api.rb +4 -1
- data/lib/beanstream/profiles_api.rb +58 -0
- data/lib/beanstream/transaction.rb +2 -2
- data/test/beanstream/payments_api_test.rb +75 -54
- data/test/beanstream/profiles_api_test.rb +127 -25
- data/test/beanstream/reporting_api_test.rb +16 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c9a72d6147bf8de094eb500954634b6ce9585a3
|
4
|
+
data.tar.gz: bf87fd124feaa654a9dd0f24a9007889b4795877
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91b68de4e5d298b720e98b82fbf2d87aab88d7b6e7e3dfa34a361e540a3816319ee25ec9192d7bfdfb7030af76258b607d163b74f91e398b86467079b89ce5a6
|
7
|
+
data.tar.gz: 864d5dcb81d8e90ab79079d0426d4c70bf93fd1c318abafca33af0d030bae12693d1e7ad2354f0fb9a8e46ad7914f93655fe6f7562924b57b7d1264d45b551a8
|
data/beanstream.gemspec
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'beanstream'
|
6
|
-
s.version = '1.0.0.
|
7
|
-
s.date = '2015-08-
|
6
|
+
s.version = '1.0.0.rc2'
|
7
|
+
s.date = '2015-08-21'
|
8
8
|
s.summary = "Beanstream Ruby SDK"
|
9
9
|
s.description = "Accept payments using Beanstream and Ruby"
|
10
10
|
s.authors = ["Brent Owens", "Colin Walker", "Tom Mengda"]
|
@@ -44,6 +44,7 @@ module Beanstream
|
|
44
44
|
:code => "",
|
45
45
|
:complete => true
|
46
46
|
}
|
47
|
+
return request
|
47
48
|
end
|
48
49
|
|
49
50
|
#Payment Request Hash for making a payment with a credit card number
|
@@ -58,17 +59,19 @@ module Beanstream
|
|
58
59
|
:cvd => "",
|
59
60
|
:complete => true
|
60
61
|
}
|
62
|
+
return request
|
61
63
|
end
|
62
64
|
|
63
65
|
#Payment Request Hash for making a payment with a Payment Profile
|
64
66
|
def getProfilePaymentRequestTemplate()
|
65
67
|
request = getPaymentRequestTemplate()
|
66
68
|
request[:payment_method] = PaymentMethods::PROFILE
|
67
|
-
request[:
|
69
|
+
request[:payment_profile] = {
|
68
70
|
:customer_code => "",
|
69
71
|
:card_id => 1,
|
70
72
|
:complete => true
|
71
73
|
}
|
74
|
+
return request
|
72
75
|
end
|
73
76
|
|
74
77
|
# Base Payment Request Hash for making a payments
|
@@ -11,6 +11,64 @@ module Beanstream
|
|
11
11
|
"#{Beanstream.api_base_url()}/profiles/cards"
|
12
12
|
end
|
13
13
|
|
14
|
+
def getCreateProfileWithCardTemplate()
|
15
|
+
request = getProfileTemplate()
|
16
|
+
request[:card] = {
|
17
|
+
:name => "",
|
18
|
+
:number => "",
|
19
|
+
:expiry_month => "",
|
20
|
+
:expiry_year => "",
|
21
|
+
:cvd => ""
|
22
|
+
}
|
23
|
+
return request
|
24
|
+
end
|
25
|
+
|
26
|
+
def getCreateProfileWithTokenTemplate()
|
27
|
+
request = getProfileTemplate()
|
28
|
+
request[:token] = {
|
29
|
+
:name => "",
|
30
|
+
:code => ""
|
31
|
+
}
|
32
|
+
return request
|
33
|
+
end
|
34
|
+
|
35
|
+
# a template for a Secure Payment Profile
|
36
|
+
def getProfileTemplate()
|
37
|
+
request = {
|
38
|
+
:language=> "",
|
39
|
+
:comments=> "",
|
40
|
+
:billing=> {
|
41
|
+
:name=> "",
|
42
|
+
:address_line1=> "",
|
43
|
+
:address_line2=> "",
|
44
|
+
:city=> "",
|
45
|
+
:province=> "",
|
46
|
+
:country=> "",
|
47
|
+
:postal_code=> "",
|
48
|
+
:phone_number=> "",
|
49
|
+
:email_address=> ""
|
50
|
+
},
|
51
|
+
:shipping=> {
|
52
|
+
:name=> "",
|
53
|
+
:address_line1=> "",
|
54
|
+
:address_line2=> "",
|
55
|
+
:city=> "",
|
56
|
+
:province=> "",
|
57
|
+
:country=> "",
|
58
|
+
:postal_code=> "",
|
59
|
+
:phone_number=> "",
|
60
|
+
:email_address=> ""
|
61
|
+
},
|
62
|
+
:custom=> {
|
63
|
+
:ref1=> "",
|
64
|
+
:ref2=> "",
|
65
|
+
:ref3=> "",
|
66
|
+
:ref4=> "",
|
67
|
+
:ref5=> ""
|
68
|
+
}
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
14
72
|
def create_profile(profile)
|
15
73
|
val = transaction_post("POST", profile_url, Beanstream.merchant_id, Beanstream.profiles_api_key, profile)
|
16
74
|
end
|
@@ -14,7 +14,7 @@ module Beanstream
|
|
14
14
|
enc = encode(merchant_id, api_key)
|
15
15
|
|
16
16
|
path = Beanstream.api_host_url+url_path
|
17
|
-
puts "processing the data: #{method} #{path} #{data.to_json}"
|
17
|
+
#puts "processing the data: #{method} #{path} #{data.to_json}"
|
18
18
|
|
19
19
|
req_params = {
|
20
20
|
:verify_ssl => OpenSSL::SSL::VERIFY_PEER,
|
@@ -46,7 +46,7 @@ module Beanstream
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def handle_api_error(ex)
|
49
|
-
puts "error: #{ex}"
|
49
|
+
#puts "error: #{ex}"
|
50
50
|
|
51
51
|
http_status_code = ex.http_code
|
52
52
|
message = ex.message
|
@@ -70,21 +70,24 @@ module Beanstream
|
|
70
70
|
puts "token result: #{token}"
|
71
71
|
assert(token != nil)
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
:
|
80
|
-
|
81
|
-
|
73
|
+
begin
|
74
|
+
result = Beanstream.PaymentsAPI.make_payment(
|
75
|
+
{
|
76
|
+
:order_number => PaymentsAPI.generateRandomOrderId("test"),
|
77
|
+
:amount => 13.99,
|
78
|
+
:payment_method => PaymentMethods::TOKEN,
|
79
|
+
:token => {
|
80
|
+
:name => "Bobby Test",
|
81
|
+
:code => token,
|
82
|
+
:complete => true
|
83
|
+
}
|
82
84
|
}
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
)
|
86
|
+
puts "result: #{result}"
|
87
|
+
assert(PaymentsAPI.payment_approved(result))
|
88
|
+
rescue BeanstreamException => ex
|
89
|
+
assert(false)
|
90
|
+
end
|
88
91
|
end
|
89
92
|
|
90
93
|
#Card decline
|
@@ -106,6 +109,8 @@ module Beanstream
|
|
106
109
|
:complete => true
|
107
110
|
}
|
108
111
|
})
|
112
|
+
puts "Success! TransactionID: #{result['id']}"
|
113
|
+
|
109
114
|
rescue BeanstreamException => ex
|
110
115
|
decline = true
|
111
116
|
puts "Exception: #{ex.user_facing_message}"
|
@@ -120,36 +125,47 @@ module Beanstream
|
|
120
125
|
#PreAuth card
|
121
126
|
should "have successful credit card pre-auth and completion" do
|
122
127
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
:
|
130
|
-
:
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
128
|
+
decline = false
|
129
|
+
begin
|
130
|
+
result = Beanstream.PaymentsAPI.make_payment(
|
131
|
+
{
|
132
|
+
:order_number => PaymentsAPI.generateRandomOrderId("test"),
|
133
|
+
:amount => 100,
|
134
|
+
:payment_method => PaymentMethods::CARD,
|
135
|
+
:card => {
|
136
|
+
:name => "Mr. Card Testerson",
|
137
|
+
:number => "4030000010001234",
|
138
|
+
:expiry_month => "07",
|
139
|
+
:expiry_year => "22",
|
140
|
+
:cvd => "123",
|
141
|
+
:complete => false
|
142
|
+
}
|
135
143
|
}
|
136
|
-
|
137
|
-
|
138
|
-
|
144
|
+
)
|
145
|
+
puts "result: #{result}"
|
146
|
+
assert(PaymentsAPI.payment_approved(result))
|
147
|
+
transaction_id = result['id']
|
148
|
+
puts "TransactionId: #{transaction_id}"
|
149
|
+
|
150
|
+
result = Beanstream.PaymentsAPI.complete_preauth(transaction_id, 59.50)
|
151
|
+
puts "completion result: #{result}"
|
152
|
+
assert(PaymentsAPI.payment_approved(result))
|
139
153
|
|
140
|
-
|
141
|
-
|
142
|
-
|
154
|
+
rescue BeanstreamException => ex
|
155
|
+
decline = true
|
156
|
+
puts "Exception: #{ex.user_facing_message}"
|
157
|
+
assert(ex.user_facing_message == "DECLINE")
|
158
|
+
assert(ex.is_user_error())
|
159
|
+
end
|
160
|
+
|
161
|
+
assert(!decline)
|
143
162
|
|
144
|
-
result = Beanstream.PaymentsAPI.complete_preauth(transaction_id, 59.50)
|
145
|
-
puts "completion result: #{result}"
|
146
|
-
assert(PaymentsAPI.payment_approved(result))
|
147
163
|
end
|
148
164
|
|
149
165
|
#PreAuth token
|
150
166
|
should "pre-auth and complete successfully with a legato token" do
|
151
167
|
|
152
|
-
# 1) get token
|
168
|
+
# 1) get token (this is normally done in the client app)
|
153
169
|
token = Beanstream.PaymentsAPI.get_legato_token(
|
154
170
|
{
|
155
171
|
:number => "4030000010001234",
|
@@ -162,26 +178,31 @@ module Beanstream
|
|
162
178
|
assert(token != nil)
|
163
179
|
|
164
180
|
# 2) make pre-auth
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
:
|
172
|
-
|
173
|
-
|
181
|
+
begin
|
182
|
+
result = Beanstream.PaymentsAPI.make_payment(
|
183
|
+
{
|
184
|
+
:order_number => PaymentsAPI.generateRandomOrderId("test"),
|
185
|
+
:amount => 13.99,
|
186
|
+
:payment_method => PaymentMethods::TOKEN,
|
187
|
+
:token => {
|
188
|
+
:name => "Bobby Test",
|
189
|
+
:code => token,
|
190
|
+
:complete => false
|
191
|
+
}
|
174
192
|
}
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
transaction_id = result['id']
|
193
|
+
)
|
194
|
+
puts "result: #{result}"
|
195
|
+
assert(PaymentsAPI.payment_approved(result))
|
196
|
+
transaction_id = result['id']
|
180
197
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
198
|
+
# 3) complete purchase
|
199
|
+
result = Beanstream.PaymentsAPI.complete_preauth(transaction_id, 10.33)
|
200
|
+
puts "completion result: #{result}"
|
201
|
+
assert(PaymentsAPI.payment_approved(result))
|
202
|
+
rescue BeanstreamException => ex
|
203
|
+
puts "card declined"
|
204
|
+
assert(false)
|
205
|
+
end
|
185
206
|
end
|
186
207
|
|
187
208
|
#Return
|
@@ -63,31 +63,70 @@ module Beanstream
|
|
63
63
|
|
64
64
|
end
|
65
65
|
|
66
|
-
# Profile CREATE
|
67
|
-
should "have successfully created a profile" do
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
:billing
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
66
|
+
# Profile CREATE with CARD
|
67
|
+
should "have successfully created a profile with credit card" do
|
68
|
+
|
69
|
+
begin
|
70
|
+
profile = Beanstream.ProfilesAPI.getCreateProfileWithCardTemplate()
|
71
|
+
profile[:card][:name] = "Bob Test"
|
72
|
+
profile[:card][:number] = "4030000010001234"
|
73
|
+
profile[:card][:expiry_month] ="07"
|
74
|
+
profile[:card][:expiry_year] = "22"
|
75
|
+
profile[:card][:cvd] = "123"
|
76
|
+
profile[:billing][:name] = "Bob Test"
|
77
|
+
profile[:billing][:address_line1] = "123 Fake St."
|
78
|
+
profile[:billing][:city] = "Victoria"
|
79
|
+
profile[:billing][:province] = "BC"
|
80
|
+
profile[:billing][:country] = "CA"
|
81
|
+
profile[:billing][:postal_code] = "v1v2v2"
|
82
|
+
profile[:billing][:phone_number] = "12505551234"
|
83
|
+
profile[:billing][:email_address] = "fake@example.com"
|
84
|
+
|
85
|
+
result = Beanstream.ProfilesAPI.create_profile(profile)
|
86
|
+
|
87
|
+
assert(ProfilesAPI.profile_successfully_created(result))
|
88
|
+
profile_id = result['customer_code']
|
89
|
+
puts "Created profile with ID: #{profile_id}"
|
90
|
+
rescue BeanstreamException => ex
|
91
|
+
assert(false)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Profile CREATE with TOKEN
|
96
|
+
should "have successfully created a profile with token" do
|
97
|
+
|
98
|
+
begin
|
99
|
+
token = Beanstream.PaymentsAPI.get_legato_token(
|
100
|
+
{
|
101
|
+
:number => "4030000010001234",
|
102
|
+
:expiry_month => "07",
|
103
|
+
:expiry_year => "22",
|
104
|
+
:cvd => "123"
|
105
|
+
}
|
106
|
+
)
|
107
|
+
puts "token result: #{token}"
|
108
|
+
assert(token != nil)
|
109
|
+
|
110
|
+
profile = Beanstream.ProfilesAPI.getCreateProfileWithTokenTemplate()
|
111
|
+
profile[:token][:name] = "Bob Test"
|
112
|
+
profile[:token][:code] = token
|
113
|
+
profile[:billing][:name] = "Bob Test"
|
114
|
+
profile[:billing][:address_line1] = "123 Fake St."
|
115
|
+
profile[:billing][:city] = "Victoria"
|
116
|
+
profile[:billing][:province] = "BC"
|
117
|
+
profile[:billing][:country] = "CA"
|
118
|
+
profile[:billing][:postal_code] = "v1v2v2"
|
119
|
+
profile[:billing][:phone_number] = "12505551234"
|
120
|
+
profile[:billing][:email_address] = "fake@example.com"
|
121
|
+
|
122
|
+
result = Beanstream.ProfilesAPI.create_profile(profile)
|
123
|
+
|
124
|
+
assert(ProfilesAPI.profile_successfully_created(result))
|
125
|
+
profile_id = result['customer_code']
|
126
|
+
puts "Created profile with ID: #{profile_id}"
|
127
|
+
rescue BeanstreamException => ex
|
128
|
+
assert(false)
|
129
|
+
end
|
91
130
|
end
|
92
131
|
|
93
132
|
# Profile DELETE
|
@@ -257,5 +296,68 @@ module Beanstream
|
|
257
296
|
delete_card = Beanstream.ProfilesAPI.delete_profile_card(@profile,1)
|
258
297
|
assert(delete_card['message']== 'Operation Successful')
|
259
298
|
end
|
299
|
+
|
300
|
+
# Profile PAYMENT and PRE_AUTH
|
301
|
+
should "have successfully made payments with a profile" do
|
302
|
+
|
303
|
+
profile_id = ""
|
304
|
+
begin
|
305
|
+
result = Beanstream.ProfilesAPI.create_profile(
|
306
|
+
{
|
307
|
+
:card => {
|
308
|
+
:name => "Bob Test",
|
309
|
+
:number => "4030000010001234",
|
310
|
+
:expiry_month => "07",
|
311
|
+
:expiry_year => "22",
|
312
|
+
:cvd => "123"
|
313
|
+
},
|
314
|
+
:billing => {
|
315
|
+
:name => "Bob Test",
|
316
|
+
:address_line1 => "123 Fake St.",
|
317
|
+
:city => "Victoria",
|
318
|
+
:province => "BC",
|
319
|
+
:country => "CA",
|
320
|
+
:postal_code => "v1v2v2",
|
321
|
+
:phone_number => "12505551234",
|
322
|
+
:email_address => "fake@example.com"
|
323
|
+
}
|
324
|
+
})
|
325
|
+
assert(ProfilesAPI.profile_successfully_created(result))
|
326
|
+
profile_id = result['customer_code']
|
327
|
+
puts "Created profile with ID: #{profile_id}"
|
328
|
+
rescue BeanstreamException => ex
|
329
|
+
puts "Error: #{ex.user_facing_message()}"
|
330
|
+
assert(false)
|
331
|
+
end
|
332
|
+
|
333
|
+
begin
|
334
|
+
# payment
|
335
|
+
profile_payment = Beanstream.PaymentsAPI.getProfilePaymentRequestTemplate()
|
336
|
+
profile_payment[:payment_profile][:customer_code] = profile_id
|
337
|
+
profile_payment[:amount] = 77.50
|
338
|
+
result = Beanstream.PaymentsAPI.make_payment(profile_payment)
|
339
|
+
rescue BeanstreamException => ex
|
340
|
+
puts "Error: #{ex.user_facing_message()}"
|
341
|
+
assert(false) #declined
|
342
|
+
end
|
343
|
+
|
344
|
+
begin
|
345
|
+
# pre-auth
|
346
|
+
profile_payment = Beanstream.PaymentsAPI.getProfilePaymentRequestTemplate()
|
347
|
+
profile_payment[:amount] = 80
|
348
|
+
profile_payment[:payment_profile][:customer_code] = profile_id
|
349
|
+
profile_payment[:payment_profile][:complete] = false #false for pre-auth
|
350
|
+
result = Beanstream.PaymentsAPI.make_payment(profile_payment)
|
351
|
+
|
352
|
+
#complete pre-auth
|
353
|
+
result = Beanstream.PaymentsAPI.complete_preauth(result['id'], 40.50)
|
354
|
+
puts "completion result: #{result}"
|
355
|
+
assert(PaymentsAPI.payment_approved(result))
|
356
|
+
rescue BeanstreamException => ex
|
357
|
+
puts "Error: #{ex.user_facing_message()}"
|
358
|
+
assert(false) #declined
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
260
362
|
end
|
261
363
|
end
|
@@ -6,13 +6,11 @@ module Beanstream
|
|
6
6
|
|
7
7
|
class ReportingAPITest < Test::Unit::TestCase
|
8
8
|
|
9
|
-
=begin
|
10
9
|
setup do
|
11
10
|
Beanstream.merchant_id = "300200578"
|
12
11
|
Beanstream.payments_api_key = "4BaD82D9197b4cc4b70a221911eE9f70"
|
13
12
|
Beanstream.reporting_api_key = "4e6Ff318bee64EA391609de89aD4CF5d"
|
14
13
|
end
|
15
|
-
=end
|
16
14
|
|
17
15
|
should "make reports url be the same" do
|
18
16
|
assert_equal("/api/v1/reports", ReportingAPI.new.reports_url())
|
@@ -21,11 +19,14 @@ module Beanstream
|
|
21
19
|
end
|
22
20
|
|
23
21
|
class ReportingAPIIntegrationTest < Test::Unit::TestCase
|
24
|
-
|
25
|
-
|
22
|
+
|
23
|
+
setup do
|
26
24
|
Beanstream.merchant_id = "300200578"
|
27
25
|
Beanstream.payments_api_key = "4BaD82D9197b4cc4b70a221911eE9f70"
|
28
26
|
Beanstream.reporting_api_key = "4e6Ff318bee64EA391609de89aD4CF5d"
|
27
|
+
end
|
28
|
+
|
29
|
+
should "have successfully found my payments" do
|
29
30
|
|
30
31
|
prefix = SecureRandom.hex(4)
|
31
32
|
#prepare a payment
|
@@ -79,9 +80,17 @@ module Beanstream
|
|
79
80
|
|
80
81
|
|
81
82
|
#find transaction 1 from order number
|
82
|
-
results = Beanstream.ReportingAPI.search_transactions(
|
83
|
-
|
84
|
-
|
83
|
+
results = Beanstream.ReportingAPI.search_transactions(
|
84
|
+
last3Hours,
|
85
|
+
next3Hours,
|
86
|
+
1,
|
87
|
+
10,
|
88
|
+
Criteria.new(
|
89
|
+
Fields::OrderNumber,
|
90
|
+
Operators::EQUALS,
|
91
|
+
orderNum1
|
92
|
+
)
|
93
|
+
)
|
85
94
|
assert(results != nil)
|
86
95
|
puts "Report search by order number\n: #{results}"
|
87
96
|
assert(results.length == 1, "Found #{results.length} instead")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beanstream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brent Owens
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-08-
|
13
|
+
date: 2015-08-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest-client
|