Skip to content

Commit c3986b4

Browse files
committed
Merge remote-tracking branch 'origin/MC-34152' into 2.4-develop-pr28
2 parents 9501fe6 + 11e3bcd commit c3986b4

File tree

4 files changed

+302
-122
lines changed

4 files changed

+302
-122
lines changed

app/code/Magento/Paypal/Model/Payflowpro.php

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
use Magento\Framework\DataObject;
1010
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\Exception\State\InvalidTransitionException;
12+
use Magento\Payment\Gateway\Command\CommandException;
1113
use Magento\Payment\Helper\Formatter;
1214
use Magento\Payment\Model\InfoInterface;
1315
use 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

dev/tests/integration/testsuite/Magento/Paypal/Model/Payflow/TransparentTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ protected function setUp(): void
4747
}
4848

4949
/**
50-
* Checks a case when order should be placed in "Suspected Fraud" status based on after account verification.
50+
* Checks a case when order should be placed in "Suspected Fraud" status based on account verification.
5151
*
5252
* @magentoDataFixture Magento/Checkout/_files/quote_with_shipping_method.php
5353
* @magentoConfigFixture current_store payment/payflowpro/active 1
5454
* @magentoConfigFixture current_store payment/payflowpro/payment_action Authorization
5555
* @magentoConfigFixture current_store payment/payflowpro/fmf 1
5656
*/
57-
public function testPlaceOrderSuspectedFraud()
57+
public function testPlaceOrderSuspectedFraud(): void
5858
{
5959
$quote = $this->getQuote('test_order_1');
6060
$this->addFraudPayment($quote);
@@ -114,7 +114,7 @@ private function getQuote(string $reservedOrderId): CartInterface
114114
*
115115
* @return void
116116
*/
117-
private function addFraudPayment(CartInterface $quote)
117+
private function addFraudPayment(CartInterface $quote): void
118118
{
119119
$payment = $quote->getPayment();
120120
$payment->setMethod(Config::METHOD_PAYFLOWPRO);

0 commit comments

Comments
 (0)