1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file has been created by developers from BitBag. |
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
6
|
|
|
* another great project. |
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
8
|
|
|
* an email on [email protected]. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace BitBag\SyliusMultiSafepayPlugin\Action; |
14
|
|
|
|
15
|
|
|
use BitBag\SyliusMultiSafepayPlugin\Action\Api\ApiAwareTrait; |
16
|
|
|
use BitBag\SyliusMultiSafepayPlugin\MultiSafepayGatewayFactory; |
17
|
|
|
use Payum\Core\Action\ActionInterface; |
18
|
|
|
use Payum\Core\ApiAwareInterface; |
19
|
|
|
use Payum\Core\Bridge\Spl\ArrayObject; |
20
|
|
|
use Payum\Core\GatewayAwareInterface; |
21
|
|
|
use Payum\Core\GatewayAwareTrait; |
22
|
|
|
use Payum\Core\Reply\HttpResponse; |
23
|
|
|
use Payum\Core\Request\GetHttpRequest; |
24
|
|
|
use Payum\Core\Request\Notify; |
25
|
|
|
use Psr\Log\LoggerInterface; |
26
|
|
|
use SM\Factory\FactoryInterface; |
27
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
28
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
29
|
|
|
use Sylius\Component\Core\Model\PaymentMethodInterface; |
30
|
|
|
use Sylius\Component\Payment\PaymentTransitions; |
31
|
|
|
|
32
|
|
|
final class NotifyAction implements ActionInterface, ApiAwareInterface, GatewayAwareInterface |
33
|
|
|
{ |
34
|
|
|
use GatewayAwareTrait, ApiAwareTrait; |
35
|
|
|
|
36
|
|
|
/** @var LoggerInterface */ |
37
|
|
|
private $logger; |
38
|
|
|
|
39
|
|
|
/** @var FactoryInterface */ |
40
|
|
|
private $stateMachineFactory; |
41
|
|
|
|
42
|
|
|
public function __construct(LoggerInterface $logger, FactoryInterface $stateMachineFactory) |
43
|
|
|
{ |
44
|
|
|
$this->logger = $logger; |
45
|
|
|
$this->stateMachineFactory = $stateMachineFactory; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function execute($request): void |
49
|
|
|
{ |
50
|
|
|
/** @var $request Notify */ |
51
|
|
|
$details = ArrayObject::ensureArrayObject($request->getModel()); |
52
|
|
|
|
53
|
|
|
$this->gateway->execute($httpRequest = new GetHttpRequest()); |
54
|
|
|
|
55
|
|
|
if (!isset($httpRequest->query['transactionid'])) { |
56
|
|
|
throw new HttpResponse(null, 400); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** @var PaymentInterface $payment */ |
60
|
|
|
$payment = $request->getFirstModel(); |
61
|
|
|
|
62
|
|
|
/** @var OrderInterface $order */ |
63
|
|
|
$order = $payment->getOrder(); |
64
|
|
|
|
65
|
|
|
/** @var PaymentInterface $item */ |
66
|
|
|
foreach ($order->getPayments() as $item) { |
67
|
|
|
/** @var PaymentMethodInterface $method */ |
68
|
|
|
$method = $item->getMethod(); |
69
|
|
|
|
70
|
|
|
if ( |
71
|
|
|
PaymentInterface::STATE_NEW === $item->getState() && |
72
|
|
|
MultiSafepayGatewayFactory::FACTORY_NAME === $method->getGatewayConfig()->getFactoryName() && |
|
|
|
|
73
|
|
|
$payment !== $item |
74
|
|
|
) { |
75
|
|
|
$order->removePayment($item); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$paymentStateMachine = $this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH); |
80
|
|
|
|
81
|
|
|
$orderData = $this->multiSafepayApiClient->getOrderById($details['orderId']); |
82
|
|
|
|
83
|
|
|
if ( |
84
|
|
|
(PaymentInterface::STATE_FAILED === $payment->getState() || PaymentInterface::STATE_CANCELLED === $payment->getState()) && |
85
|
|
|
$paymentStateMachine->can(PaymentTransitions::TRANSITION_PROCESS) && |
86
|
|
|
$this->multiSafepayApiClient->isPaymentActive($orderData->status) |
87
|
|
|
) { |
88
|
|
|
$paymentStateMachine->apply(PaymentTransitions::TRANSITION_PROCESS); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$details['status'] = $orderData->status; |
92
|
|
|
|
93
|
|
|
throw new HttpResponse('OK', 200); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function supports($request): bool |
97
|
|
|
{ |
98
|
|
|
return |
99
|
|
|
$request instanceof Notify && |
100
|
|
|
$request->getModel() instanceof \ArrayAccess |
101
|
|
|
; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.