Test Failed
Push — master ( 74331d...6be589 )
by Alexey
04:30
created

Paykeeper::goToMerchant()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
nc 1
nop 6
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Merchant helper Paykeeper
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
12
namespace Money\MerchantHelper;
13
14
15
class Paykeeper extends \Money\MerchantHelper {
16
17
    public static function goToMerchant($payId, $amount, $currency, $description = '', $success = '/', $false = '/') {
18
        $config = static::getConfig();
19
        # предполагаются заранее известными значения переменных
20
        # $client_login, $order_id, $order_sum и $optional_phone
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
21
22
        $payment_parameters = http_build_query(array(
23
            "clientid" => \Users\User::$cur->id,
24
            "orderid" => $payId,
25
            "sum" => $amount,
26
            //"phone" => $optional_phone
27
        ));
28
        $options = array("http" => array(
29
            "method" => "POST",
30
            "header" =>
31
                "Content-type: application/x-www-form-urlencoded",
32
            "content" => $payment_parameters
33
        ));
34
        $context = stream_context_create($options);
35
        echo "<style>.tmg {margin:0 auto}</style>";
36
        echo file_get_contents("http://{$config['domain']}.paykeeper.ru/order/inline/", FALSE, $context);
37
38
    }
39
40
    public static function reciver($data, $status) {
41
        $config = static::getConfig();
42
        $result = [];
43
        $result['status'] = 'error';
44
45
        $secret_seed = $config['secret'];
46
        $id = $_POST['id'];
47
        $sum = $_POST['sum'];
48
        $clientid = $_POST['clientid'];
49
        $orderid = $_POST['orderid'];
50
        $key = $_POST['key'];
51
52
        if ($key != md5($id . sprintf("%.2lf", $sum) .
53
                $clientid . $orderid . $secret_seed)
54
        ) {
55
            $result['callback'] = 'Error! Hash mismatch';
56
            return $result;
57
        }
58
59
        if ($orderid == "") {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
60
            # Платёж – пополнение счёта, нужно зачислить   деньги на баланс $clientid
61
            # ...
62
        } else {
63
            $result['payId'] = $data["orderid"];
64
            $result['status'] = 'success';
65
        }
66
        $result['callback'] = "OK " . md5($id . $secret_seed);
67
68
69
        return $result;
70
    }
71
}