-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathEnvatoPurchaseCodeVerifier.php
64 lines (53 loc) · 1.81 KB
/
EnvatoPurchaseCodeVerifier.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
61
62
63
64
<?php
/**
* PHP version 5.6+
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @author Joseph G. <emailnotpublic@domain.tld>
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version 0.0.1
* @link https://github.com/codehaiku/Envato-Purchase-Code-Verifier
* @since 0.0.1
*/
require_once __DIR__ . '/vendor/autoload.php';
use Curl\Curl;
final class EnvatoPurchaseCodeVerifier
{
protected $accessToken = '';
const AUTHOR_SALES_ENDPOINT_URI = 'https://api.envato.com/v3/market/author/sale';
/**
* Class constructor, pass the access token.
* @param mixed The access token <https://build.envato.com/create-token/>
*/
public function __construct($accessToken)
{
$this->accessToken = $accessToken;
}
/**
* Supply the purchase code of the buyer as argument.
* @param mixed $purchaseCode The purchase code of he buyer.
* @return mixed (Boolean) False on fail, the api (Object) $curl->response info on success.
*/
public function verified($purchaseCode)
{
if (empty($purchaseCode)) {
return false;
}
$curl = new Curl();
$curl->setHeader('Authorization', 'Bearer ' . $this->accessToken);
$curl->get(self::AUTHOR_SALES_ENDPOINT_URI, array(
'code' => $purchaseCode
));
$curl->close();
if ($curl->error) {
return false;
} else {
return $curl->response;
}
}
}