wesleydeveloper /
hotmart
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Class Hotmart |
||
| 4 | * @package Wesleydeveloper\Hotmart |
||
| 5 | * @author Wesley Silva <[email protected]> |
||
| 6 | */ |
||
| 7 | |||
| 8 | |||
| 9 | namespace Wesleydeveloper\Hotmart; |
||
| 10 | |||
| 11 | |||
| 12 | use GuzzleHttp\Client; |
||
| 13 | use Wesleydeveloper\Hotmart\Support\Connect; |
||
| 14 | |||
| 15 | class Hotmart extends Connect |
||
| 16 | { |
||
| 17 | private const BASE_URI = 'https://api-hot-connect.hotmart.com/'; |
||
| 18 | |||
| 19 | private $client; |
||
| 20 | |||
| 21 | private $params; |
||
| 22 | |||
| 23 | public function __construct($config = null) |
||
| 24 | { |
||
| 25 | parent::__construct($config); |
||
| 26 | $this->params = ['headers' => ['Authorization' => "Bearer {$this->getConfig()->getAccessToken()}"]]; |
||
| 27 | $this->client = new Client(['base_uri' => self::BASE_URI]); |
||
| 28 | } |
||
| 29 | |||
| 30 | // Report |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Required parameters: startDate, endDate. |
||
| 34 | * Optional parameters: productId, statusType, email, transaction, transactionStatus, buyerName, cpf, salesNature, paymentEngine, showNotAccessed, paymentType, source, affiliateName, offerKey, orderBy, format page and rows. |
||
| 35 | * @param array|null $params |
||
| 36 | * @return mixed |
||
| 37 | */ |
||
| 38 | public function getHistory(array $params) |
||
| 39 | { |
||
| 40 | $keys = ['startDate', 'endDate']; |
||
| 41 | $params = array_filter($params); |
||
| 42 | foreach ($keys as $key) { |
||
| 43 | if (! array_key_exists($key, $params)) { |
||
| 44 | throw new InvalidArgumentException("Missing configuration key [$key]."); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 45 | } |
||
| 46 | } |
||
| 47 | $this->params['query'] = $params; |
||
| 48 | $request = $this->client->get('/reports/rest/v2/history', $this->params); |
||
| 49 | $response = json_decode($request->getBody()->getContents(), true); |
||
| 50 | |||
| 51 | return $response; |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Required parameters: startDate, endDate and transactionStatus. |
||
| 56 | * Optional parameters: productId, buyerEmail, transaction, page and rows. |
||
| 57 | * @param array $params |
||
| 58 | * @return mixed |
||
| 59 | */ |
||
| 60 | public function getPurchaseDetails(array $params) |
||
| 61 | { |
||
| 62 | $keys = ['startDate', 'endDate', 'transactionStatus']; |
||
| 63 | $params = array_filter($params); |
||
| 64 | foreach ($keys as $key) { |
||
| 65 | if (! array_key_exists($key, $params)) { |
||
| 66 | throw new InvalidArgumentException("Missing configuration key [$key]."); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | $this->params['query'] = $params; |
||
| 70 | $request = $this->client->get('/reports/rest/v2/purchaseDetails', $this->params); |
||
| 71 | $response = json_decode($request->getBody()->getContents(), true); |
||
| 72 | |||
| 73 | return $response; |
||
| 74 | } |
||
| 75 | |||
| 76 | // Affiliation |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @return mixed |
||
| 80 | */ |
||
| 81 | public function getHotlinks() |
||
| 82 | { |
||
| 83 | $request = $this->client->get('/affiliation/rest/v2/', $this->params); |
||
| 84 | $response = json_decode($request->getBody()->getContents(), true); |
||
| 85 | |||
| 86 | return $response; |
||
| 87 | } |
||
| 88 | |||
| 89 | // Product |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @param int $productId |
||
| 93 | * @return mixed |
||
| 94 | */ |
||
| 95 | public function getProduct(int $productId) |
||
| 96 | { |
||
| 97 | $request = $this->client->get("/product/rest/v2/{$productId}", $this->params); |
||
| 98 | $response = json_decode($request->getBody()->getContents(), true); |
||
| 99 | |||
| 100 | return $response; |
||
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @param int $productId |
||
| 105 | * @return mixed |
||
| 106 | */ |
||
| 107 | public function getOffersOfProduct(int $productId) |
||
| 108 | { |
||
| 109 | $request = $this->client->get("/product/rest/v2/{$productId}/offers/", $this->params); |
||
| 110 | $response = json_decode($request->getBody()->getContents(), true); |
||
| 111 | |||
| 112 | return $response; |
||
| 113 | } |
||
| 114 | |||
| 115 | // Subscription |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Optional parameters: page and rows. |
||
| 119 | * @param array|null $params |
||
| 120 | * @return mixed |
||
| 121 | */ |
||
| 122 | public function getSubscription(array $params = null, bool $var) |
||
| 123 | { |
||
| 124 | if (is_array($params)) { |
||
| 125 | $params = array_filter($params); |
||
| 126 | $this->params['query'] = $params; |
||
| 127 | } |
||
| 128 | $request = $this->client->get('/subscriber/rest/v2', $this->params); |
||
| 129 | $response = json_decode($request->getBody()->getContents(), true); |
||
| 130 | |||
| 131 | return $response; |
||
| 132 | } |
||
| 133 | |||
| 134 | // User |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Optional parameters: id and ucode. |
||
| 138 | * @param array|null $params |
||
| 139 | * @return mixed |
||
| 140 | */ |
||
| 141 | public function getUser(array $params = null) |
||
| 142 | { |
||
| 143 | if (is_array($params)) { |
||
| 144 | $params = array_filter($params); |
||
| 145 | $this->params['query'] = $params; |
||
| 146 | } |
||
| 147 | $request = $this->client->get('/user/rest/v2', $this->params); |
||
| 148 | $response = json_decode($request->getBody()->getContents(), true); |
||
| 149 | |||
| 150 | return $response; |
||
| 151 | } |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @return mixed |
||
| 155 | */ |
||
| 156 | public function getLoggedUser() |
||
| 157 | { |
||
| 158 | $request = $this->client->get('/user/rest/v2/me', $this->params); |
||
| 159 | $response = json_decode($request->getBody()->getContents(), true); |
||
| 160 | |||
| 161 | return $response; |
||
| 162 | } |
||
| 163 | } |