-
Notifications
You must be signed in to change notification settings - Fork 34
/
class.verify-purchase.php
60 lines (47 loc) · 2.01 KB
/
class.verify-purchase.php
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
<?php
class EnvatoApi2 {
// Bearer, no need for OAUTH token, change this to your bearer string
// https://build.envato.com/api/#token
private static $bearer = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // replace the API key here.
static function getPurchaseData( $code ) {
//setting the header for the rest of the api
$bearer = 'bearer ' . self::$bearer;
$header = array();
$header[] = 'Content-length: 0';
$header[] = 'Content-type: application/json; charset=utf-8';
$header[] = 'Authorization: ' . $bearer;
$verify_url = 'https://api.envato.com/v3/market/author/sale/';
$ch_verify = curl_init( $verify_url . '?code=' . $code );
curl_setopt( $ch_verify, CURLOPT_HTTPHEADER, $header );
curl_setopt( $ch_verify, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch_verify, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch_verify, CURLOPT_CONNECTTIMEOUT, 5 );
curl_setopt( $ch_verify, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$cinit_verify_data = curl_exec( $ch_verify );
curl_close( $ch_verify );
if ($cinit_verify_data != "")
return json_decode($cinit_verify_data);
else
return false;
}
static function verifyPurchase( $code ) {
$verify_obj = self::getPurchaseData($code);
// Check for correct verify code
if (
(false === $verify_obj) ||
!is_object($verify_obj) ||
isset($verify_obj->error) ||
!isset($verify_obj->sold_at)
)
return -1;
// If empty or date present, then it's valid
if (
$verify_obj->supported_until == "" ||
$verify_obj->supported_until != null
)
return $verify_obj;
// Null or something non-string value, thus support period over
return 0;
}
}
?>