Total Complexity | 6 |
Total Lines | 82 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | abstract class AbstractRequest |
||
8 | { |
||
9 | /** @var string */ |
||
10 | const REQUEST_URL = Monetico::MAIN_REQUEST_URL; |
||
11 | |||
12 | /** @var string */ |
||
13 | const REQUEST_URI = ''; |
||
14 | |||
15 | /** |
||
16 | * @param string $securityKey |
||
17 | * @param array $fields |
||
18 | * @return string |
||
19 | */ |
||
20 | public function generateSeal(string $securityKey, array $fields): string |
||
21 | { |
||
22 | ksort($fields); |
||
23 | |||
24 | $query = http_build_query($fields, null, '*'); |
||
25 | $query = urldecode($query); |
||
26 | |||
27 | return strtoupper(hash_hmac( |
||
28 | 'sha1', |
||
29 | $query, |
||
30 | $securityKey |
||
31 | )); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @param string $seal |
||
36 | * @param array $fields |
||
37 | * @return array |
||
38 | */ |
||
39 | public function generateFields(string $seal, array $fields): array |
||
40 | { |
||
41 | return array_merge( |
||
42 | $fields, |
||
43 | ['MAC' => $seal] |
||
44 | ); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @return string |
||
49 | */ |
||
50 | protected function getRequestUrl(): string |
||
51 | { |
||
52 | return self::REQUEST_URL; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @return string |
||
57 | */ |
||
58 | protected function getRequestUri(): string |
||
59 | { |
||
60 | return self::REQUEST_URI; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @param bool $testMode |
||
65 | * @return string |
||
66 | */ |
||
67 | public function getUrl(bool $testMode = false): string |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @return bool |
||
79 | */ |
||
80 | abstract public function validate(): bool; |
||
81 | |||
82 | /** |
||
83 | * @param string $eptCode |
||
84 | * @param string $companyCode |
||
85 | * @param string $version |
||
86 | * @return array |
||
87 | */ |
||
88 | abstract public function fieldsToArray(string $eptCode, string $companyCode, string $version): array; |
||
89 | } |
||
90 |