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\SyliusAdyenPlugin\Action; |
14
|
|
|
|
15
|
|
|
use Payum\Core\Action\ActionInterface; |
16
|
|
|
use Payum\Core\Exception\RequestNotSupportedException; |
17
|
|
|
use Payum\Core\Request\Convert; |
18
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
19
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
20
|
|
|
|
21
|
|
|
final class ConvertPaymentAction implements ActionInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritDoc} |
25
|
|
|
* |
26
|
|
|
* @param Convert $request |
27
|
|
|
*/ |
28
|
|
|
public function execute($request): void |
29
|
|
|
{ |
30
|
|
|
RequestNotSupportedException::assertSupports($this, $request); |
31
|
|
|
|
32
|
|
|
/** @var PaymentInterface $payment */ |
33
|
|
|
$payment = $request->getSource(); |
34
|
|
|
/** @var OrderInterface $order */ |
35
|
|
|
$order = $payment->getOrder(); |
36
|
|
|
|
37
|
|
|
$details['merchantReference'] = $order->getNumber() . "-" . $payment->getId(); |
38
|
|
|
$details['paymentAmount'] = $payment->getAmount(); |
39
|
|
|
$details['shopperEmail'] = $order->getCustomer()->getEmail(); |
40
|
|
|
$details['currencyCode'] = $order->getCurrencyCode(); |
41
|
|
|
$details['shopperReference'] = $order->getCustomer()->getId(); |
42
|
|
|
$details['shopperLocale'] = $order->getLocaleCode(); |
43
|
|
|
$details['countryCode'] = null !== $order->getShippingAddress() ? $order->getShippingAddress()->getCountryCode() : null; |
44
|
|
|
|
45
|
|
|
$request->setResult((array) $details); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
|
public function supports($request): bool |
52
|
|
|
{ |
53
|
|
|
return |
54
|
|
|
$request instanceof Convert && |
55
|
|
|
$request->getSource() instanceof PaymentInterface && |
56
|
|
|
$request->getTo() === 'array' |
57
|
|
|
; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|