PluginProbe
YayMail – WooCommerce Email Customizer / trunk
YayMail – WooCommerce Email Customizer vtrunk
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
yaymail / vendor-prefixed / src / License / LicenseAPI.php

LicenseAPI.php in YayMail – WooCommerce Email Customizer trunk, at vendor-prefixed/src/License/LicenseAPI.php

87 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMailScoped\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 */
12 class LicenseAPI
13 {
14 public static function activate_license(string $store_url, int $item_id, string $license_key): array
15 {
16 try {
17 $url = $store_url . '?edd_action=activate_license&item_id=' . $item_id . '&license=' . rawurlencode($license_key) . '&url=' . home_url();
18 $raw = wp_remote_get($url);
19 if (is_wp_error($raw)) {
20 throw new \Error('WP HTTP error', 1);
21 }
22 $response = json_decode(wp_remote_retrieve_body($raw));
23 if (isset($response->success) && $response->success) {
24 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 ?? ''];
25 }
26 return ['success' => \false, 'message' => $response->error ?? 'unknown_error'];
27 } catch (\Error $error) {
28 return ['success' => \false, 'message' => 'server_error', 'is_server_error' => \true];
29 }
30 }
31 public static function deactivate_license(string $store_url, int $item_id, string $license_key): array
32 {
33 try {
34 $url = $store_url . '?edd_action=deactivate_license&item_id=' . $item_id . '&license=' . rawurlencode($license_key) . '&url=' . home_url();
35 $raw = wp_remote_get($url);
36 if (is_wp_error($raw)) {
37 return ['success' => \false, 'is_server_error' => \true];
38 }
39 $response = json_decode(wp_remote_retrieve_body($raw));
40 return ['success' => isset($response->success) && $response->success, 'license' => $response->license ?? 'deactivated'];
41 } catch (\Error $error) {
42 return ['success' => \false, 'is_server_error' => \true];
43 }
44 }
45 public static function check_license(string $store_url, int $item_id, $license_key): array
46 {
47 try {
48 $url = $store_url . '?edd_action=check_license&item_id=' . $item_id . '&license=' . rawurlencode((string) $license_key) . '&url=' . home_url();
49 $raw = wp_remote_get($url);
50 if (is_wp_error($raw)) {
51 throw new \Error('WP HTTP error', 1);
52 }
53 $response = json_decode(wp_remote_retrieve_body($raw));
54 if (isset($response->success) && \true === $response->success) {
55 if ('valid' === $response->license || 'expired' === $response->license) {
56 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 ?? ''];
57 }
58 }
59 return ['success' => \false];
60 } catch (\Error $error) {
61 return ['success' => \false, 'is_server_error' => \true];
62 }
63 }
64 public static function get_version(string $store_url, int $item_id, ?string $license_key = null)
65 {
66 try {
67 $url = $store_url . '?edd_action=get_version&item_id=' . $item_id;
68 if (!empty($license_key)) {
69 $url .= '&license=' . rawurlencode($license_key);
70 }
71 $raw = wp_remote_get($url);
72 $response = json_decode(wp_remote_retrieve_body($raw));
73 if (isset($response->new_version)) {
74 return (array) $response;
75 }
76 return \false;
77 } catch (\Error $error) {
78 return \false;
79 }
80 }
81 public static function get_error_message(string $message): string
82 {
83 $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.'];
84 return $messages[$message] ?? 'Your license could not be activated.';
85 }
86 }
87