Skip to content

Commit 454ac36

Browse files
committed
AC-13414: Credit Card(Payflow Link) payment is not working
Process payment if not already done via silent post
1 parent d253a44 commit 454ac36

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All rights reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Paypal\Plugin;
9+
10+
use Magento\Framework\App\RequestInterface;
11+
use Magento\Paypal\Controller\Payflow\ReturnUrl as Subject;
12+
use Magento\Paypal\Model\PayflowlinkFactory;
13+
use Magento\Sales\Model\Order;
14+
use Magento\Sales\Model\OrderFactory;
15+
use Psr\Log\LoggerInterface;
16+
17+
class PayflowSilentPost
18+
{
19+
/**
20+
* @var array
21+
*/
22+
protected array $allowedOrderStates = [
23+
Order::STATE_PROCESSING,
24+
Order::STATE_COMPLETE,
25+
Order::STATE_PAYMENT_REVIEW
26+
];
27+
28+
/**
29+
* @param RequestInterface $request
30+
* @param OrderFactory $orderFactory
31+
* @param PayflowlinkFactory $payflowlinkFactory
32+
* @param LoggerInterface $logger
33+
*/
34+
public function __construct(
35+
Private readonly RequestInterface $request,
36+
Private readonly OrderFactory $orderFactory,
37+
Private readonly PayflowlinkFactory $payflowlinkFactory,
38+
Private readonly LoggerInterface $logger,
39+
) {
40+
}
41+
42+
/**
43+
* Process payment if not already done via silent post
44+
*
45+
* @param Subject $subject
46+
* @return void
47+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
48+
*/
49+
public function beforeExecute(Subject $subject): void
50+
{
51+
$data = $this->request->getParams();
52+
$orderId = (string)$data['INVNUM'];
53+
54+
if (!$orderId) {
55+
return;
56+
}
57+
58+
$order = $this->orderFactory->create()->loadByIncrementId($orderId);
59+
$payment = $order->getPayment();
60+
61+
if (in_array($order->getState(), $this->allowedOrderStates) || $payment->getLastTransId()
62+
|| trim((string)$data['RESPMSG']) !== 'Approved' || (int)$data['RESULT'] !== 0) {
63+
return;
64+
}
65+
66+
$paymentModel = $this->payflowlinkFactory->create();
67+
try {
68+
$paymentModel->process($data);
69+
} catch (\Exception $e) {
70+
$this->logger->critical($e);
71+
}
72+
}
73+
}

app/code/Magento/Paypal/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,7 @@
269269
</argument>
270270
</arguments>
271271
</type>
272+
<type name="Magento\Paypal\Controller\Payflow\ReturnUrl">
273+
<plugin name="payflow_silentpost" type="Magento\Paypal\Plugin\PayflowSilentPost"/>
274+
</type>
272275
</config>

0 commit comments

Comments
 (0)