Passed
Push — master ( f940ba...b28d4a )
by Mykolas
03:04 queued 53s
created

ConvertPaymentAction   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 25%

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 56
ccs 6
cts 24
cp 0.25
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 6 3
A execute() 0 32 2
1
<?php
2
3
namespace PTS\Paysera\Action;
4
5
use Payum\Core\Action\ActionInterface;
6
use Payum\Core\Bridge\Spl\ArrayObject;
7
use Payum\Core\Exception\RequestNotSupportedException;
8
use Payum\Core\GatewayAwareInterface;
9
use Payum\Core\GatewayAwareTrait;
10
use Payum\Core\Model\PaymentInterface;
11
use Payum\Core\Request\Convert;
12
use Payum\Core\Security\GenericTokenFactoryAwareInterface;
13
use Payum\Core\Security\GenericTokenFactoryAwareTrait;
14
15
class ConvertPaymentAction implements ActionInterface, GenericTokenFactoryAwareInterface, GatewayAwareInterface
16
{
17
18
    use GatewayAwareTrait;
19
20
    use GenericTokenFactoryAwareTrait;
21
22
    /**
23
     * {@inheritDoc}
24
     *
25
     * @param Convert $request
26
     */
27 5
    public function execute($request)
28
    {
29 5
        RequestNotSupportedException::assertSupports($this, $request);
30
        /**
31
         * @var $order PaymentInterface
32
         */
33
        $order = $request->getSource();
34
35
        $details = ArrayObject::ensureArrayObject($order->getDetails());
36
37
38
        $details['amount'] = $order->getTotalAmount();
39
        $details['currency'] = $order->getCurrencyCode();
40
        $details['orderid'] = $order->getNumber();
41
        $details['description'] = $order->getDescription();
42
        $details['p_email'] = $order->getClientEmail();
43
        $details['personcode'] = $order->getClientId();
44
        $details['customerIp'] = array_key_exists('REMOTE_ADDR', $_SERVER) ? $_SERVER['REMOTE_ADDR'] : null;
45
46
        $token = $request->getToken();
47
48
        $details['accepturl'] = $token->getTargetUrl();
49
        $details['cancelurl'] = $token->getTargetUrl() . '?cancel=true';
50
51
        $notifyToken = $this->tokenFactory->createNotifyToken(
52
            $token->getGatewayName(),
53
            $token->getDetails()
54
        );
55
56
        $details['callbackurl'] = $notifyToken->getTargetUrl();
57
58
        $request->setResult((array)$details);
59
60
    }
61
62
    /**
63
     * {@inheritDoc}
64
     */
65 13
    public function supports($request)
66
    {
67
        return
68 13
            $request instanceof Convert &&
69 5
            $request->getSource() instanceof PaymentInterface &&
70 13
            $request->getTo() == 'array';
71
    }
72
}
73