|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file was created by developers working at BitBag |
|
5
|
|
|
* Do you need more information about us and what we do? Visit our https://bitbag.io website! |
|
6
|
|
|
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
declare(strict_types=1); |
|
10
|
|
|
|
|
11
|
|
|
namespace BitBag\SyliusMultiSafepayPlugin\Action; |
|
12
|
|
|
|
|
13
|
|
|
use BitBag\SyliusMultiSafepayPlugin\Action\Api\ApiAwareTrait; |
|
14
|
|
|
use BitBag\SyliusMultiSafepayPlugin\ApiClient\MultiSafepayApiClientInterface; |
|
15
|
|
|
use Payum\Core\Action\ActionInterface; |
|
16
|
|
|
use Payum\Core\ApiAwareInterface; |
|
17
|
|
|
use Payum\Core\Exception\RequestNotSupportedException; |
|
18
|
|
|
use Payum\Core\GatewayAwareInterface; |
|
19
|
|
|
use Payum\Core\GatewayAwareTrait; |
|
20
|
|
|
use Payum\Core\Request\GetHttpRequest; |
|
21
|
|
|
use Payum\Core\Request\GetStatusInterface; |
|
22
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
|
23
|
|
|
|
|
24
|
|
|
final class StatusAction implements ActionInterface, GatewayAwareInterface, ApiAwareInterface |
|
25
|
|
|
{ |
|
26
|
|
|
use GatewayAwareTrait; |
|
27
|
|
|
|
|
28
|
|
|
use ApiAwareTrait; |
|
29
|
|
|
|
|
30
|
|
|
public function execute($request): void |
|
31
|
|
|
{ |
|
32
|
|
|
RequestNotSupportedException::assertSupports($this, $request); |
|
33
|
|
|
|
|
34
|
|
|
/** @var PaymentInterface $payment */ |
|
35
|
|
|
$payment = $request->getModel(); |
|
36
|
|
|
|
|
37
|
|
|
$details = $payment->getDetails(); |
|
38
|
|
|
|
|
39
|
|
|
if (!isset($details['status']) || !isset($details['orderId'])) { |
|
40
|
|
|
$request->markNew(); |
|
41
|
|
|
|
|
42
|
|
|
return; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$this->gateway->execute($httpRequest = new GetHttpRequest()); |
|
46
|
|
|
|
|
47
|
|
|
if (isset($httpRequest->query['type']) && MultiSafepayApiClientInterface::STATUS_CANCEL === $httpRequest->query['type']) { |
|
48
|
|
|
$details['status'] = MultiSafepayApiClientInterface::STATUS_CANCELED; |
|
49
|
|
|
} elseif (MultiSafepayApiClientInterface::STATUS_CANCELED !== $details['status']) { |
|
50
|
|
|
$order = $this->multiSafepayApiClient->getOrderById($details['orderId']); |
|
51
|
|
|
|
|
52
|
|
|
$details['status'] = $order->status; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$payment->setDetails($details); |
|
56
|
|
|
|
|
57
|
|
|
switch ($details['status']) { |
|
58
|
|
|
case MultiSafepayApiClientInterface::STATUS_CANCELED: |
|
59
|
|
|
case MultiSafepayApiClientInterface::STATUS_VOID: |
|
60
|
|
|
$request->markCanceled(); |
|
61
|
|
|
|
|
62
|
|
|
break; |
|
63
|
|
|
case MultiSafepayApiClientInterface::STATUS_COMPLETED: |
|
64
|
|
|
$request->markCaptured(); |
|
65
|
|
|
|
|
66
|
|
|
break; |
|
67
|
|
|
case MultiSafepayApiClientInterface::STATUS_INITIALIZED: |
|
68
|
|
|
case MultiSafepayApiClientInterface::STATUS_UNCLEARED: |
|
69
|
|
|
case MultiSafepayApiClientInterface::STATUS_RESERVED: |
|
70
|
|
|
$request->markPending(); |
|
71
|
|
|
|
|
72
|
|
|
break; |
|
73
|
|
|
case MultiSafepayApiClientInterface::STATUS_DECLINED: |
|
74
|
|
|
case MultiSafepayApiClientInterface::STATUS_EXPIRED: |
|
75
|
|
|
$request->markFailed(); |
|
76
|
|
|
|
|
77
|
|
|
break; |
|
78
|
|
|
case MultiSafepayApiClientInterface::STATUS_REFUNDED: |
|
79
|
|
|
$request->markRefunded(); |
|
80
|
|
|
|
|
81
|
|
|
break; |
|
82
|
|
|
default: |
|
83
|
|
|
$request->markUnknown(); |
|
84
|
|
|
|
|
85
|
|
|
break; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function supports($request): bool |
|
90
|
|
|
{ |
|
91
|
|
|
return |
|
92
|
|
|
$request instanceof GetStatusInterface && |
|
93
|
|
|
$request->getModel() instanceof PaymentInterface |
|
94
|
|
|
; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|