Total Complexity | 5 |
Total Lines | 76 |
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 | /** |
||
13 | * @param string $securityKey |
||
14 | * @param array $fields |
||
15 | * @return string |
||
16 | */ |
||
17 | public function generateSeal(string $securityKey, array $fields): string |
||
18 | { |
||
19 | ksort($fields); |
||
20 | |||
21 | $query = http_build_query($fields, null, '*'); |
||
22 | $query = urldecode($query); |
||
23 | |||
24 | return strtoupper(hash_hmac( |
||
25 | 'sha1', |
||
26 | $query, |
||
27 | $securityKey |
||
28 | )); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * @param string $seal |
||
33 | * @param array $fields |
||
34 | * @return array |
||
35 | */ |
||
36 | public function generateFields(string $seal, array $fields): array |
||
37 | { |
||
38 | return array_merge( |
||
39 | $fields, |
||
40 | ['MAC' => $seal] |
||
41 | ); |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @return string |
||
46 | */ |
||
47 | protected static function getRequestUrl(): string |
||
48 | { |
||
49 | return self::REQUEST_URL; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | */ |
||
55 | abstract protected static function getRequestUri(): string; |
||
56 | |||
57 | /** |
||
58 | * @param bool $testMode |
||
59 | * @return string |
||
60 | */ |
||
61 | public static function getUrl(bool $testMode = false): string |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @return bool |
||
73 | */ |
||
74 | abstract public function validate(): bool; |
||
75 | |||
76 | /** |
||
77 | * @param string $eptCode |
||
78 | * @param string $companyCode |
||
79 | * @param string $version |
||
80 | * @return array |
||
81 | */ |
||
82 | abstract public function fieldsToArray(string $eptCode, string $companyCode, string $version): array; |
||
83 | } |
||
84 |