Skip to content

Commit c2515cc

Browse files
committed
MC-33117: PayPal payflow pro cancel fraud transaction on paypal no reference to Magento
1 parent a202112 commit c2515cc

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

app/code/Magento/Paypal/Model/Payflow/Transparent.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Transparent extends Payflowpro implements TransparentInterface
6161
*
6262
* @var bool
6363
*/
64-
protected $_canFetchTransactionInfo = false;
64+
protected $_canFetchTransactionInfo = true;
6565

6666
/**
6767
* @var ResponseValidator
@@ -355,11 +355,11 @@ public function capture(InfoInterface $payment, $amount)
355355
*
356356
* @param InfoInterface $payment
357357
* @return bool
358-
* @throws InvalidTransitionException
359358
* @throws LocalizedException
360359
*/
361360
public function acceptPayment(InfoInterface $payment)
362361
{
362+
$this->validatePaymentTransaction($payment);
363363
if ($this->getConfigPaymentAction() === MethodInterface::ACTION_AUTHORIZE_CAPTURE) {
364364
$invoices = iterator_to_array($payment->getOrder()->getInvoiceCollection());
365365
$invoice = count($invoices) ? reset($invoices) : null;
@@ -387,6 +387,20 @@ public function denyPayment(InfoInterface $payment)
387387
return true;
388388
}
389389

390+
/**
391+
* @inheritDoc
392+
*/
393+
public function fetchTransactionInfo(InfoInterface $payment, $transactionId)
394+
{
395+
$result = parent::fetchTransactionInfo($payment, $transactionId);
396+
$this->_canFetchTransactionInfo = false;
397+
if ($payment->getIsTransactionApproved()) {
398+
$this->acceptPayment($payment);
399+
}
400+
401+
return $result;
402+
}
403+
390404
/**
391405
* Marks payment as fraudulent.
392406
*
@@ -444,4 +458,24 @@ private function getZeroAmountAuthorizationId(InfoInterface $payment): string
444458
{
445459
return (string)$payment->getAdditionalInformation(self::PNREF);
446460
}
461+
462+
/**
463+
* Validates payment transaction status on PayPal.
464+
*
465+
* @param InfoInterface $payment
466+
* @throws LocalizedException
467+
*/
468+
private function validatePaymentTransaction(InfoInterface $payment): void
469+
{
470+
if ($payment->canFetchTransactionInfo()) {
471+
$transactionId = $payment->getLastTransId();
472+
parent::fetchTransactionInfo($payment, $transactionId);
473+
$this->_canFetchTransactionInfo = false;
474+
if ($payment->getIsTransactionDenied()) {
475+
throw new LocalizedException(
476+
__('Payment can\'t be accepted since transaction was rejected by merchant.')
477+
);
478+
}
479+
}
480+
}
447481
}

app/code/Magento/Paypal/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,3 +739,4 @@ User,User
739739
"Elektronisches Lastschriftverfahren - German ELV","Elektronisches Lastschriftverfahren - German ELV"
740740
"Please enter at least 0 and at most 65535","Please enter at least 0 and at most 65535"
741741
"Order is suspended as an account verification transaction is suspected to be fraudulent.","Order is suspended as an account verification transaction is suspected to be fraudulent."
742+
"Payment can't be accepted since transaction was rejected by merchant.","Payment can't be accepted since transaction was rejected by merchant."

app/code/Magento/Sales/Controller/Adminhtml/Order/ReviewPayment.php

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

99
namespace Magento\Sales\Controller\Adminhtml\Order;
1010

11-
use Magento\Backend\App\Action;
1211
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
1312

1413
/**
@@ -63,17 +62,20 @@ public function execute()
6362
}
6463
$this->orderRepository->save($order);
6564
$this->messageManager->addSuccessMessage($message);
66-
$resultRedirect->setPath('sales/order/view', ['order_id' => $order->getEntityId()]);
67-
} else {
68-
$resultRedirect->setPath('sales/*/');
69-
return $resultRedirect;
7065
}
7166
// phpcs:ignore Magento2.Exceptions.ThrowCatch
7267
} catch (\Magento\Framework\Exception\LocalizedException $e) {
68+
$this->messageManager->addErrorMessage($e->getMessage());
7369
$this->messageManager->addErrorMessage(__('We can\'t update the payment right now.'));
7470
$this->logger->critical($e);
71+
}
72+
73+
if ($order) {
74+
$resultRedirect->setPath('sales/order/view', ['order_id' => $order->getEntityId()]);
75+
} else {
7576
$resultRedirect->setPath('sales/*/');
7677
}
78+
7779
return $resultRedirect;
7880
}
7981
}

0 commit comments

Comments
 (0)