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\SyliusCoinbasePlugin\Action; |
12
|
|
|
|
13
|
|
|
use BitBag\SyliusCoinbasePlugin\ApiClient\CoinbaseApiClientInterface; |
14
|
|
|
use Payum\Core\Action\ActionInterface; |
15
|
|
|
use Payum\Core\Exception\RequestNotSupportedException; |
16
|
|
|
use Payum\Core\GatewayAwareInterface; |
17
|
|
|
use Payum\Core\GatewayAwareTrait; |
18
|
|
|
use Payum\Core\Request\GetStatusInterface; |
19
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
20
|
|
|
|
21
|
|
|
final class StatusAction implements ActionInterface, GatewayAwareInterface |
22
|
|
|
{ |
23
|
|
|
use GatewayAwareTrait; |
24
|
|
|
|
25
|
|
|
public function execute($request): void |
26
|
|
|
{ |
27
|
|
|
RequestNotSupportedException::assertSupports($this, $request); |
28
|
|
|
|
29
|
|
|
/** @var PaymentInterface $payment */ |
30
|
|
|
$payment = $request->getModel(); |
31
|
|
|
|
32
|
|
|
$details = $payment->getDetails(); |
33
|
|
|
|
34
|
|
|
if (!isset($details['status']) || !isset($details['payment_id'])) { |
35
|
|
|
$request->markNew(); |
36
|
|
|
|
37
|
|
|
return; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
switch ($details['status']) { |
41
|
|
|
case CoinbaseApiClientInterface::STATUS_CREATED: |
42
|
|
|
case CoinbaseApiClientInterface::STATUS_NEW: |
43
|
|
|
case CoinbaseApiClientInterface::STATUS_PENDING: |
44
|
|
|
$request->markPending(); |
45
|
|
|
|
46
|
|
|
break; |
47
|
|
|
case CoinbaseApiClientInterface::STATUS_CANCELED: |
48
|
|
|
$request->markCanceled(); |
49
|
|
|
|
50
|
|
|
break; |
51
|
|
|
case CoinbaseApiClientInterface::STATUS_COMPLETED: |
52
|
|
|
$request->markCaptured(); |
53
|
|
|
|
54
|
|
|
break; |
55
|
|
|
default: |
56
|
|
|
$request->markFailed(); |
57
|
|
|
|
58
|
|
|
break; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function supports($request): bool |
63
|
|
|
{ |
64
|
|
|
return |
65
|
|
|
$request instanceof GetStatusInterface && |
66
|
|
|
$request->getModel() instanceof PaymentInterface |
67
|
|
|
; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|