AuthorizationRequest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A build() 0 16 3
1
<?php
2
/**
3
 * Copyright © Getnet. All rights reserved.
4
 *
5
 * @author    Bruno Elisei <[email protected]>
6
 * See LICENSE for license details.
7
 */
8
9
namespace Getnet\PaymentMagento\Gateway\Request;
10
11
use InvalidArgumentException;
12
use Magento\Payment\Gateway\ConfigInterface;
13
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
14
use Magento\Payment\Gateway\Request\BuilderInterface;
15
16
/**
17
 * Class Authorization Request - Authorization structure.
18
 */
19
class AuthorizationRequest implements BuilderInterface
20
{
21
    /**
22
     * @var string
23
     */
24
    public const GETNET_ORDER_ID = 'getnet_order_id';
25
26
    /**
27
     * @var ConfigInterface
28
     */
29
    protected $config;
30
31
    /**
32
     * @param ConfigInterface $config
33
     */
34
    public function __construct(
35
        ConfigInterface $config
36
    ) {
37
        $this->config = $config;
38
    }
39
40
    /**
41
     * Build.
42
     *
43
     * @param array $buildSubject
44
     */
45
    public function build(array $buildSubject)
46
    {
47
        if (!isset($buildSubject['payment'])
48
            || !$buildSubject['payment'] instanceof PaymentDataObjectInterface
49
        ) {
50
            throw new InvalidArgumentException('Payment data object should be provided');
51
        }
52
53
        $paymentDO = $buildSubject['payment'];
54
55
        $payment = $paymentDO->getPayment();
56
57
        $order = $payment->getOrder();
58
59
        return [
60
            self::GETNET_ORDER_ID => $order->getExtOrderId(),
61
        ];
62
    }
63
}
64