ConvertPaymentAction   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 19 2
A supports() 0 8 3
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