Passed
Push — master ( c14871...b4b2a6 )
by Antonio
04:24 queued 42s
created

ConvertPaymentAction   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 13 1
A supports() 0 6 3
1
<?php
2
3
namespace Locastic\SyliusHTPayWayPlugin\Action;
4
5
use Payum\Core\Action\ActionInterface;
6
use Payum\Core\Exception\RequestNotSupportedException;
7
use Payum\Core\Model\PaymentInterface;
8
use Payum\Core\Request\Convert;
9
10
class ConvertPaymentAction implements ActionInterface
11
{
12
    /**
13
     * {@inheritDoc}
14
     *
15
     * @param Convert $request
16
     */
17
    public function execute($request)
18
    {
19
        RequestNotSupportedException::assertSupports($this, $request);
20
21
        /** @var PaymentInterface $payment */
22
        $payment = $request->getSource();
23
24
        $details = $payment->getDetails();
25
        $details['pgwOrderId'] = $payment->getNumber();
26
        $details['pgwAmount'] = $payment->getTotalAmount();
27
        $details['pgwEmail'] = $payment->getClientEmail();
28
29
        $request->setResult($details);
30
    }
31
32
    /**
33
     * {@inheritDoc}
34
     */
35
    public function supports($request)
36
    {
37
        return
38
            $request instanceof Convert &&
39
            'array' === $request->getTo() &&
40
            $request->getSource() instanceof PaymentInterface;
41
    }
42
}
43