AcceptPaymentHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 39
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 26 4
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
14
/**
15
 * Class AcceptPaymentHandler - Deals reading responses for payment authorization accepted.
16
 */
17
class AcceptPaymentHandler implements HandlerInterface
18
{
19
    /**
20
     * @const TXN ID
21
     */
22
    const TXN_ID = 'TXN_ID';
23
24
    /**
25
     * Handles.
26
     *
27
     * @param array $handlingSubject
28
     * @param array $response
29
     */
30
    public function handle(array $handlingSubject, array $response)
31
    {
32
        if (!isset($handlingSubject['payment'])
33
            || !$handlingSubject['payment'] instanceof PaymentDataObjectInterface
34
        ) {
35
            throw new \InvalidArgumentException('Payment data object should be provided');
36
        }
37
38
        if ($response['RESULT_CODE']) {
39
            $paymentDO = $handlingSubject['payment'];
40
41
            $payment = $paymentDO->getPayment();
42
43
            $order = $payment->getOrder();
44
            $amount = $order->getBaseGrandTotal();
45
            $baseAmount = $order->getGrandTotal();
46
47
            $payment->registerAuthorizationNotification($amount);
48
            $payment->registerCaptureNotification($amount);
49
            $payment->setIsTransactionApproved(true);
50
            $payment->setIsTransactionDenied(false);
51
            $payment->setIsInProcess(true);
52
            $payment->setIsTransactionClosed(true);
53
54
            $payment->setAmountAuthorized($amount);
55
            $payment->setBaseAmountAuthorized($baseAmount);
56
        }
57
    }
58
}
59