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

ConvertPaymentAction::supports()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
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