Passed
Pull Request — master (#36)
by
unknown
04:47
created

CaptureRequest::build()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 14
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 25
rs 9.7998
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
use Magento\Sales\Api\Data\OrderPaymentInterface;
12
13
class CaptureRequest implements BuilderInterface
14
{
15
    /**
16
     * @var ConfigInterface
17
     */
18
    private $config;
19
20
    /**
21
     * @param ConfigInterface $config
22
     */
23
    public function __construct(
24
        ConfigInterface $config
25
    ) {
26
        $this->config = $config;
27
    }
28
29
    /**
30
     * Builds ENV request
31
     *
32
     * @param array $buildSubject
33
     * @return array
34
     */
35
    public function build(array $buildSubject)
36
    {
37
        if (!isset($buildSubject['payment'])
38
            || !$buildSubject['payment'] instanceof PaymentDataObjectInterface
39
        ) {
40
            throw new \InvalidArgumentException('Payment data object should be provided');
41
        }
42
43
        /** @var PaymentDataObjectInterface $paymentDO */
44
        $paymentDO = $buildSubject['payment'];
45
46
        $order = $paymentDO->getOrder();
47
48
        $payment = $paymentDO->getPayment();
49
50
        if (!$payment instanceof OrderPaymentInterface) {
51
            throw new \LogicException('Order payment should be provided.');
52
        }
53
54
        return [
55
            'TXN_TYPE' => 'S',
56
            'TXN_ID' => $payment->getLastTransId(),
57
            'MERCHANT_KEY' => $this->config->getValue(
58
                'merchant_gateway_key',
59
                $order->getStoreId()
60
            )
61
        ];
62
    }
63
}
64