1
- <?php
1
+ <?php /** @noinspection PhpUnusedParameterInspection */
2
2
3
3
namespace Ekyna \Component \Payum \Payzen \Api ;
4
4
@@ -106,7 +106,7 @@ public function createRequestUrl(array $data)
106
106
107
107
$ data = $ this ->createRequestData ($ data );
108
108
109
- $ url = $ this ->getEndpoint () . '? ' .
109
+ $ url = $ this ->getUrl () . '? ' .
110
110
implode ('& ' , array_map (function ($ key , $ value ) {
111
111
return $ key . '= ' . rawurlencode ($ value );
112
112
}, array_keys ($ data ), $ data ));
@@ -178,9 +178,14 @@ public function generateSignature(array $data, $hashed = true)
178
178
$ content .= $ value . '+ ' ;
179
179
}
180
180
}
181
+
181
182
$ content .= $ this ->config ['certificate ' ];
182
183
183
- return $ hashed ? sha1 ($ content ) : $ content ;
184
+ if ($ hashed ) {
185
+ return $ this ->hash ($ content );
186
+ }
187
+
188
+ return $ content ;
184
189
}
185
190
186
191
/**
@@ -200,18 +205,6 @@ private function getDirectoryPath()
200
205
return $ path . DIRECTORY_SEPARATOR ;
201
206
}
202
207
203
- /**
204
- * Returns the endpoint url.
205
- *
206
- * @return string
207
- *
208
- * @throws \Exception
209
- */
210
- private function getEndpoint ()
211
- {
212
- return 'https://paiement.systempay.fr/vads-payment/ ' ;
213
- }
214
-
215
208
/**
216
209
* Check that the API has been configured.
217
210
*
@@ -242,12 +235,16 @@ private function getConfigResolver()
242
235
'certificate ' ,
243
236
'ctx_mode ' ,
244
237
'directory ' ,
245
- 'debug ' ,
238
+ ])
239
+ ->setDefaults ([
240
+ 'endpoint ' => null ,
241
+ 'debug ' => false ,
246
242
])
247
243
->setAllowedTypes ('site_id ' , 'string ' )
248
244
->setAllowedTypes ('certificate ' , 'string ' )
249
245
->setAllowedValues ('ctx_mode ' , ['TEST ' , 'PRODUCTION ' ])
250
246
->setAllowedTypes ('directory ' , 'string ' )
247
+ ->setAllowedValues ('endpoint ' , $ this ->getEndPoints ())
251
248
->setAllowedTypes ('debug ' , 'bool ' )
252
249
->setNormalizer ('directory ' , function (Options $ options , $ value ) {
253
250
return rtrim ($ value , DIRECTORY_SEPARATOR );
@@ -435,21 +432,43 @@ private function getCardsCodes()
435
432
{
436
433
return [
437
434
null ,
438
- 'AMEX ' , // American Express
435
+ 'AMEX ' , // American Express
439
436
'AURORE-MULTI ' , // Aurore
440
- 'BUYSTER ' , // Buyster
441
- 'CB ' , // CB
442
- 'COFINOGA ' , // Cofinoga
437
+ 'BUYSTER ' , // Buyster
438
+ 'CB ' , // CB
439
+ 'COFINOGA ' , // Cofinoga
443
440
'E-CARTEBLEUE ' , // E-Carte bleue
444
- 'MASTERCARD ' , // Eurocard / Mastercard
445
- 'JCB ' , // JCB
446
- 'MAESTRO ' , // Maestro
447
- 'ONEY ' , // Oney
441
+ 'MASTERCARD ' , // Eurocard / Mastercard
442
+ 'JCB ' , // JCB
443
+ 'MAESTRO ' , // Maestro
444
+ 'ONEY ' , // Oney
448
445
'ONEY_SANDBOX ' , // Oney (sandbox)
449
- 'PAYPAL ' , // Paypal
450
- 'PAYPAL_SB ' , // Paypal (sandbox)
451
- 'PAYSAFECARD ' , // Paysafe card
452
- 'VISA ' , // Visa
446
+ 'PAYPAL ' , // Paypal
447
+ 'PAYPAL_SB ' , // Paypal (sandbox)
448
+ 'PAYSAFECARD ' , // Paysafe card
449
+ 'VISA ' , // Visa
453
450
];
454
451
}
452
+
453
+ private function getEndPoints ()
454
+ {
455
+ return [null , 'SYSTEMPAY ' ];
456
+ }
457
+
458
+ private function getUrl ()
459
+ {
460
+ if ($ this ->config ['endpoint ' ] === 'SYSTEMPAY ' ) {
461
+ return 'https://paiement.systempay.fr/vads-payment/ ' ;
462
+ }
463
+
464
+ return 'https://secure.payzen.eu/vads-payment/ ' ;
465
+ }
466
+
467
+ private function hash (string $ content ) {
468
+ if ($ this ->config ['endpoint ' ] === 'SYSTEMPAY ' ) {
469
+ return sha1 ($ content );
470
+ }
471
+
472
+ return base64_encode (hash_hmac ('sha256 ' , $ content , $ this ->config ['certificate ' ], true ));
473
+ }
455
474
}
0 commit comments