|
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\Convert; |
|
19
|
|
|
use Sylius\Bundle\PayumBundle\Provider\PaymentDescriptionProviderInterface; |
|
20
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
|
21
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
|
22
|
|
|
|
|
23
|
|
|
final class ConvertPaymentAction implements ActionInterface, GatewayAwareInterface |
|
24
|
|
|
{ |
|
25
|
|
|
use GatewayAwareTrait; |
|
26
|
|
|
|
|
27
|
|
|
/** @var PaymentDescriptionProviderInterface */ |
|
28
|
|
|
private $paymentDescriptionProvider; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct(PaymentDescriptionProviderInterface $paymentDescriptionProvider) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->paymentDescriptionProvider = $paymentDescriptionProvider; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function execute($request): void |
|
36
|
|
|
{ |
|
37
|
|
|
RequestNotSupportedException::assertSupports($this, $request); |
|
38
|
|
|
|
|
39
|
|
|
/** @var PaymentInterface $payment */ |
|
40
|
|
|
$payment = $request->getSource(); |
|
41
|
|
|
|
|
42
|
|
|
/** @var OrderInterface $order */ |
|
43
|
|
|
$order = $payment->getOrder(); |
|
44
|
|
|
|
|
45
|
|
|
$customer = $order->getCustomer(); |
|
46
|
|
|
|
|
47
|
|
|
$details = [ |
|
48
|
|
|
'name' => 'Payment', |
|
49
|
|
|
'description' => $this->paymentDescriptionProvider->getPaymentDescription($payment), |
|
50
|
|
|
'pricing_type' => CoinbaseApiClientInterface::FIXED_PRICE_PRICING_TYPE, |
|
51
|
|
|
'local_price' => [ |
|
52
|
|
|
'amount' => $payment->getAmount() / 100, |
|
53
|
|
|
'currency' => $payment->getCurrencyCode(), |
|
54
|
|
|
], |
|
55
|
|
|
'metadata' => [ |
|
56
|
|
|
'customer_id' => $customer->getId(), |
|
57
|
|
|
'payment_id' => $payment->getId(), |
|
58
|
|
|
], |
|
59
|
|
|
]; |
|
60
|
|
|
|
|
61
|
|
|
$request->setResult($details); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function supports($request): bool |
|
65
|
|
|
{ |
|
66
|
|
|
return |
|
67
|
|
|
$request instanceof Convert && |
|
68
|
|
|
$request->getSource() instanceof PaymentInterface && |
|
69
|
|
|
$request->getTo() == 'array' |
|
70
|
|
|
; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|