Hello @codac
Thank you for your message and for using my plugin. Sorry for the late reply, I was quite busy the last 2-3 months.
Odd, have you tried with POSTMAN? Does it work there?
Thread Starter
codac
(@codac)
Thank god you replied, I’m quite desperate in finding a solution.
In Postman, the following call works:
https://www.my-url.com/wp-json/lmfwc/v2/licenses/validate/THE-PRETENDER?consumer_key={{consumer_key}}&consumer_secret={{consumer_secret}}
Authorization is Basic Auth with Comsumer Key as Username und Consumer Secret as Password.
@codac
Did you make sure that this is a GET request? Perhaps you can also send me your POSTMAN collection and I’ll take a look myself.
Thread Starter
codac
(@codac)
This is my Code:
//validate license key
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.my-url.com/wp-json/lmfwc/v2/licenses/validate/".$this->lcns."?consumer_key=".$this->lmfwcConsumerKey."&consumer_secret=".$this->lmfwcConsumerSecret,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$err = curl_error($curl);
$result = json_decode($response, true);
curl_close($curl);
So yes the call is defined to be a GET request.
Where can I send you my Postman Collection to?
-
This reply was modified 5 years, 11 months ago by
codac.
-
This reply was modified 5 years, 11 months ago by
codac.
-
This reply was modified 5 years, 11 months ago by
codac.
Hello @codac
I already got the link to the POSTMAN collection from your original post, good that you quickly edited it out.
I was also able to do it via POSTMAN, I’ll try with a PHP script and let you know in a bit.
@codac
I managed to get it working by adding the User-Agent header.
Try adding the following before the curl_exec() method:
$headers = array(
'User-Agent: ' . $_SERVER['HTTP_USER_AGENT'],
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
Please let me know if it worked for you as well.
Thread Starter
codac
(@codac)
That did the trick. The final code is:
//validate license key
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.my-url.com/wp-json/lmfwc/v2/licenses/validate/".$this->lcns."?consumer_key=".$this->lmfwcConsumerKey."&consumer_secret=".$this->lmfwcConsumerSecret,
CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$err = curl_error($curl);
$result = json_decode($response, true);
curl_close($curl);
Can you explain why this part of code is necessary?
@codac
I honestly don’t know why this part is necessary. Do you maybe have a security plugin on your website which blocks all requests without a user agent?
Thread Starter
codac
(@codac)
Yes I do, so that might be it then…
Thank you very much Drazen!
@codac
No problem!
If you’re satisfied with the plugin and the support, I would like to ask you to write a plugin review here on ww.wp.xz.cn. The reviews really help the plugin grow, and mean a lot to me personally.
Here’s the link: https://ww.wp.xz.cn/support/plugin/license-manager-for-woocommerce/reviews/#new-post
Let me know if there is anything else I can do.