RefundHandler::handle()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 11
c 1
b 0
f 0
nc 5
nop 2
dl 0
loc 20
rs 9.6111
1
<?php
2
/**
3
 * Copyright © Wirecard Brasil. All rights reserved.
4
 *
5
 * @author    Bruno Elisei <[email protected]>
6
 * See COPYING.txt for license details.
7
 */
8
9
namespace Moip\Magento2\Gateway\Response;
10
11
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Payment\Gateway\...mentDataObjectInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Magento\Payment\Gateway\Response\HandlerInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Payment\Gateway\Response\HandlerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Magento\Sales\Model\Order\Creditmemo;
0 ignored issues
show
Bug introduced by
The type Magento\Sales\Model\Order\Creditmemo was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
15
/**
16
 * Class AcceptPaymentHandler - Deals reading responses for refunded payment authorization.
17
 */
18
class RefundHandler implements HandlerInterface
19
{
20
    /**
21
     * @const TXN ID
22
     */
23
    const TXN_ID = 'TXN_ID';
24
25
    /**
26
     * Handles.
27
     *
28
     * @param array $handlingSubject
29
     * @param array $response
30
     */
31
    public function handle(array $handlingSubject, array $response)
32
    {
33
        if (!isset($handlingSubject['payment'])
34
            || !$handlingSubject['payment'] instanceof PaymentDataObjectInterface
35
        ) {
36
            throw new \InvalidArgumentException('Payment data object should be provided');
37
        }
38
39
        $paymentDO = $handlingSubject['payment'];
40
        $payment = $paymentDO->getPayment();
41
42
        $payment->setTransactionId($response['REFUND_ID']);
43
44
        if ($response['STATUS'] === 'REQUESTED') {
45
            $creditmemo = $payment->getCreditmemo();
46
            $creditmemo->setState(Creditmemo::STATE_OPEN);
47
        }
48
49
        if ($response['RESULT_CODE']) {
50
            $paymentDO->getPayment();
51
        }
52
    }
53
}
54