Hi.
I am working on a theme and I am stuck at validating the theme, php is not my strong point so I am sure that I am missing something, the token key is valid but the response is null. Any help is greatly appreciate it.
Thank you.
function fwdupt_verify_envato_purchase_code($code_to_verify) {
$ch = curl_init();
var_dump($code_to_verify);
curl_setopt_array($ch, array(
CURLOPT_URL => “https://api.envato.com/v3/market/author/sale?code={$code_to_verify} ”,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 20,
CURLOPT_HTTPHEADER => array(
“Authorization: Bearer (redacted)”,
“User-Agent: Purchase code verification for Kreative Theme”
)
));
$response = @curl_exec($ch);
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$response = @curl_exec($ch);
$data = json_decode($response);
var_dump($response);
if(!empty($data->item->name) && (strpos($data->item->name, 'Kreative') !== false || strpos($data->item->name, 'Mega') !== false)){
return 'valid';
}else{
return 'invalid';
}
}
Just saw that curl_error returns " malformed" , I have no idea what that means. So frustrating
Hi
You can check this helpful reply from @baileyherbert
This is a community guide for authors who want to implement purchase code verification on their items, websites, and applications. If you have any questions or feedback then please feel free to respond directly to this topic.
This topic is a wiki. All active members of the forums can edit it. Don’t hesitate to make corrections or add in any new information. All contributions are welcome!
Just want some working code to get started quickly?
There are some functi…
Thanks
2 Likes
For others that might have this issue I was testing local on a http protocol and I had to add in curl_set_opt
CURLOPT_SSL_VERIFYPEER => false
This has solved the issue.
Thank you!
2 Likes
Glad you got it resolved. Just a heads up, though – you should definitely make sure to turn that option back on during production for security reasons.
If you get errors about SSL certificates and aren’t sure how to fix that on the server-side, you can quickly download a CA bundle from https://curl.haxx.se/docs/caextract.html and set it like below - this will allow CURL to verify the certificates.
curl_setopt($ch, CURLOPT_CAINFO, '/path/to/cacert.pem');
Also, just saw a personal token in your code. I removed it, but if that was a real token, I’d suggest revoking that one and creating a new one.
2 Likes
Thank you for your help and I aplogie about the token I missed it :).