B2binpayCallbackModuleFrontController   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B postProcess() 0 49 9
A getStatus() 0 9 1
1
<?php
2
/**
3
 * NOTICE OF LICENSE
4
 *
5
 * Copyright (c) 2019 B2BinPay
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in all
15
 * copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
 * SOFTWARE.
24
 *
25
 *  @author    B2BINPAY <[email protected]>
26
 *  @copyright 2019 B2BinPay
27
 *  @license   https://github.com/b2binpay/prestashop/blob/master/LICENSE  The MIT License (MIT)
28
 */
29
30
class B2binpayCallbackModuleFrontController extends ModuleFrontController
0 ignored issues
show
Bug introduced by
The type ModuleFrontController 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...
31
{
32
    public function postProcess()
33
    {
34
        if (Tools::isSubmit('tracking_id') == false
0 ignored issues
show
Bug introduced by
The type Tools 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...
35
            || Tools::isSubmit('status') == false
36
            || Tools::isSubmit('amount') == false
37
            || Tools::isSubmit('actual_amount') == false
38
        ) {
39
            header('HTTP/1.1 400 Bad Request');
40
            exit();
41
        }
42
43
        $headers = getallheaders();
44
        $b2binpay_auth = $this->module->provider->getAuthorization();
45
46
        if (empty($headers['Authorization']) || ($headers['Authorization'] !== $b2binpay_auth)) {
47
            header('HTTP/1.1 401 Unauthorized');
48
            exit();
49
        }
50
51
        $tracking_id = Tools::getValue('tracking_id');
52
        $status = (string)Tools::getValue('status');
53
54
        $cart = new Cart((int)$tracking_id);
0 ignored issues
show
Bug introduced by
The type Cart 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...
55
        $order = Order::getByCartId((int)$cart->id);
0 ignored issues
show
Bug introduced by
The type Order 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...
56
57
        $status_list = $this->getStatus();
58
59
        $amount = Tools::getValue('amount');
60
        $actual_amount = Tools::getValue('actual_amount');
61
62
        $history = new OrderHistory();
0 ignored issues
show
Bug introduced by
The type OrderHistory 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...
63
        $history->id_order = $order->id;
64
65
        if (($status === '2') && ($amount === $actual_amount)) {
66
            $payment_status = Configuration::get('PS_OS_PAYMENT');
0 ignored issues
show
Bug introduced by
The type Configuration 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...
67
        } else {
68
            $payment_status = $status_list[$status];
69
        }
70
71
        $history->changeIdOrderState(
72
            $payment_status,
73
            $order,
74
            true
75
        );
76
77
        $history->add();
78
        $order->save();
79
80
        exit("OK");
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
81
    }
82
83
    private function getStatus()
84
    {
85
        return array(
86
            '-2' => Configuration::get('PS_OS_ERROR'),
87
            '-1' => Configuration::get('PS_OS_ERROR'),
88
            '1' => Configuration::get('PS_OS_BANKWIRE'),
89
            '2' => Configuration::get('PS_OS_BANKWIRE'),
90
            '3' => Configuration::get('PS_OS_ERROR'),
91
            '4' => Configuration::get('PS_OS_PAYMENT'),
92
        );
93
    }
94
}
95