PluginProbe ʕ •ᴥ•ʔ
WP Chat App / trunk
WP Chat App vtrunk
3.8.1 3.8.2 trunk 2.6 3.4 3.4.1 3.4.2 3.4.4 3.4.5 3.4.6 3.5 3.6 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.6.9 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0
wp-whatsapp / vendor-prefixed / src / License / LicenseAPI.php
wp-whatsapp / vendor-prefixed / src / License Last commit date
Contracts 4 months ago EDD_SL_Plugin_Updater.php 4 months ago License.php 4 months ago LicenseAPI.php 4 months ago LicenseHandler.php 3 months ago PluginInfoFactory.php 4 months ago RestAPI.php 4 months ago
LicenseAPI.php
88 lines
1 <?php
2
3 namespace WhatsappScoped\YayCommerce\AdminShell\License;
4
5 \defined('ABSPATH') || exit;
6 /**
7 * EDD HTTP client — all calls go through wp_remote_get.
8 *
9 * Ported from YayMail Pro LicenseAPI.php — YAYCOMMERCE_SELLER_SITE_URL constant
10 * replaced with $store_url parameter sourced from LicenseConfigAdapter::get_store_url().
11 * @internal
12 */
13 class LicenseAPI
14 {
15 public static function activate_license(string $store_url, int $item_id, string $license_key) : array
16 {
17 try {
18 $url = $store_url . '?edd_action=activate_license&item_id=' . $item_id . '&license=' . \rawurlencode($license_key) . '&url=' . \home_url();
19 $raw = wp_remote_get($url);
20 if (is_wp_error($raw)) {
21 throw new \Error('WP HTTP error', 1);
22 }
23 $response = \json_decode(wp_remote_retrieve_body($raw));
24 if (isset($response->success) && $response->success) {
25 return ['success' => \true, 'license' => $response->license ?? 'valid', 'expires' => $response->expires ?? null, 'license_limit' => $response->license_limit ?? 0, 'payment_id' => $response->payment_id ?? '', 'customer_name' => $response->customer_name ?? ''];
26 }
27 return ['success' => \false, 'message' => $response->error ?? 'unknown_error'];
28 } catch (\Error $error) {
29 return ['success' => \false, 'message' => 'server_error', 'is_server_error' => \true];
30 }
31 }
32 public static function deactivate_license(string $store_url, int $item_id, string $license_key) : array
33 {
34 try {
35 $url = $store_url . '?edd_action=deactivate_license&item_id=' . $item_id . '&license=' . \rawurlencode($license_key) . '&url=' . \home_url();
36 $raw = wp_remote_get($url);
37 if (is_wp_error($raw)) {
38 return ['success' => \false, 'is_server_error' => \true];
39 }
40 $response = \json_decode(wp_remote_retrieve_body($raw));
41 return ['success' => isset($response->success) && $response->success, 'license' => $response->license ?? 'deactivated'];
42 } catch (\Error $error) {
43 return ['success' => \false, 'is_server_error' => \true];
44 }
45 }
46 public static function check_license(string $store_url, int $item_id, $license_key) : array
47 {
48 try {
49 $url = $store_url . '?edd_action=check_license&item_id=' . $item_id . '&license=' . \rawurlencode((string) $license_key) . '&url=' . \home_url();
50 $raw = wp_remote_get($url);
51 if (is_wp_error($raw)) {
52 throw new \Error('WP HTTP error', 1);
53 }
54 $response = \json_decode(wp_remote_retrieve_body($raw));
55 if (isset($response->success) && \true === $response->success) {
56 if ('valid' === $response->license || 'expired' === $response->license) {
57 return ['success' => \true, 'license' => $response->license, 'expires' => $response->expires ?? null, 'license_limit' => $response->license_limit ?? 0, 'payment_id' => $response->payment_id ?? '', 'customer_name' => $response->customer_name ?? ''];
58 }
59 }
60 return ['success' => \false];
61 } catch (\Error $error) {
62 return ['success' => \false, 'is_server_error' => \true];
63 }
64 }
65 public static function get_version(string $store_url, int $item_id, ?string $license_key = null)
66 {
67 try {
68 $url = $store_url . '?edd_action=get_version&item_id=' . $item_id;
69 if (!empty($license_key)) {
70 $url .= '&license=' . \rawurlencode($license_key);
71 }
72 $raw = wp_remote_get($url);
73 $response = \json_decode(wp_remote_retrieve_body($raw));
74 if (isset($response->new_version)) {
75 return (array) $response;
76 }
77 return \false;
78 } catch (\Error $error) {
79 return \false;
80 }
81 }
82 public static function get_error_message(string $message) : string
83 {
84 $messages = ['missing' => "License doesn't exist", 'license_not_activable' => "Attempting to activate a bundle's parent license", 'disabled' => 'License key revoked', 'no_activations_left' => 'No activations left', 'expired' => 'License has expired', 'key_mismatch' => 'License is not valid for this product', 'item_name_mismatch' => 'License is not valid for this product', 'server_error' => 'Your license could not be activated because of server error.'];
85 return $messages[$message] ?? 'Your license could not be activated.';
86 }
87 }
88