Passed
Branch [email protected] (aae97d)
by Bruno
10:40
created

WalletFetchTransactionInfoRequest::build()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 2
b 0
f 0
nc 2
nop 1
dl 0
loc 18
rs 9.9332
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 Wallet Fetch Transaction Info Request - Transaction query data structure.
18
 */
19
class WalletFetchTransactionInfoRequest implements BuilderInterface
20
{
21
    /**
22
     * @var string
23
     */
24
    public const GETNET_PAYMENT_ID = 'payment_id';
25
26
    /**
27
     * Order State - Block Name.
28
     */
29
    public const ORDER_STATE = 'state';
30
31
    /**
32
     * @var ConfigInterface
33
     */
34
    protected $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
        $payment = $paymentDO->getPayment();
64
65
        return [
66
            self::GETNET_PAYMENT_ID => $payment->getLastTransId(),
67
            self::ORDER_STATE       => $order->getState(),
68
        ];
69
    }
70
}
71