AuthorizationRequest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A build() 0 22 3
1
<?php
2
/**
3
 * Copyright © 2016 Magento. All rights reserved.
4
 * See COPYING.txt for license details.
5
 */
6
namespace Pagantis\Pagantis\Gateway\Request;
7
8
use Magento\Payment\Gateway\ConfigInterface;
9
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
10
use Magento\Payment\Gateway\Request\BuilderInterface;
11
12
class AuthorizationRequest implements BuilderInterface
13
{
14
    /**
15
     * @var ConfigInterface
16
     */
17
    private $config;
18
19
    /**
20
     * @param ConfigInterface $config
21
     */
22
    public function __construct(
23
        ConfigInterface $config
24
    ) {
25
        $this->config = $config;
26
    }
27
28
    /**
29
     * Builds ENV request
30
     *
31
     * @param array $buildSubject
32
     * @return array
33
     */
34
    public function build(array $buildSubject)
35
    {
36
        if (!isset($buildSubject['payment'])
37
            || !$buildSubject['payment'] instanceof PaymentDataObjectInterface
38
        ) {
39
            throw new \InvalidArgumentException('Payment data object should be provided');
40
        }
41
42
        /** @var PaymentDataObjectInterface $payment */
43
        $payment = $buildSubject['payment'];
44
        $order = $payment->getOrder();
45
        $address = $order->getShippingAddress();
46
47
        return [
48
            'TXN_TYPE' => 'A',
49
            'INVOICE' => $order->getOrderIncrementId(),
50
            'AMOUNT' => $order->getGrandTotalAmount(),
51
            'CURRENCY' => $order->getCurrencyCode(),
52
            'EMAIL' => $address->getEmail(),
53
            'MERCHANT_KEY' => $this->config->getValue(
54
                'merchant_gateway_key',
55
                $order->getStoreId()
56
            )
57
        ];
58
    }
59
}
60