PluginProbe
YayMail – WooCommerce Email Customizer / 3.3
YayMail – WooCommerce Email Customizer v3.3
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 / includes / License / LicenseAPI.php

LicenseAPI.php in YayMail – WooCommerce Email Customizer 3.3, at includes/License/LicenseAPI.php

114 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMail\License;
4
5 defined( 'ABSPATH' ) || exit;
6
7 class LicenseAPI {
8 public static function activate_license( $item_id, $license_key ) {
9 try {
10 $response = wp_remote_get( YAYCOMMERCE_SELLER_SITE_URL . '?edd_action=activate_license&item_id=' . $item_id . '&license=' . $license_key . '&url=' . home_url() );
11
12 $response = json_decode( $response['body'] );
13
14 if ( $response->success ) {
15 return array(
16 'success' => true,
17 'expires' => $response->expires,
18 'license_limit' => $response->license_limit,
19 'payment_id' => $response->payment_id,
20 'customer_name' => $response->customer_name,
21 );
22 }
23 return array(
24 'success' => false,
25 'message' => $response->error,
26 );
27 } catch ( \Error $error ) {
28 return array(
29 'success' => false,
30 'message' => 'server_error',
31 );
32 }
33 }
34
35 public static function check_license( $item_id, $license_key ) {
36 try {
37 $response = wp_remote_get( YAYCOMMERCE_SELLER_SITE_URL . '?edd_action=check_license&item_id=' . $item_id . '&license=' . $license_key . '&url=' . home_url() );
38
39 $response = json_decode( $response['body'] );
40
41 if ( true === $response->success ) {
42 if ( 'valid' === $response->license || 'expired' === $response->license ) {
43 return array(
44 'success' => true,
45 'expires' => $response->expires,
46 'license_limit' => $response->license_limit,
47 'payment_id' => $response->payment_id,
48 'customer_name' => $response->customer_name,
49 );
50 }
51 }
52 return array(
53 'success' => false,
54 );
55 } catch ( \Error $error ) {
56 return array(
57 'success' => false,
58 'is_server_error' => true,
59 );
60 }
61 }
62
63 public static function get_version( $item_id, $license_key = null ) {
64 try {
65 $api_url = YAYCOMMERCE_SELLER_SITE_URL . '?edd_action=get_version&item_id=' . $item_id;
66 if ( ! empty( $license_key ) ) {
67 $api_url .= '&license=' . $license_key;
68 }
69 $response = wp_remote_get( $api_url );
70 $response = json_decode( $response['body'] );
71 if ( isset( $response->new_version ) ) {
72 return (array) $response;
73 }
74 return false;
75 } catch ( \Error $error ) {
76 return false;
77 }
78 }
79
80 public static function get_error_message( $message ) {
81 $result = '';
82 switch ( $message ) {
83 case 'missing':
84 $result = "License doesn't exist";
85 break;
86 case 'license_not_activable':
87 $result = "Attempting to activate a bundle's parent license";
88 break;
89 case 'disabled':
90 $result = 'License key revoked';
91 break;
92 case 'no_activations_left':
93 $result = 'No activations left';
94 break;
95 case 'expired':
96 $result = 'License has expired';
97 break;
98 case 'key_mismatch':
99 $result = 'License is not valid for this product';
100 break;
101 case 'item_name_mismatch':
102 $result = 'License is not valid for this product';
103 break;
104 case 'server_error':
105 $result = 'Your license could not be activated because of server error.';
106 break;
107 default:
108 $result = 'Your license could not be activated.';
109 break;
110 }
111 return $result;
112 }
113 }
114