CcTransactionAuthorizationHandler   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B handle() 0 39 6
A __construct() 0 8 1
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\Response;
10
11
use Getnet\PaymentMagento\Gateway\Config\Config;
12
use Getnet\PaymentMagento\Gateway\Config\ConfigCc;
13
use InvalidArgumentException;
14
use Magento\Framework\Serialize\Serializer\Json;
15
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
16
use Magento\Payment\Gateway\Response\HandlerInterface;
17
18
/**
19
 * Cc Transaction Authorization Handler - Handles reading responses for CC on authorization.
20
 *
21
 * @SuppressWarnings(PHPCPD)
22
 */
23
class CcTransactionAuthorizationHandler implements HandlerInterface
24
{
25
    /**
26
     * Response Pay Credit - Block name.
27
     */
28
    public const CREDIT = 'credit';
29
30
    /**
31
     * Response Pay Payment Id - Block name.
32
     */
33
    public const RESPONSE_PAYMENT_ID = 'payment_id';
34
35
    /**
36
     * Response Pay Delayed - Block name.
37
     */
38
    public const RESPONSE_DELAYED = 'delayed';
39
40
    /**
41
     * Response Pay Status - Block name.
42
     */
43
    public const RESPONSE_STATUS = 'status';
44
45
    /**
46
     * Response Pay Approved - Block name.
47
     */
48
    public const RESPONSE_APPROVED = 'APPROVED';
49
50
    /**
51
     * Response Pay Authorized - Block name.
52
     */
53
    public const RESPONSE_AUTHORIZED = 'AUTHORIZED';
54
55
    /**
56
     * Response Pay Pending - Block name.
57
     */
58
    public const RESPONSE_PENDING = 'PENDING';
59
60
    /**
61
     * @var Json
62
     */
63
    private $json;
64
65
    /**
66
     * @var Config
67
     */
68
    private $config;
69
70
    /**
71
     * @var ConfigCc
72
     */
73
    private $configCc;
74
75
    /**
76
     * @param Json     $json
77
     * @param Config   $config
78
     * @param ConfigCc $configCc
79
     */
80
    public function __construct(
81
        Json $json,
82
        Config $config,
83
        ConfigCc $configCc
84
    ) {
85
        $this->json = $json;
86
        $this->config = $config;
87
        $this->configCc = $configCc;
88
    }
89
90
    /**
91
     * Handles.
92
     *
93
     * @param array $handlingSubject
94
     * @param array $response
95
     *
96
     * @return void
97
     */
98
    public function handle(array $handlingSubject, array $response)
99
    {
100
        if (!isset($handlingSubject['payment'])
101
            || !$handlingSubject['payment'] instanceof PaymentDataObjectInterface
102
        ) {
103
            throw new InvalidArgumentException('Payment data object should be provided');
104
        }
105
        $isApproved = false;
106
107
        $isDenied = true;
108
109
        $paymentDO = $handlingSubject['payment'];
110
111
        $payment = $paymentDO->getPayment();
112
113
        $order = $payment->getOrder();
114
115
        $amount = $order->getBaseGrandTotal();
116
117
        $baseAmount = $order->getGrandTotal();
118
119
        if ($response[self::RESPONSE_STATUS] === self::RESPONSE_APPROVED ||
120
            $response[self::RESPONSE_STATUS] === self::RESPONSE_AUTHORIZED ||
121
            $response[self::RESPONSE_STATUS] === self::RESPONSE_PENDING
122
        ) {
123
            $isApproved = true;
124
            $isDenied = false;
125
        }
126
127
        $payment->registerAuthorizationNotification($amount);
128
        $payment->setAmountAuthorized($amount);
129
        $payment->setBaseAmountAuthorized($baseAmount);
130
        $payment->setIsTransactionApproved($isApproved);
131
        $payment->setIsTransactionDenied($isDenied);
132
        $payment->setIsTransactionPending(true);
133
        $payment->setIsTransactionClosed(false);
134
        $payment->setTransactionId($response[self::RESPONSE_PAYMENT_ID]);
135
        $payment->setTransactionDetails($this->json->serialize($response));
136
        $payment->setAdditionalData($this->json->serialize($response));
0 ignored issues
show
Bug introduced by
The method setAdditionalData() does not exist on Magento\Payment\Model\InfoInterface. Did you maybe mean setAdditionalInformation()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

136
        $payment->/** @scrutinizer ignore-call */ 
137
                  setAdditionalData($this->json->serialize($response));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
137
    }
138
}
139