1 | <?php |
||
2 | |||
3 | namespace BPT\receiver; |
||
4 | use BPT\BPT; |
||
5 | use BPT\constants\callbackTypes; |
||
6 | use BPT\constants\codecAction; |
||
7 | use BPT\pay\crypto; |
||
8 | use BPT\settings; |
||
9 | use BPT\tools\tools; |
||
10 | |||
11 | class callback { |
||
12 | public static function encodeData (array $data): string { |
||
13 | return tools::codec(codecAction::ENCRYPT, json_encode($data), md5(settings::$token), 'SguQgUvvKRLvmCyq')['hash']; |
||
14 | } |
||
15 | |||
16 | public static function decodeData (string $data): array { |
||
17 | return json_decode(tools::codec(codecAction::DECRYPT, $data, md5(settings::$token), 'SguQgUvvKRLvmCyq'), true); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
18 | } |
||
19 | |||
20 | /** |
||
21 | * @internal Only for BPT self usage , Don't use it in your source! |
||
22 | */ |
||
23 | public static function process () { |
||
24 | if (!settings::$handler || settings::$receiver != \BPT\constants\receiver::WEBHOOK || settings::$multi || !(isset($_GET['data']) || isset($_POST['data']))) { |
||
25 | return false; |
||
26 | } |
||
27 | |||
28 | $input = $_GET['data'] ?? $_POST['data']; |
||
29 | |||
30 | if (!($data = self::decodeData($input))) { |
||
31 | return false; |
||
32 | } |
||
33 | |||
34 | if (!is_array($data)) { |
||
0 ignored issues
–
show
|
|||
35 | return false; |
||
36 | } |
||
37 | |||
38 | if ($data['type'] === callbackTypes::CRYPTO) { |
||
39 | return crypto::callbackProcess($data); |
||
40 | } |
||
41 | |||
42 | return false; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @internal Only for BPT self usage , Don't use it in your source! |
||
47 | */ |
||
48 | public static function callHandler (string $handler_name, $input) { |
||
49 | if (method_exists(BPT::$handler, $handler_name)) { |
||
50 | BPT::$handler->$handler_name($input); |
||
51 | } |
||
52 | } |
||
53 | } |