8
8
9
9
use Magento \Framework \DataObject ;
10
10
use Magento \Framework \Exception \LocalizedException ;
11
+ use Magento \Framework \Exception \State \InvalidTransitionException ;
12
+ use Magento \Payment \Gateway \Command \CommandException ;
11
13
use Magento \Payment \Helper \Formatter ;
12
14
use Magento \Payment \Model \InfoInterface ;
13
15
use Magento \Payment \Model \Method \ConfigInterface ;
@@ -85,6 +87,8 @@ class Payflowpro extends \Magento\Payment\Model\Method\Cc implements GatewayInte
85
87
86
88
const RESPONSE_CODE_VOID_ERROR = 108 ;
87
89
90
+ private const RESPONSE_CODE_AUTHORIZATION_EXPIRED = 10601 ;
91
+
88
92
const PNREF = 'pnref ' ;
89
93
90
94
/**#@-*/
@@ -376,7 +380,7 @@ public function getConfigPaymentAction()
376
380
* @param float $amount
377
381
* @return $this
378
382
* @throws \Magento\Framework\Exception\LocalizedException
379
- * @throws \Magento\Framework\Exception\State\ InvalidTransitionException
383
+ * @throws InvalidTransitionException
380
384
*/
381
385
public function authorize (\Magento \Payment \Model \InfoInterface $ payment , $ amount )
382
386
{
@@ -410,7 +414,7 @@ protected function _getCaptureAmount($amount)
410
414
* @param float $amount
411
415
* @return $this
412
416
* @throws \Magento\Framework\Exception\LocalizedException
413
- * @throws \Magento\Framework\Exception\State\ InvalidTransitionException
417
+ * @throws InvalidTransitionException
414
418
*/
415
419
public function capture (\Magento \Payment \Model \InfoInterface $ payment , $ amount )
416
420
{
@@ -448,7 +452,7 @@ public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
448
452
* @param InfoInterface|Payment|Object $payment
449
453
* @return $this
450
454
* @throws \Magento\Framework\Exception\LocalizedException
451
- * @throws \Magento\Framework\Exception\State\ InvalidTransitionException
455
+ * @throws InvalidTransitionException
452
456
*/
453
457
public function void (\Magento \Payment \Model \InfoInterface $ payment )
454
458
{
@@ -491,14 +495,23 @@ public function canVoid()
491
495
*
492
496
* @param InfoInterface|Object $payment
493
497
* @return $this
498
+ * @throws CommandException
494
499
*/
495
500
public function cancel (\Magento \Payment \Model \InfoInterface $ payment )
496
501
{
497
502
if (!$ payment ->getOrder ()->getInvoiceCollection ()->count ()) {
498
- return $ this ->void ($ payment );
503
+ try {
504
+ $ this ->void ($ payment );
505
+ } catch (CommandException $ e ) {
506
+ // Ignore error about expiration of authorization transaction.
507
+ if (strpos ($ e ->getMessage (), (string )self ::RESPONSE_CODE_AUTHORIZATION_EXPIRED ) === false ) {
508
+ throw $ e ;
509
+ }
510
+ }
511
+
499
512
}
500
513
501
- return false ;
514
+ return $ this ;
502
515
}
503
516
504
517
/**
@@ -508,7 +521,7 @@ public function cancel(\Magento\Payment\Model\InfoInterface $payment)
508
521
* @param float $amount
509
522
* @return $this
510
523
* @throws \Magento\Framework\Exception\LocalizedException
511
- * @throws \Magento\Framework\Exception\State\ InvalidTransitionException
524
+ * @throws InvalidTransitionException
512
525
*/
513
526
public function refund (\Magento \Payment \Model \InfoInterface $ payment , $ amount )
514
527
{
@@ -558,7 +571,7 @@ public function fetchTransactionInfo(InfoInterface $payment, $transactionId)
558
571
* @return bool
559
572
* phpcs:disable Magento2.Functions.StaticFunction
560
573
*/
561
- protected static function _isTransactionUnderReview ($ status )
574
+ protected function _isTransactionUnderReview ($ status )
562
575
{
563
576
if (in_array ($ status , [self ::RESPONSE_CODE_APPROVED , self ::RESPONSE_CODE_DECLINED_BY_MERCHANT ])) {
564
577
return false ;
@@ -650,21 +663,22 @@ public function buildBasicRequest()
650
663
*
651
664
* @param DataObject $response
652
665
* @return void
653
- * @throws \Magento\Payment\Gateway\Command\ CommandException
654
- * @throws \Magento\Framework\Exception\State\ InvalidTransitionException
666
+ * @throws CommandException
667
+ * @throws InvalidTransitionException
655
668
*/
656
669
public function processErrors (DataObject $ response )
657
670
{
658
- if ($ response ->getResultCode () == self ::RESPONSE_CODE_VOID_ERROR ) {
659
- throw new \Magento \Framework \Exception \State \InvalidTransitionException (
671
+ $ resultCode = (int )$ response ->getResultCode ();
672
+ if ($ resultCode === self ::RESPONSE_CODE_VOID_ERROR ) {
673
+ throw new InvalidTransitionException (
660
674
__ ("The verification transaction can't be voided. " )
661
675
);
662
- } elseif ( $ response -> getResultCode () != self :: RESPONSE_CODE_APPROVED &&
663
- $ response -> getResultCode () != self ::RESPONSE_CODE_FRAUDSERVICE_FILTER
664
- ) {
665
- throw new \ Magento \ Payment \ Gateway \ Command \ CommandException ( __ ( $ response -> getRespmsg ()));
666
- } elseif ( $ response ->getOrigresult () == self ::RESPONSE_CODE_DECLINED_BY_FILTER ) {
667
- throw new \ Magento \ Payment \ Gateway \ Command \ CommandException (__ ($ response ->getRespmsg ()));
676
+ }
677
+ if (! in_array ( $ resultCode , [ self ::RESPONSE_CODE_APPROVED , self :: RESPONSE_CODE_FRAUDSERVICE_FILTER ])) {
678
+ throw new CommandException ( __ ( $ response -> getRespmsg ()));
679
+ }
680
+ if (( int ) $ response ->getOrigresult () = == self ::RESPONSE_CODE_DECLINED_BY_FILTER ) {
681
+ throw new CommandException (__ ($ response ->getRespmsg ()));
668
682
}
669
683
}
670
684
0 commit comments