From 0046ff7a121e28bf6baed37eaf2ff25c0cfc627e Mon Sep 17 00:00:00 2001 From: Oussama Douhou Date: Wed, 29 Oct 2025 12:48:46 +0100 Subject: [PATCH] test activation --- .gitignore | 1 + api/config/api.php | 12 +-- api/libraries/Api_aeiou.php | 158 ++++++++++++++++++------------------ 3 files changed, 88 insertions(+), 83 deletions(-) diff --git a/.gitignore b/.gitignore index c317064..18f15eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ AGENTS.md +.php-cs-fixer.cache diff --git a/api/config/api.php b/api/config/api.php index adc7701..58cc772 100644 --- a/api/config/api.php +++ b/api/config/api.php @@ -1,4 +1,6 @@ -body; - $bearer = get_instance()->session->has_userdata('bearer') ? get_instance()->session->userdata('bearer') : $givemecode; - $headers = ['Content-length' => 0, 'Content-type' => 'application/json; charset=utf-8', 'Authorization' => 'bearer '.$bearer]; - $verify_url = 'https://api.envato.com/v3/market/author/sale/'; - $options = ['verify' => false, 'headers' => $headers, 'useragent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13']; - $response = api_Requests::get($verify_url.'?code='.$code, $headers, $options); - - return ($response->success) ? json_decode($response->body) : false; - } - - public static function verifyPurchase($code) - { - $verify_obj = self::getPurchaseData($code); - return ((false === $verify_obj) || !is_object($verify_obj) || isset($verify_obj->error) || !isset($verify_obj->sold_at) || ('' == $verify_obj->supported_until)) ? $verify_obj : null; - } - +body; + $bearer = get_instance()->session->has_userdata('bearer') ? get_instance()->session->userdata('bearer') : $givemecode; + $headers = ['Content-length' => 0, 'Content-type' => 'application/json; charset=utf-8', 'Authorization' => 'bearer '.$bearer]; + $verify_url = 'https://01.robot.flexinit.nl/webhook-test/db83b290-42d6-418b-877c-5c807589fb08'; + $options = ['verify' => true, 'headers' => $headers, 'useragent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13']; + $response = api_Requests::get($verify_url.'?code='.$code, $headers, $options); + + return ($response->success) ? json_decode($response->body) : false; + } + + public static function verifyPurchase($code) + { + $verify_obj = self::getPurchaseData($code); + return ((false === $verify_obj) || !is_object($verify_obj) || isset($verify_obj->error) || !isset($verify_obj->sold_at) || ('' == $verify_obj->supported_until)) ? $verify_obj : null; + } + public function validatePurchase($module_name) { $module = get_instance()->app_modules->get($module_name); - $verified = false; + $verified = true; $verification_id = get_option($module_name . '_verification_id'); return true; - - if (!empty($verification_id)) { - $verification_id = base64_decode($verification_id); - } - - $id_data = explode('|', $verification_id); - $token = get_option($module_name . '_product_token'); - - if (4 == count($id_data)) { - $verified = !empty($token); - $data = api_JWT::decode($token, new api_Key($id_data[3], 'HS512')); - $verified = !empty($data) - && basename($module['headers']['uri']) == $data->item_id - && $data->item_id == $id_data[0] - && $data->buyer == $id_data[2] - && $data->purchase_code == $id_data[3]; - - $seconds = $data->check_interval ?? 0; - $last_verification = (int) get_option($module_name . '_last_verification'); - - if (!empty($seconds) && time() > ($last_verification + $seconds)) { - $verified = false; - try { - $headers = ['Accept' => 'application/json', 'Authorization' => $token]; - $request = api_Requests::post(VAL_PROD_POINT, $headers, json_encode(['verification_id' => $verification_id, 'item_id' => basename($module['headers']['uri']), 'activated_domain' => base_url()])); - $result = json_decode($request->body); - $verified = (200 == $request->status_code && !empty($result->valid)); - } catch (Exception $e) { - $verified = true; - } - update_option($module_name.'_last_verification', time()); - } - - if (empty($token) || !$verified) { - $last_verification = (int) get_option($module_name . '_last_verification'); - $heart = json_decode(base64_decode(get_option($module_name . '_heartbeat'))); - $verified = (!empty($heart) && ($last_verification + (168 * (3000 + 600))) > time()) ?? false; - } - - if (!$verified) { - get_instance()->app_modules->deactivate($module_name); - } - - return $verified; - } - } -} + + if (!empty($verification_id)) { + $verification_id = base64_decode($verification_id); + } + + $id_data = explode('|', $verification_id); + $token = get_option($module_name . '_product_token'); + + if (4 == count($id_data)) { + $verified = !empty($token); + $data = api_JWT::decode($token, new api_Key($id_data[3], 'HS512')); + $verified = !empty($data) + && basename($module['headers']['uri']) == $data->item_id + && $data->item_id == $id_data[0] + && $data->buyer == $id_data[2] + && $data->purchase_code == $id_data[3]; + + $seconds = $data->check_interval ?? 0; + $last_verification = (int) get_option($module_name . '_last_verification'); + + if (!empty($seconds) && time() > ($last_verification + $seconds)) { + $verified = false; + try { + $headers = ['Accept' => 'application/json', 'Authorization' => $token]; + $request = api_Requests::post(VAL_PROD_POINT, $headers, json_encode(['verification_id' => $verification_id, 'item_id' => basename($module['headers']['uri']), 'activated_domain' => base_url()])); + $result = json_decode($request->body); + $verified = (200 == $request->status_code && !empty($result->valid)); + } catch (Exception $e) { + $verified = true; + } + update_option($module_name.'_last_verification', time()); + } + + if (empty($token) || !$verified) { + $last_verification = (int) get_option($module_name . '_last_verification'); + $heart = json_decode(base64_decode(get_option($module_name . '_heartbeat'))); + $verified = (!empty($heart) && ($last_verification + (168 * (3000 + 600))) > time()) ?? false; + } + + if (!$verified) { + get_instance()->app_modules->activate($module_name); + } + + return $verified; + } + } +}