ExtPaymentIdRequest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 14 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\Data\PaymentDataObjectInterface;
13
use Magento\Payment\Gateway\Request\BuilderInterface;
14
15
/**
16
 * Class External Payment Id - Payment Id structure.
17
 */
18
class ExtPaymentIdRequest implements BuilderInterface
19
{
20
    /**
21
     * @var string
22
     */
23
    public const GETNET_PAYMENT_ID = 'payment_id';
24
25
    /**
26
     * Build.
27
     *
28
     * @param array $buildSubject
29
     */
30
    public function build(array $buildSubject)
31
    {
32
        if (!isset($buildSubject['payment'])
33
        || !$buildSubject['payment'] instanceof PaymentDataObjectInterface
34
        ) {
35
            throw new InvalidArgumentException('Payment data object should be provided');
36
        }
37
38
        $paymentDO = $buildSubject['payment'];
39
40
        $payment = $paymentDO->getPayment();
41
42
        return [
43
            self::GETNET_PAYMENT_ID => $payment->getLastTransId(),
44
        ];
45
    }
46
}
47