GetpayFetchTransactionInfoRequest::build()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 17
rs 9.9666
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 Getpay Fetch Transaction Info Request - Transaction query data structure.
18
 */
19
class GetpayFetchTransactionInfoRequest implements BuilderInterface
20
{
21
    /**
22
     * @var string
23
     */
24
    public const GETNET_ORDER_ID = 'order_id';
25
26
    /**
27
     * Order State - Block Name.
28
     */
29
    public const ORDER_STATE = 'state';
30
31
    /**
32
     * @var ConfigInterface
33
     */
34
    private $config;
35
36
    /**
37
     * @param ConfigInterface $config
38
     */
39
    public function __construct(
40
        ConfigInterface $config
41
    ) {
42
        $this->config = $config;
43
    }
44
45
    /**
46
     * Build.
47
     *
48
     * @param array $buildSubject
49
     */
50
    public function build(array $buildSubject)
51
    {
52
        if (!isset($buildSubject['payment'])
53
            || !$buildSubject['payment'] instanceof PaymentDataObjectInterface
54
        ) {
55
            throw new InvalidArgumentException('Payment data object should be provided');
56
        }
57
58
        $paymentDO = $buildSubject['payment'];
59
60
        $payment = $paymentDO->getPayment();
61
62
        $order = $payment->getOrder();
63
64
        return [
65
            self::GETNET_ORDER_ID   => $order->getExtOrderId(),
66
            self::ORDER_STATE       => $order->getState(),
67
        ];
68
    }
69
}
70