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