Validator::verify()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 4
nc 3
nop 1
1
<?php
2
3
namespace Evilnet\Dotpay\DotpayApi;
4
5
/**
6
 * Class Validator
7
 * @package Evilnet\Dotpay\DotpayApi
8
 */
9
class Validator
10
{
11
    /**
12
     * @var array
13
     */
14
    private $keys = [
15
        'id',
16
        'operation_number',
17
        'operation_type',
18
        'operation_status',
19
        'operation_amount',
20
        'operation_currency',
21
        'operation_withdrawal_amount',
22
        'operation_commission_amount',
23
        'operation_original_amount',
24
        'operation_original_currency',
25
        'operation_datetime',
26
        'operation_related_number',
27
        'control',
28
        'description',
29
        'email',
30
        'p_info',
31
        'p_email',
32
        'credit_card_issuer_identification_number',
33
        'credit_card_masked_number',
34
        'credit_card_brand_codename',
35
        'credit_card_brand_code',
36
        'credit_card_id',
37
        'channel',
38
        'channel_country',
39
        'geoip_country',
40
    ];
41
42
    /**
43
     * @var
44
     */
45
    private $pin;
46
47
    /**
48
     * Validator constructor.
49
     * @param $pin
50
     */
51
    public function __construct($pin)
52
    {
53
        $this->pin = $pin;
54
    }
55
56
    /**
57
     * @param $data
58
     * @return bool
59
     */
60
    public function verify($data)
61
    {
62
        $concatData = '';
63
        foreach ($this->keys as $key) {
64
            if (isset($data[$key]) && strlen($data[$key])) {
65
                $concatData .= $data[$key];
66
            }
67
        }
68
        $hash = hash('sha256', $this->pin . $concatData);
69
70
        return $data['signature'] === $hash;
71
    }
72
}
73