1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nexy\PayboxDirect; |
4
|
|
|
|
5
|
|
|
use Nexy\PayboxDirect\HttpClient\AbstractHttpClient; |
6
|
|
|
use Nexy\PayboxDirect\HttpClient\GuzzleHttpClient; |
7
|
|
|
use Nexy\PayboxDirect\OptionsResolver\OptionsResolver; |
8
|
|
|
use Nexy\PayboxDirect\Request\RequestInterface; |
9
|
|
|
use Nexy\PayboxDirect\Response\PayboxResponse; |
10
|
|
|
use Nexy\PayboxDirect\Variable\Activity; |
11
|
|
|
use Nexy\PayboxDirect\Variable\Currency; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @author Sullivan Senechal <[email protected]> |
15
|
|
|
* |
16
|
|
|
* @see http://www1.paybox.com/espace-integrateur-documentation/les-solutions-paybox-direct-et-paybox-direct-plus/les-operations-de-caisse-direct-plus/ |
17
|
|
|
* @see http://www1.paybox.com/espace-integrateur-documentation/dictionnaire-des-donnees/paybox-direct-et-direct-plus/ |
18
|
|
|
* |
19
|
|
|
* @method PayboxResponse authorize(array $parameters) |
20
|
|
|
* @method PayboxResponse debit(array $parameters) |
21
|
|
|
* @method PayboxResponse authorizeAndCapture(array $parameters) |
22
|
|
|
* @method PayboxResponse credit(array $parameters) |
23
|
|
|
* @method PayboxResponse cancel(array $parameters) |
24
|
|
|
* @method PayboxResponse check(array $parameters) |
25
|
|
|
* @method PayboxResponse transact(array $parameters) |
26
|
|
|
* @method PayboxResponse updateAmount(array $parameters) |
27
|
|
|
* @method PayboxResponse refund(array $parameters) |
28
|
|
|
* @method PayboxResponse inquiry(array $parameters) |
29
|
|
|
* @method PayboxResponse authorizeSubscriber(array $parameters) |
30
|
|
|
* @method PayboxResponse debitSubscriber(array $parameters) |
31
|
|
|
* @method PayboxResponse authorizeAndCaptureSubscriber(array $parameters) |
32
|
|
|
* @method PayboxResponse creditSubscriber(array $parameters) |
33
|
|
|
* @method PayboxResponse cancelSubscriberTransaction(array $parameters) |
34
|
|
|
* @method PayboxResponse registerSubscriber(array $parameters) |
35
|
|
|
* @method PayboxResponse updateSubscriber(array $parameters) |
36
|
|
|
* @method PayboxResponse deleteSubscriber(array $parameters) |
37
|
|
|
* @method PayboxResponse transactSubscriber(array $parameters) |
38
|
|
|
*/ |
39
|
|
|
final class Paybox |
40
|
|
|
{ |
41
|
|
|
const VERSION_DIRECT = '00103'; |
42
|
|
|
const VERSION_DIRECT_PLUS = '00104'; |
43
|
|
|
|
44
|
|
|
const VERSIONS = [ |
45
|
|
|
'direct' => self::VERSION_DIRECT, |
46
|
|
|
'direct_plus' => self::VERSION_DIRECT_PLUS, |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
const API_URL_PRODUCTION = 'https://ppps.paybox.com/PPPS.php'; |
50
|
|
|
const API_URL_RESCUE = 'https://ppps1.paybox.com/PPPS.php'; |
51
|
|
|
const API_URL_TEST = 'https://preprod-ppps.paybox.com/PPPS.php'; |
52
|
|
|
|
53
|
|
|
// TODO: Remove it |
54
|
|
|
private static $operations = [ |
55
|
|
|
'authorize' => [ |
56
|
|
|
'code' => '00001', |
57
|
|
|
'parameters' => [ |
58
|
|
|
'defined' => [ |
59
|
|
|
'AUTORISATION', |
60
|
|
|
], |
61
|
|
|
'defaults' => [ |
62
|
|
|
'DEVISE' => null, |
63
|
|
|
], |
64
|
|
|
'required' => [ |
65
|
|
|
'DATEVAL', |
66
|
|
|
'MONTANT', |
67
|
|
|
'PORTEUR', |
68
|
|
|
'REFERENCE', |
69
|
|
|
], |
70
|
|
|
], |
71
|
|
|
], |
72
|
|
|
'debit' => [ |
73
|
|
|
'code' => '00002', |
74
|
|
|
'parameters' => [ |
75
|
|
|
'defaults' => [ |
76
|
|
|
'DEVISE' => null, |
77
|
|
|
], |
78
|
|
|
'required' => [ |
79
|
|
|
'MONTANT', |
80
|
|
|
'NUMAPPEL', |
81
|
|
|
'NUMTRANS', |
82
|
|
|
'REFERENCE', |
83
|
|
|
], |
84
|
|
|
], |
85
|
|
|
], |
86
|
|
|
'authorizeAndCapture' => [ |
87
|
|
|
'code' => '00003', |
88
|
|
|
'parameters' => [ |
89
|
|
|
'defined' => [ |
90
|
|
|
'AUTORISATION', |
91
|
|
|
], |
92
|
|
|
'defaults' => [ |
93
|
|
|
'DEVISE' => null, |
94
|
|
|
], |
95
|
|
|
'required' => [ |
96
|
|
|
'DATEVAL', |
97
|
|
|
'MONTANT', |
98
|
|
|
'PORTEUR', |
99
|
|
|
'REFERENCE', |
100
|
|
|
], |
101
|
|
|
], |
102
|
|
|
], |
103
|
|
|
'credit' => [ |
104
|
|
|
'code' => '00004', |
105
|
|
|
'parameters' => [ |
106
|
|
|
'defaults' => [ |
107
|
|
|
'DEVISE' => null, |
108
|
|
|
], |
109
|
|
|
'required' => [ |
110
|
|
|
'DATEVAL', |
111
|
|
|
'MONTANT', |
112
|
|
|
'PORTEUR', |
113
|
|
|
'REFERENCE', |
114
|
|
|
], |
115
|
|
|
], |
116
|
|
|
], |
117
|
|
|
'cancel' => [ |
118
|
|
|
'code' => '00005', |
119
|
|
|
'parameters' => [ |
120
|
|
|
'defaults' => [ |
121
|
|
|
'DEVISE' => null, |
122
|
|
|
], |
123
|
|
|
'required' => [ |
124
|
|
|
'MONTANT', |
125
|
|
|
'NUMAPPEL', |
126
|
|
|
'NUMTRANSL', |
127
|
|
|
'REFERENCE', |
128
|
|
|
], |
129
|
|
|
], |
130
|
|
|
], |
131
|
|
|
'check' => [ |
132
|
|
|
'code' => '00011', |
133
|
|
|
'parameters' => [ |
134
|
|
|
'defaults' => [ |
135
|
|
|
'DEVISE' => null, |
136
|
|
|
], |
137
|
|
|
'required' => [ |
138
|
|
|
'MONTANT', |
139
|
|
|
'REFERENCE', |
140
|
|
|
], |
141
|
|
|
], |
142
|
|
|
], |
143
|
|
|
'transact' => [ |
144
|
|
|
'code' => '00012', |
145
|
|
|
'parameters' => [ |
146
|
|
|
'defaults' => [ |
147
|
|
|
'DEVISE' => null, |
148
|
|
|
], |
149
|
|
|
'required' => [ |
150
|
|
|
'DATEVAL', |
151
|
|
|
'MONTANT', |
152
|
|
|
'PORTEUR', |
153
|
|
|
'REFERENCE', |
154
|
|
|
], |
155
|
|
|
], |
156
|
|
|
], |
157
|
|
|
'updateAmount' => [ |
158
|
|
|
'code' => '00013', |
159
|
|
|
'parameters' => [ |
160
|
|
|
'defined' => [ |
161
|
|
|
'AUTORISATION', |
162
|
|
|
], |
163
|
|
|
'defaults' => [ |
164
|
|
|
'DEVISE' => null, |
165
|
|
|
], |
166
|
|
|
'required' => [ |
167
|
|
|
'MONTANT', |
168
|
|
|
'NUMAPPEL', |
169
|
|
|
'NUMTRANS', |
170
|
|
|
], |
171
|
|
|
], |
172
|
|
|
], |
173
|
|
|
'refund' => [ |
174
|
|
|
'code' => '00014', |
175
|
|
|
'parameters' => [ |
176
|
|
|
'defaults' => [ |
177
|
|
|
'DEVISE' => null, |
178
|
|
|
], |
179
|
|
|
'required' => [ |
180
|
|
|
'MONTANT', |
181
|
|
|
'NUMAPPEL', |
182
|
|
|
'NUMTRANS', |
183
|
|
|
], |
184
|
|
|
], |
185
|
|
|
], |
186
|
|
|
'inquiry' => [ |
187
|
|
|
'code' => '00017', |
188
|
|
|
'parameters' => [ |
189
|
|
|
'required' => [ |
190
|
|
|
'NUMTRANS', |
191
|
|
|
], |
192
|
|
|
], |
193
|
|
|
], |
194
|
|
|
'authorizeSubscriber' => [ |
195
|
|
|
'code' => '00051', |
196
|
|
|
'parameters' => [ |
197
|
|
|
'defined' => [ |
198
|
|
|
'AUTORISATION', |
199
|
|
|
], |
200
|
|
|
'defaults' => [ |
201
|
|
|
'DEVISE' => null, |
202
|
|
|
], |
203
|
|
|
'required' => [ |
204
|
|
|
'DATEVAL', |
205
|
|
|
'PORTEUR', |
206
|
|
|
'REFABONNE', |
207
|
|
|
'REFERENCE', |
208
|
|
|
], |
209
|
|
|
], |
210
|
|
|
], |
211
|
|
|
'debitSubscriber' => [ |
212
|
|
|
'code' => '00052', |
213
|
|
|
'parameters' => [ |
214
|
|
|
'defaults' => [ |
215
|
|
|
'DEVISE' => null, |
216
|
|
|
], |
217
|
|
|
'required' => [ |
218
|
|
|
'MONTANT', |
219
|
|
|
'NUMAPPEL', |
220
|
|
|
'NUMTRANS', |
221
|
|
|
'REFERENCE', |
222
|
|
|
], |
223
|
|
|
], |
224
|
|
|
], |
225
|
|
|
'authorizeAndCaptureSubscriber' => [ |
226
|
|
|
'code' => '00053', |
227
|
|
|
'parameters' => [ |
228
|
|
|
'defaults' => [ |
229
|
|
|
'DEVISE' => null, |
230
|
|
|
], |
231
|
|
|
'required' => [ |
232
|
|
|
'DATEVAL', |
233
|
|
|
'MONTANT', |
234
|
|
|
'PORTEUR', |
235
|
|
|
'REFABONNE', |
236
|
|
|
'REFERENCE', |
237
|
|
|
], |
238
|
|
|
], |
239
|
|
|
], |
240
|
|
|
'creditSubscriber' => [ |
241
|
|
|
'code' => '00054', |
242
|
|
|
'parameters' => [ |
243
|
|
|
'defaults' => [ |
244
|
|
|
'DEVISE' => null, |
245
|
|
|
], |
246
|
|
|
'required' => [ |
247
|
|
|
'DATEVAL', |
248
|
|
|
'MONTANT', |
249
|
|
|
'PORTEUR', |
250
|
|
|
'REFABONNE', |
251
|
|
|
'REFERENCE', |
252
|
|
|
], |
253
|
|
|
], |
254
|
|
|
], |
255
|
|
|
'cancelSubscriberTransaction' => [ |
256
|
|
|
'code' => '00055', |
257
|
|
|
'parameters' => [ |
258
|
|
|
'defaults' => [ |
259
|
|
|
'DEVISE' => null, |
260
|
|
|
], |
261
|
|
|
'required' => [ |
262
|
|
|
'DATEVAL', |
263
|
|
|
'MONTANT', |
264
|
|
|
'NUMAPPEL', |
265
|
|
|
'NUMTRANS', |
266
|
|
|
'PORTEUR', |
267
|
|
|
'REFABONNE', |
268
|
|
|
'REFERENCE', |
269
|
|
|
], |
270
|
|
|
], |
271
|
|
|
], |
272
|
|
|
'registerSubscriber' => [ |
273
|
|
|
'code' => '00056', |
274
|
|
|
'parameters' => [ |
275
|
|
|
'defaults' => [ |
276
|
|
|
'DEVISE' => null, |
277
|
|
|
], |
278
|
|
|
'defined' => [ |
279
|
|
|
'AUTORISATION', |
280
|
|
|
], |
281
|
|
|
'required' => [ |
282
|
|
|
'DATEVAL', |
283
|
|
|
'MONTANT', |
284
|
|
|
'PORTEUR', |
285
|
|
|
'REFABONNE', |
286
|
|
|
'REFERENCE', |
287
|
|
|
], |
288
|
|
|
], |
289
|
|
|
], |
290
|
|
|
'updateSubscriber' => [ |
291
|
|
|
'code' => '00057', |
292
|
|
|
'parameters' => [ |
293
|
|
|
'defaults' => [ |
294
|
|
|
'DEVISE' => null, |
295
|
|
|
], |
296
|
|
|
'defined' => [ |
297
|
|
|
'AUTORISATION', |
298
|
|
|
], |
299
|
|
|
'required' => [ |
300
|
|
|
'DATEVAL', |
301
|
|
|
'MONTANT', |
302
|
|
|
'PORTEUR', |
303
|
|
|
'REFABONNE', |
304
|
|
|
], |
305
|
|
|
], |
306
|
|
|
], |
307
|
|
|
'deleteSubscriber' => [ |
308
|
|
|
'code' => '00058', |
309
|
|
|
'parameters' => [ |
310
|
|
|
'required' => [ |
311
|
|
|
'REFABONNE', |
312
|
|
|
], |
313
|
|
|
], |
314
|
|
|
], |
315
|
|
|
'transactSubscriber' => [ |
316
|
|
|
'code' => '00061', |
317
|
|
|
'parameters' => [ |
318
|
|
|
'defaults' => [ |
319
|
|
|
'DEVISE' => null, |
320
|
|
|
], |
321
|
|
|
'required' => [ |
322
|
|
|
'DATEVAL', |
323
|
|
|
'MONTANT', |
324
|
|
|
'PORTEUR', |
325
|
|
|
'REFABONNE', |
326
|
|
|
'REFERENCE', |
327
|
|
|
], |
328
|
|
|
], |
329
|
|
|
], |
330
|
|
|
]; |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* @var AbstractHttpClient |
334
|
|
|
*/ |
335
|
|
|
private $httpClient; |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* @var array |
339
|
|
|
*/ |
340
|
|
|
private $options; |
341
|
|
|
|
342
|
|
|
public function __construct(array $options = [], AbstractHttpClient $httpClient = null) |
343
|
|
|
{ |
344
|
|
|
$resolver = new OptionsResolver(); |
345
|
|
|
$this->configureOptions($resolver); |
346
|
|
|
|
347
|
|
|
$this->options = $resolver->resolve($options); |
348
|
|
|
|
349
|
|
|
$this->httpClient = $httpClient ? $httpClient : new GuzzleHttpClient(); |
350
|
|
|
$this->httpClient->setOptions($this->options); |
351
|
|
|
$this->httpClient->init(); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* @param RequestInterface $request |
356
|
|
|
* |
357
|
|
|
* @return PayboxResponse |
358
|
|
|
* |
359
|
|
|
* @throws Exception\PayboxException |
360
|
|
|
*/ |
361
|
|
|
public function request(RequestInterface $request) |
362
|
|
|
{ |
363
|
|
|
return $this->httpClient->call( |
364
|
|
|
$request->getRequestId(), |
365
|
|
|
$this->resolveRequestParameters($request->getParameters()) |
366
|
|
|
); |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* Paybox base options validation. |
371
|
|
|
* |
372
|
|
|
* @param OptionsResolver $resolver |
373
|
|
|
*/ |
374
|
|
|
private function configureOptions(OptionsResolver $resolver) |
375
|
|
|
{ |
376
|
|
|
$resolver->setDefaults([ |
377
|
|
|
'timeout' => 10, |
378
|
|
|
'production' => false, |
379
|
|
|
'paybox_default_currency' => Currency::EURO, |
380
|
|
|
]); |
381
|
|
|
$resolver->setRequired([ |
382
|
|
|
'paybox_version', // Paybox Direct Plus protocol |
383
|
|
|
'paybox_site', |
384
|
|
|
'paybox_rank', |
385
|
|
|
'paybox_identifier', |
386
|
|
|
'paybox_key', |
387
|
|
|
]); |
388
|
|
|
|
389
|
|
|
$resolver->setAllowedTypes('timeout', 'int'); |
390
|
|
|
$resolver->setAllowedTypes('production', 'bool'); |
391
|
|
|
$resolver->setAllowedTypes('paybox_version', 'string'); |
392
|
|
|
$resolver->setAllowedTypes('paybox_default_currency', 'int'); |
393
|
|
|
$resolver->setAllowedTypes('paybox_site', 'string'); |
394
|
|
|
$resolver->setAllowedTypes('paybox_rank', 'string'); |
395
|
|
|
$resolver->setAllowedTypes('paybox_identifier', 'string'); |
396
|
|
|
$resolver->setAllowedTypes('paybox_key', 'string'); |
397
|
|
|
|
398
|
|
|
$resolver->setAllowedValues('paybox_version', static::VERSIONS); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* Paybox request paramaters validation. |
403
|
|
|
* |
404
|
|
|
* @param array $parameters |
405
|
|
|
* |
406
|
|
|
* @return array |
407
|
|
|
*/ |
408
|
|
|
private function resolveRequestParameters(array $parameters) |
409
|
|
|
{ |
410
|
|
|
$resolver = new OptionsResolver(); |
411
|
|
|
|
412
|
|
|
// Defines parameters keys to enable them. |
413
|
|
|
foreach (array_keys($parameters) as $key) { |
414
|
|
|
$resolver->setDefined($key); |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
$resolver |
|
|
|
|
418
|
|
|
->setAllowedTypesIfDefined('ACQUEREUR', 'string') |
419
|
|
|
->setAllowedTypesIfDefined('ACTIVITE', 'int') |
420
|
|
|
->setAllowedTypesIfDefined('ARCHIVAGE', 'string') |
421
|
|
|
->setAllowedTypesIfDefined('AUTORISATION', 'string') |
422
|
|
|
->setAllowedTypesIfDefined('CVV', 'string') |
423
|
|
|
->setAllowedTypesIfDefined('DATENAISS', 'string') |
424
|
|
|
->setAllowedTypesIfDefined('DATEQ', ['string', 'null']) |
425
|
|
|
->setAllowedTypesIfDefined('DATEVAL', 'string') |
426
|
|
|
->setAllowedTypesIfDefined('DEVISE', ['int', 'null']) |
427
|
|
|
->setAllowedTypesIfDefined('DIFFERE', 'int') |
428
|
|
|
->setAllowedTypesIfDefined('ERRORCODETEST', 'int') |
429
|
|
|
->setAllowedTypesIfDefined('ID3D', 'string') |
430
|
|
|
->setAllowedTypesIfDefined('MONTANT', 'int') |
431
|
|
|
->setAllowedTypesIfDefined('NUMAPPEL', 'int') |
432
|
|
|
->setAllowedTypesIfDefined('NUMTRANS', 'int') |
433
|
|
|
->setAllowedTypesIfDefined('PORTEUR', 'string') |
434
|
|
|
->setAllowedTypesIfDefined('PRIV_CODETRAITEMENT', 'string') |
435
|
|
|
->setAllowedTypesIfDefined('REFABONNE', 'string') |
436
|
|
|
->setAllowedTypesIfDefined('REFERENCE', 'string') // TODO: Auto-generated if not provided? |
437
|
|
|
; |
438
|
|
|
|
439
|
|
|
$resolver |
|
|
|
|
440
|
|
|
->setAllowedValuesIfDefined('ACQUEREUR', ['PAYPAL', 'EMS', 'ATOSBE', 'BCMC', 'PSC', 'FINAREF', 'BUYSTER', '34ONEY']) |
441
|
|
|
->setAllowedValuesIfDefined('ACTIVITE', [ |
442
|
|
|
Activity::NOT_SPECIFIED, |
443
|
|
|
Activity::PHONE_REQUEST, |
444
|
|
|
Activity::MAIL_REQUEST, |
445
|
|
|
Activity::MINITEL_REQUEST, |
446
|
|
|
Activity::WEB_REQUEST, |
447
|
|
|
Activity::RECURRING_PAYMENT, |
448
|
|
|
]) |
449
|
|
|
->setAllowedValuesIfDefined('DEVISE', [ |
450
|
|
|
null, |
451
|
|
|
Currency::EURO, |
452
|
|
|
Currency::US_DOLLAR, |
453
|
|
|
Currency::CFA, |
454
|
|
|
]) |
455
|
|
|
->setAllowedValuesIfDefined('PAYS', '') |
456
|
|
|
->setAllowedValuesIfDefined('SHA-1', '') |
457
|
|
|
->setAllowedValuesIfDefined('TYPECARTE', '') |
458
|
|
|
; |
459
|
|
|
|
460
|
|
|
return $resolver->resolve($parameters); |
461
|
|
|
} |
462
|
|
|
} |
463
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.