88
99use Magento \Framework \DataObject ;
1010use Magento \Framework \Exception \LocalizedException ;
11+ use Magento \Framework \Exception \State \InvalidTransitionException ;
12+ use Magento \Payment \Gateway \Command \CommandException ;
1113use Magento \Payment \Helper \Formatter ;
1214use Magento \Payment \Model \InfoInterface ;
1315use Magento \Payment \Model \Method \ConfigInterface ;
@@ -85,6 +87,8 @@ class Payflowpro extends \Magento\Payment\Model\Method\Cc implements GatewayInte
8587
8688 const RESPONSE_CODE_VOID_ERROR = 108 ;
8789
90+ private const RESPONSE_CODE_AUTHORIZATION_EXPIRED = 10601 ;
91+
8892 const PNREF = 'pnref ' ;
8993
9094 /**#@-*/
@@ -376,7 +380,7 @@ public function getConfigPaymentAction()
376380 * @param float $amount
377381 * @return $this
378382 * @throws \Magento\Framework\Exception\LocalizedException
379- * @throws \Magento\Framework\Exception\State\ InvalidTransitionException
383+ * @throws InvalidTransitionException
380384 */
381385 public function authorize (\Magento \Payment \Model \InfoInterface $ payment , $ amount )
382386 {
@@ -410,7 +414,7 @@ protected function _getCaptureAmount($amount)
410414 * @param float $amount
411415 * @return $this
412416 * @throws \Magento\Framework\Exception\LocalizedException
413- * @throws \Magento\Framework\Exception\State\ InvalidTransitionException
417+ * @throws InvalidTransitionException
414418 */
415419 public function capture (\Magento \Payment \Model \InfoInterface $ payment , $ amount )
416420 {
@@ -448,7 +452,7 @@ public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
448452 * @param InfoInterface|Payment|Object $payment
449453 * @return $this
450454 * @throws \Magento\Framework\Exception\LocalizedException
451- * @throws \Magento\Framework\Exception\State\ InvalidTransitionException
455+ * @throws InvalidTransitionException
452456 */
453457 public function void (\Magento \Payment \Model \InfoInterface $ payment )
454458 {
@@ -491,14 +495,23 @@ public function canVoid()
491495 *
492496 * @param InfoInterface|Object $payment
493497 * @return $this
498+ * @throws CommandException
494499 */
495500 public function cancel (\Magento \Payment \Model \InfoInterface $ payment )
496501 {
497502 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+
499512 }
500513
501- return false ;
514+ return $ this ;
502515 }
503516
504517 /**
@@ -508,7 +521,7 @@ public function cancel(\Magento\Payment\Model\InfoInterface $payment)
508521 * @param float $amount
509522 * @return $this
510523 * @throws \Magento\Framework\Exception\LocalizedException
511- * @throws \Magento\Framework\Exception\State\ InvalidTransitionException
524+ * @throws InvalidTransitionException
512525 */
513526 public function refund (\Magento \Payment \Model \InfoInterface $ payment , $ amount )
514527 {
@@ -558,7 +571,7 @@ public function fetchTransactionInfo(InfoInterface $payment, $transactionId)
558571 * @return bool
559572 * phpcs:disable Magento2.Functions.StaticFunction
560573 */
561- protected static function _isTransactionUnderReview ($ status )
574+ protected function _isTransactionUnderReview ($ status )
562575 {
563576 if (in_array ($ status , [self ::RESPONSE_CODE_APPROVED , self ::RESPONSE_CODE_DECLINED_BY_MERCHANT ])) {
564577 return false ;
@@ -650,21 +663,22 @@ public function buildBasicRequest()
650663 *
651664 * @param DataObject $response
652665 * @return void
653- * @throws \Magento\Payment\Gateway\Command\ CommandException
654- * @throws \Magento\Framework\Exception\State\ InvalidTransitionException
666+ * @throws CommandException
667+ * @throws InvalidTransitionException
655668 */
656669 public function processErrors (DataObject $ response )
657670 {
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 (
660674 __ ("The verification transaction can't be voided. " )
661675 );
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 ()));
668682 }
669683 }
670684
0 commit comments