77
88use Omnipay \Common \Exception \InvalidResponseException ;
99use Omnipay \Common \Message \ResponseInterface ;
10+ use Omnipay \Gvp \Mask ;
11+ use Omnipay \Gvp \RequestInterface ;
1012
11- abstract class AbstractRequest extends \Omnipay \Common \Message \AbstractRequest
13+ abstract class AbstractRequest extends \Omnipay \Common \Message \AbstractRequest implements RequestInterface
1214{
1315 /** @var string */
1416 protected const USERNAME_AUT = 'PROVAUT ' ;
@@ -36,6 +38,8 @@ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
3638 'JPY ' => 392
3739 ];
3840
41+ protected $ requestParams ;
42+
3943 /**
4044 * @return string
4145 */
@@ -256,44 +260,44 @@ protected function getTransactionHashRefundAndCancel(): string
256260 $ this ->getSecurityHash ())));
257261 }
258262
263+
259264 /**
260265 * @return array
261- * @throws \Omnipay\Common\Exception\InvalidRequestException
262266 */
263267 protected function getSalesRequestParams (): array
264268 {
265269 $ data = $ this ->getInfo ();
266- $ data ['Card ' ] = array (
270+ $ data ['Card ' ] = [
267271 'Number ' => $ this ->getCard ()->getNumber (),
268272 'ExpireDate ' => $ this ->getCard ()->getExpiryDate ('my ' ),
269273 'CVV2 ' => $ this ->getCard ()->getCvv ()
270- ) ;
274+ ] ;
271275
272- $ data ['Order ' ] = array (
276+ $ data ['Order ' ] = [
273277 'OrderID ' => $ this ->getOrderId ()
274- ) ;
278+ ] ;
275279
276- $ data ['Customer ' ] = array (
280+ $ data ['Customer ' ] = [
277281 'IPAddress ' => $ this ->getClientIp (),
278282 'EmailAddress ' => $ this ->getCard ()->getEmail ()
279- ) ;
283+ ] ;
280284
281285 $ data ['Terminal ' ] = [
282- 'ProvUserID ' => self :: USERNAME_AUT ,
286+ 'ProvUserID ' => $ this -> getProcessName () ,
283287 'HashData ' => $ this ->getTransactionHash (),
284- 'UserID ' => self :: USERNAME_AUT ,
288+ 'UserID ' => $ this -> getProcessName () ,
285289 'ID ' => $ this ->getTerminalId (),
286290 'MerchantID ' => $ this ->getMerchantId ()
287291 ];
288292
289- $ data ['Transaction ' ] = array (
290- 'Type ' => ' sales ' ,
293+ $ data ['Transaction ' ] = [
294+ 'Type ' => $ this -> getProcessType () ,
291295 'InstallmentCnt ' => $ this ->getInstallment (),
292296 'Amount ' => $ this ->getAmountInteger (),
293297 'CurrencyCode ' => $ this ->currency_list [$ this ->getCurrency ()],
294- 'CardholderPresentCode ' => " 0 " ,
295- 'MotoInd ' => " N "
296- ) ;
298+ 'CardholderPresentCode ' => ' 0 ' ,
299+ 'MotoInd ' => ' N '
300+ ] ;
297301
298302 return $ data ;
299303 }
@@ -306,28 +310,28 @@ protected function getCompleteSalesRequestParams(): array
306310 {
307311
308312 $ data = $ this ->getInfo ();
309- $ data ['Order ' ] = array (
313+ $ data ['Order ' ] = [
310314 'OrderID ' => $ this ->getOrderId ()
311- ) ;
315+ ] ;
312316
313- $ data ['Customer ' ] = array (
317+ $ data ['Customer ' ] = [
314318 'IPAddress ' => $ this ->getClientIp (),
315- ) ;
319+ ] ;
316320
317321 $ data ['Terminal ' ] = [
318- 'ProvUserID ' => self :: USERNAME_AUT ,
322+ 'ProvUserID ' => $ this -> getProcessName () ,
319323 'HashData ' => $ this ->getTransactionHashWithoutCardNumber (),
320- 'UserID ' => self :: USERNAME_AUT ,
324+ 'UserID ' => $ this -> getProcessName () ,
321325 'ID ' => $ this ->getTerminalId (),
322326 'MerchantID ' => $ this ->getMerchantId ()
323327 ];
324328
325- $ data ['Transaction ' ] = array (
326- 'Type ' => ' sales ' ,
329+ $ data ['Transaction ' ] = [
330+ 'Type ' => $ this -> getProcessType () ,
327331 'Amount ' => $ this ->getAmountInteger (),
328332 'CurrencyCode ' => $ this ->currency_list [$ this ->getCurrency ()],
329- 'MotoInd ' => " N "
330- ) ;
333+ 'MotoInd ' => ' N '
334+ ] ;
331335
332336 return $ data ;
333337 }
@@ -339,46 +343,48 @@ protected function getAuthorizeRequestParams(): array
339343 {
340344 $ data = $ this ->getInfo ();
341345 $ data ['Terminal ' ] = [
342- 'ProvUserID ' => self :: USERNAME_AUT ,
346+ 'ProvUserID ' => $ this -> getProcessName () ,
343347 'HashData ' => $ this ->getTransactionHash (),
344- 'UserID ' => self :: USERNAME_AUT ,
348+ 'UserID ' => $ this -> getProcessName () ,
345349 'ID ' => $ this ->getTerminalId (),
346350 'MerchantID ' => $ this ->getMerchantId ()
347351 ];
348- $ data ['Customer ' ] = array (
352+ $ data ['Customer ' ] = [
349353 'IPAddress ' => $ this ->getClientIp (),
350354 'EmailAddress ' => $ this ->getCard ()->getEmail ()
351- );
352- $ data ['Card ' ] = array (
355+ ];
356+
357+ $ data ['Card ' ] = [
353358 'Number ' => $ this ->getCard ()->getNumber (),
354359 'ExpireDate ' => $ this ->getCard ()->getExpiryDate ('my ' )
355- );
356- $ data ['Order ' ] = array (
360+ ];
361+
362+ $ data ['Order ' ] = [
357363 'OrderID ' => $ this ->getOrderId ()
358- );
359- $ data ['Transaction ' ] = array (
360- 'Type ' => 'preauth ' ,
364+ ];
365+
366+ $ data ['Transaction ' ] = [
367+ 'Type ' => $ this ->getProcessType (),
361368 'InstallmentCnt ' => $ this ->getInstallment (),
362369 'Amount ' => $ this ->getAmountInteger (),
363370 'CurrencyCode ' => $ this ->currency_list [$ this ->getCurrency ()],
364- 'CardholderPresentCode ' => " 0 " ,
365- 'MotoInd ' => " N "
366- ) ;
371+ 'CardholderPresentCode ' => ' 0 ' ,
372+ 'MotoInd ' => ' N '
373+ ] ;
367374
368375 return $ data ;
369376 }
370377
371378 /**
372379 * @return array
373- * @throws \Omnipay\Common\Exception\InvalidRequestException
374380 */
375381 protected function getSalesRequestParamsFor3d (): array
376382 {
377383 $ expiryYear = \DateTime::createFromFormat ('Y ' , $ this ->getCard ()->getExpiryYear ());
378384 $ params ['apiversion ' ] = $ this ->version ;
379385 $ params ['mode ' ] = $ this ->getTestMode () ? 'TEST ' : 'PROD ' ;
380- $ params ['terminalprovuserid ' ] = self :: USERNAME_AUT ;
381- $ params ['terminaluserid ' ] = self :: USERNAME_AUT ;
386+ $ params ['terminalprovuserid ' ] = $ this -> getProcessName () ;
387+ $ params ['terminaluserid ' ] = $ this -> getProcessName () ;
382388 $ params ['terminalid ' ] = $ this ->getTerminalId ();
383389 $ params ['terminalmerchantid ' ] = $ this ->getMerchantId ();
384390 $ params ['txntype ' ] = 'sales ' ;
@@ -405,14 +411,62 @@ protected function getSalesRequestParamsFor3d(): array
405411 return $ params ;
406412 }
407413
414+ /**
415+ * @return array
416+ */
417+ protected function getRefundRequestParams (): array
418+ {
419+ $ data = $ this ->getInfo ();
420+ $ data ['Terminal ' ] = [
421+ 'ProvUserID ' => $ this ->getProcessName (),
422+ 'HashData ' => $ this ->getTransactionHashRefundAndCancel (),
423+ 'UserID ' => $ this ->getProcessName (),
424+ 'ID ' => $ this ->getTerminalId (),
425+ 'MerchantID ' => $ this ->getMerchantId ()
426+ ];
427+
428+ $ data ['Customer ' ] = [
429+ 'IPAddress ' => $ this ->getClientIp ()
430+ ];
431+
432+ $ data ['Order ' ] = [
433+ 'OrderID ' => $ this ->getOrderId ()
434+ ];
435+
436+ $ data ['Transaction ' ] = [
437+ 'Type ' => $ this ->getProcessType (),
438+ 'Amount ' => $ this ->getAmountInteger (),
439+ 'CurrencyCode ' => $ this ->currency_list [$ this ->getCurrency ()]
440+ ];
441+
442+ return $ data ;
443+ }
444+
445+ protected function setRequestParams (array $ data ): void
446+ {
447+ array_walk_recursive ($ data , [$ this , 'updateValue ' ]);
448+ $ this ->requestParams = $ data ;
449+ }
450+
451+ protected function updateValue (&$ data , $ key ): void
452+ {
453+ $ sensitiveData = $ this ->getSensitiveData ();
454+
455+ if (\in_array ($ key , $ sensitiveData , true )) {
456+ $ data = Mask::mask ($ data );
457+ }
458+
459+ }
460+
408461 /**
409462 * @return array
410463 */
411464 protected function getRequestParams (): array
412465 {
413466 return [
414467 'url ' => $ this ->getEndPoint (),
415- 'data ' => $ this ->getData (),
468+ 'type ' => $ this ->getProcessType (),
469+ 'data ' => $ this ->requestParams ,
416470 'method ' => $ this ->getHttpMethod ()
417471 ];
418472 }
@@ -428,7 +482,7 @@ private function getSecurityHash(): string
428482 /**
429483 * @return array
430484 */
431- private function getInfo (): array
485+ protected function getInfo (): array
432486 {
433487 $ data ['Version ' ] = $ this ->version ;
434488 $ data ['Mode ' ] = $ this ->getTestMode () ? 'TEST ' : 'PROD ' ;
0 commit comments