Theme purchase code PHP issue

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 :slight_smile:

Hi

You can check this helpful reply from @baileyherbert

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. :stuck_out_tongue:

2 Likes

Thank you for your help and I aplogie about the token I missed it :).