paybox_direct 0.1.2 → 0.1.3
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/lib/paybox_direct/exceptions.rb +12 -6
- data/lib/paybox_direct/request.rb +5 -0
- data/lib/paybox_direct.rb +10 -10
- data/spec/paybox_direct_spec.rb +153 -14
- 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: d6998f735f27720f3c35bc55f6723eb342664d86
|
4
|
+
data.tar.gz: bd26cf6c73b72f96b1748664d2fa60e13aaa1157
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e0ef292152cb66d1da4b74d6c4227dd13c8635a1e287e84ccf9c36ea06d3e4ab72c8943ef17109b4208b828283e8876e224ba9f916c8ce8a3931c75b73303cc
|
7
|
+
data.tar.gz: c9ad2b64d51e8c5aeb08a8674fe97a6dbc1bd9a65369ec91525b95bb13eff29e30fa12d24d4f384ea2b4ef012f597cb7f7701320332688f7bedecded9e11f65e
|
@@ -3,14 +3,20 @@
|
|
3
3
|
# This library is licensed under the new BSD license. Checkout the license text
|
4
4
|
# in the LICENSE file or online at <http://opensource.org/licenses/BSD-3-Clause>.
|
5
5
|
|
6
|
-
|
6
|
+
module PayboxDirect
|
7
7
|
class PayboxRequestError < StandardError
|
8
|
-
attr_reader :code, :comment
|
8
|
+
attr_reader :request, :request_id, :code, :comment
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
|
12
|
-
@
|
13
|
-
@
|
10
|
+
def initialize(request)
|
11
|
+
@request = request
|
12
|
+
@request_id = request.request_id
|
13
|
+
@code = request.error_code
|
14
|
+
@comment = request.error_comment
|
15
|
+
super("#{@code.to_s.rjust(5, "0")}: #{@comment} (req. ##{@request_id})")
|
16
|
+
end
|
17
|
+
|
18
|
+
def may_retry?
|
19
|
+
return [105, 151, 157].include? @code
|
14
20
|
end
|
15
21
|
end
|
16
22
|
|
@@ -63,6 +63,11 @@ class PayboxDirect::Request
|
|
63
63
|
return @fields["CODEREPONSE"] != "00000"
|
64
64
|
end
|
65
65
|
|
66
|
+
def request_id
|
67
|
+
raise "Not executed yet" if @fields.nil?
|
68
|
+
return @fields["NUMAPPEL"].to_i
|
69
|
+
end
|
70
|
+
|
66
71
|
def error_code
|
67
72
|
raise "Not executed yet" if @fields.nil?
|
68
73
|
return @fields["CODEREPONSE"].to_i
|
data/lib/paybox_direct.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
require 'ostruct'
|
7
7
|
require 'net/http'
|
8
8
|
|
9
|
-
|
9
|
+
module PayboxDirect
|
10
10
|
DEV_URL = 'https://preprod-ppps.paybox.com/PPPS.php'
|
11
11
|
PROD_URL = 'https://ppps.paybox.com/PPPS.php'
|
12
12
|
PROD_FALLBACK_URL = 'https://ppps1.paybox.com/PPPS.php'
|
@@ -59,7 +59,6 @@ class PayboxDirect
|
|
59
59
|
#
|
60
60
|
# == Returns: (PayboxDirect::Request)
|
61
61
|
# The Paybox request with these response variables:
|
62
|
-
# * request_id: The Paybox request ID (NUMAPPEL)
|
63
62
|
# * transaction_id: The Paybox transaction ID (NUMTRANS)
|
64
63
|
# * wallet: (if new subscription) The created wallet code (PORTEUR)
|
65
64
|
#
|
@@ -108,10 +107,9 @@ class PayboxDirect
|
|
108
107
|
req.execute!
|
109
108
|
|
110
109
|
if req.failed?
|
111
|
-
raise AuthorizationError.new(req
|
110
|
+
raise AuthorizationError.new(req)
|
112
111
|
end
|
113
112
|
req.response = {
|
114
|
-
request_id: req.fields["NUMAPPEL"].to_i,
|
115
113
|
transaction_id: req.fields["NUMTRANS"].to_i,
|
116
114
|
authorization: req.fields["AUTORISATION"] == "XXXXXX" ? nil : req.fields["AUTORISATION"].to_i
|
117
115
|
}
|
@@ -124,7 +122,7 @@ class PayboxDirect
|
|
124
122
|
debit_authorization(
|
125
123
|
amount: opts[:amount],
|
126
124
|
currency: opts[:currency],
|
127
|
-
request_id: req.
|
125
|
+
request_id: req.request_id,
|
128
126
|
transaction_id: req.response[:transaction_id]
|
129
127
|
)
|
130
128
|
end
|
@@ -177,7 +175,7 @@ class PayboxDirect
|
|
177
175
|
req.execute!
|
178
176
|
|
179
177
|
if req.failed?
|
180
|
-
raise DebitError.new(req
|
178
|
+
raise DebitError.new(req)
|
181
179
|
end
|
182
180
|
return req
|
183
181
|
end
|
@@ -245,7 +243,7 @@ class PayboxDirect
|
|
245
243
|
req.execute!
|
246
244
|
|
247
245
|
if req.failed?
|
248
|
-
raise CancelError.new(req
|
246
|
+
raise CancelError.new(req)
|
249
247
|
end
|
250
248
|
return req
|
251
249
|
end
|
@@ -287,7 +285,7 @@ class PayboxDirect
|
|
287
285
|
req.execute!
|
288
286
|
|
289
287
|
if req.failed?
|
290
|
-
raise RefundError.new(req
|
288
|
+
raise RefundError.new(req)
|
291
289
|
end
|
292
290
|
return req
|
293
291
|
end
|
@@ -350,8 +348,10 @@ class PayboxDirect
|
|
350
348
|
req.execute!
|
351
349
|
|
352
350
|
if req.failed?
|
353
|
-
raise CreditError.new(req
|
351
|
+
raise CreditError.new(req)
|
354
352
|
end
|
353
|
+
|
354
|
+
req.response[:transaction_id] = req.fields["NUMTRANS"].to_i
|
355
355
|
return req
|
356
356
|
end
|
357
357
|
|
@@ -377,7 +377,7 @@ class PayboxDirect
|
|
377
377
|
})
|
378
378
|
req.execute!
|
379
379
|
if req.failed?
|
380
|
-
raise DeleteSubscriberError.new(req
|
380
|
+
raise DeleteSubscriberError.new(req)
|
381
381
|
end
|
382
382
|
return req
|
383
383
|
end
|
data/spec/paybox_direct_spec.rb
CHANGED
@@ -42,11 +42,11 @@ RSpec.describe PayboxDirect do
|
|
42
42
|
})
|
43
43
|
|
44
44
|
if DO_CALLS
|
45
|
-
expect(req.
|
45
|
+
expect(req.request_id).to be_a Fixnum
|
46
46
|
expect(req.response[:transaction_id]).to be_a Fixnum
|
47
47
|
expect(req.response[:authorization]).to be_nil
|
48
48
|
else
|
49
|
-
expect(req.
|
49
|
+
expect(req.request_id).to eq 111111
|
50
50
|
expect(req.response[:transaction_id]).to eq 2222222
|
51
51
|
expect(req.response[:authorization]).to eq 444444
|
52
52
|
end
|
@@ -77,12 +77,12 @@ RSpec.describe PayboxDirect do
|
|
77
77
|
})
|
78
78
|
|
79
79
|
if DO_CALLS
|
80
|
-
expect(req.
|
80
|
+
expect(req.request_id).to be_a Fixnum
|
81
81
|
expect(req.response[:transaction_id]).to be_a Fixnum
|
82
82
|
expect(req.response[:authorization]).to be_nil
|
83
83
|
expect(req.response[:wallet]).to eq "CMDLpStLLLs"
|
84
84
|
else
|
85
|
-
expect(req.
|
85
|
+
expect(req.request_id).to eq 111111
|
86
86
|
expect(req.response[:transaction_id]).to eq 2222222
|
87
87
|
expect(req.response[:authorization]).to eq 444444
|
88
88
|
expect(req.response[:wallet]).to eq "my_wallet_code"
|
@@ -129,11 +129,11 @@ RSpec.describe PayboxDirect do
|
|
129
129
|
})
|
130
130
|
|
131
131
|
if DO_CALLS
|
132
|
-
expect(req.
|
132
|
+
expect(req.request_id).to be_a Fixnum
|
133
133
|
expect(req.response[:transaction_id]).to be_a Fixnum
|
134
134
|
expect(req.response[:authorization]).to be_nil
|
135
135
|
else
|
136
|
-
expect(req.
|
136
|
+
expect(req.request_id).to eq 111111
|
137
137
|
expect(req.response[:transaction_id]).to eq 2222222
|
138
138
|
expect(req.response[:authorization]).to eq 444444
|
139
139
|
end
|
@@ -162,11 +162,11 @@ RSpec.describe PayboxDirect do
|
|
162
162
|
})
|
163
163
|
|
164
164
|
if DO_CALLS
|
165
|
-
expect(req.
|
165
|
+
expect(req.request_id).to be_a Fixnum
|
166
166
|
expect(req.response[:transaction_id]).to be_a Fixnum
|
167
167
|
expect(req.response[:authorization]).to be_nil
|
168
168
|
else
|
169
|
-
expect(req.
|
169
|
+
expect(req.request_id).to eq 111111
|
170
170
|
expect(req.response[:transaction_id]).to eq 2222222
|
171
171
|
expect(req.response[:authorization]).to eq 444444
|
172
172
|
end
|
@@ -218,12 +218,12 @@ RSpec.describe PayboxDirect do
|
|
218
218
|
})
|
219
219
|
|
220
220
|
if DO_CALLS
|
221
|
-
expect(req.
|
221
|
+
expect(req.request_id).to be_a Fixnum
|
222
222
|
expect(req.response[:transaction_id]).to be_a Fixnum
|
223
223
|
expect(req.response[:authorization]).to be_nil
|
224
224
|
expect(req.response[:wallet]).to eq "CMDLpStLLLs"
|
225
225
|
else
|
226
|
-
expect(req.
|
226
|
+
expect(req.request_id).to eq 111111
|
227
227
|
expect(req.response[:transaction_id]).to eq 2222222
|
228
228
|
expect(req.response[:authorization]).to eq 444444
|
229
229
|
expect(req.response[:wallet]).to eq "my_wallet_code"
|
@@ -270,11 +270,11 @@ RSpec.describe PayboxDirect do
|
|
270
270
|
})
|
271
271
|
|
272
272
|
if DO_CALLS
|
273
|
-
expect(req.
|
273
|
+
expect(req.request_id).to be_a Fixnum
|
274
274
|
expect(req.response[:transaction_id]).to be_a Fixnum
|
275
275
|
expect(req.response[:authorization]).to be_nil
|
276
276
|
else
|
277
|
-
expect(req.
|
277
|
+
expect(req.request_id).to eq 111111
|
278
278
|
expect(req.response[:transaction_id]).to eq 2222222
|
279
279
|
expect(req.response[:authorization]).to eq 444444
|
280
280
|
end
|
@@ -292,7 +292,7 @@ RSpec.describe PayboxDirect do
|
|
292
292
|
cc_expire: CC_EXPIRE,
|
293
293
|
cc_cvv: CC_CVV
|
294
294
|
)
|
295
|
-
req_id = req.
|
295
|
+
req_id = req.request_id
|
296
296
|
trans_id = req.response[:transaction_id]
|
297
297
|
else
|
298
298
|
req_id = 111111
|
@@ -316,6 +316,66 @@ RSpec.describe PayboxDirect do
|
|
316
316
|
end
|
317
317
|
end
|
318
318
|
|
319
|
+
context "exceptions" do
|
320
|
+
it "raises exception on auth-only failure" do
|
321
|
+
stub_response "CODEREPONSE=00008&COMMENTAIRE=&NUMAPPEL=0000111111"
|
322
|
+
|
323
|
+
expect {
|
324
|
+
PayboxDirect.authorize(
|
325
|
+
ref: "auth_only_failure",
|
326
|
+
amount: 14.29,
|
327
|
+
currency: :EUR,
|
328
|
+
cc_number: CC_NUMBER,
|
329
|
+
cc_expire: CC_EXPIRE,
|
330
|
+
cc_cvv: CC_CVV
|
331
|
+
)
|
332
|
+
}.to raise_error(PayboxDirect::AuthorizationError) do |e|
|
333
|
+
expect(e.request_id).to eq 111111
|
334
|
+
expect(e.code).to eq 8
|
335
|
+
expect(e.comment).to be_a String
|
336
|
+
expect(e.request).to be_a PayboxDirect::Request
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
it "raises exception on debit failure" do
|
341
|
+
stub_response "CODEREPONSE=00008&COMMENTAIRE=&NUMAPPEL=0000111111"
|
342
|
+
|
343
|
+
expect {
|
344
|
+
PayboxDirect.debit(
|
345
|
+
ref: "debit_failure",
|
346
|
+
amount: 50.3,
|
347
|
+
currency: :EUR,
|
348
|
+
cc_number: CC_NUMBER,
|
349
|
+
cc_expire: CC_EXPIRE,
|
350
|
+
cc_cvv: CC_CVV
|
351
|
+
)
|
352
|
+
}.to raise_error(PayboxDirect::AuthorizationError) do |e|
|
353
|
+
expect(e.request_id).to eq 111111
|
354
|
+
expect(e.code).to eq 8
|
355
|
+
expect(e.comment).to be_a String
|
356
|
+
expect(e.request).to be_a PayboxDirect::Request
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
it "raises exception on debit failure on prior auth-only" do
|
361
|
+
stub_response "CODEREPONSE=00008&COMMENTAIRE=&NUMAPPEL=0000111111"
|
362
|
+
|
363
|
+
expect {
|
364
|
+
PayboxDirect.debit_authorization(
|
365
|
+
amount: 18.20,
|
366
|
+
currency: :EUR,
|
367
|
+
request_id: 111111,
|
368
|
+
transaction_id: 2222222
|
369
|
+
)
|
370
|
+
}.to raise_error(PayboxDirect::DebitError) do |e|
|
371
|
+
expect(e.request_id).to eq 111111
|
372
|
+
expect(e.code).to eq 8
|
373
|
+
expect(e.comment).to be_a String
|
374
|
+
expect(e.request).to be_a PayboxDirect::Request
|
375
|
+
end
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
319
379
|
it "should cancel an operation" do
|
320
380
|
stub_response "CODEREPONSE=00000&COMMENTAIRE=" if !DO_CALLS
|
321
381
|
|
@@ -328,7 +388,7 @@ RSpec.describe PayboxDirect do
|
|
328
388
|
cc_expire: CC_EXPIRE,
|
329
389
|
cc_cvv: CC_CVV
|
330
390
|
)
|
331
|
-
req_id = req.
|
391
|
+
req_id = req.request_id
|
332
392
|
trans_id = req.response[:transaction_id]
|
333
393
|
else
|
334
394
|
req_id = 111111
|
@@ -375,4 +435,83 @@ RSpec.describe PayboxDirect do
|
|
375
435
|
"NUMTRANS" => "0002222222"
|
376
436
|
})
|
377
437
|
end
|
438
|
+
|
439
|
+
it "credits a card without subscription" do
|
440
|
+
stub_response "CODEREPONSE=00000&COMMENTAIRE=&NUMAPPEL=0000111111&NUMTRANS=0002222222" if !DO_CALLS
|
441
|
+
|
442
|
+
req = PayboxDirect.credit(
|
443
|
+
ref: "credit",
|
444
|
+
amount: 38.4,
|
445
|
+
currency: :EUR,
|
446
|
+
cc_number: CC_NUMBER,
|
447
|
+
cc_expire: CC_EXPIRE,
|
448
|
+
cc_cvv: CC_CVV
|
449
|
+
)
|
450
|
+
|
451
|
+
expect(req.vars).to include({
|
452
|
+
"TYPE" => "00004",
|
453
|
+
"REFERENCE" => REF_PREFIX + "credit",
|
454
|
+
"MONTANT" => "0000003840",
|
455
|
+
"DEVISE" => "978",
|
456
|
+
"PORTEUR" => CC_NUMBER.gsub("-", ""),
|
457
|
+
"DATEVAL" => CC_EXPIRE.strftime("%m%y"),
|
458
|
+
"CVV" => CC_CVV
|
459
|
+
})
|
460
|
+
|
461
|
+
if DO_CALLS
|
462
|
+
expect(req.request_id).to be_a Fixnum
|
463
|
+
expect(req.response[:transaction_id]).to be_a Fixnum
|
464
|
+
else
|
465
|
+
expect(req.request_id).to eq 111111
|
466
|
+
expect(req.response[:transaction_id]).to eq 2222222
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
it "credits a subscriber" do
|
471
|
+
stub_response "CODEREPONSE=00000&COMMENTAIRE=&NUMAPPEL=0000111111&NUMTRANS=0002222222" if !DO_CALLS
|
472
|
+
|
473
|
+
if DO_CALLS
|
474
|
+
req = PayboxDirect.debit(
|
475
|
+
ref: "credit_subscriber_create",
|
476
|
+
amount: 1,
|
477
|
+
currency: :EUR,
|
478
|
+
cc_number: CC_NUMBER,
|
479
|
+
cc_expire: CC_EXPIRE,
|
480
|
+
cc_cvv: CC_CVV,
|
481
|
+
subscriber: "my_sub_id6"
|
482
|
+
)
|
483
|
+
wallet = req.response[:wallet]
|
484
|
+
else
|
485
|
+
wallet = "my_wallet_code"
|
486
|
+
end
|
487
|
+
|
488
|
+
req = PayboxDirect.credit(
|
489
|
+
ref: "credit_subscriber",
|
490
|
+
amount: 29,
|
491
|
+
currency: :EUR,
|
492
|
+
wallet: wallet,
|
493
|
+
cc_expire: CC_EXPIRE,
|
494
|
+
cc_cvv: CC_CVV,
|
495
|
+
subscriber: "my_sub_id6"
|
496
|
+
)
|
497
|
+
|
498
|
+
expect(req.vars).to include({
|
499
|
+
"TYPE" => "00054",
|
500
|
+
"REFERENCE" => REF_PREFIX + "credit_subscriber",
|
501
|
+
"MONTANT" => "0000002900",
|
502
|
+
"DEVISE" => "978",
|
503
|
+
"PORTEUR" => wallet,
|
504
|
+
"DATEVAL" => CC_EXPIRE.strftime("%m%y"),
|
505
|
+
"CVV" => CC_CVV,
|
506
|
+
"REFABONNE" => REF_PREFIX + "my_sub_id6"
|
507
|
+
})
|
508
|
+
|
509
|
+
if DO_CALLS
|
510
|
+
expect(req.request_id).to be_a Fixnum
|
511
|
+
expect(req.response[:transaction_id]).to be_a Fixnum
|
512
|
+
else
|
513
|
+
expect(req.request_id).to eq 111111
|
514
|
+
expect(req.response[:transaction_id]).to eq 2222222
|
515
|
+
end
|
516
|
+
end
|
378
517
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paybox_direct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kévin Lesénéchal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|