Passed
Pull Request — master (#37)
by
unknown
04:35
created

TxnIdHandler::handle()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 16
rs 10
1
<?php
2
/**
3
 * Copyright © 2016 Magento. All rights reserved.
4
 * See COPYING.txt for license details.
5
 */
6
namespace Pagantis\Pagantis\Gateway\Response;
7
8
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
9
use Magento\Payment\Gateway\Response\HandlerInterface;
10
11
class TxnIdHandler implements HandlerInterface
12
{
13
    const TXN_ID = 'TXN_ID';
14
15
    /**
16
     * Handles transaction id
17
     *
18
     * @param array $handlingSubject
19
     * @param array $response
20
     * @return void
21
     */
22
    public function handle(array $handlingSubject, array $response)
23
    {
24
        if (!isset($handlingSubject['payment'])
25
            || !$handlingSubject['payment'] instanceof PaymentDataObjectInterface
26
        ) {
27
            throw new \InvalidArgumentException('Payment data object should be provided');
28
        }
29
30
        /** @var PaymentDataObjectInterface $paymentDO */
31
        $paymentDO = $handlingSubject['payment'];
32
33
        $payment = $paymentDO->getPayment();
34
35
        /** @var $payment \Magento\Sales\Model\Order\Payment */
36
        $payment->setTransactionId($response[self::TXN_ID]);
37
        $payment->setIsTransactionClosed(false);
38
    }
39
}
40