Jorge Robles Ruiz
Forum Replies Created
-
Forum: Plugins
In reply to: [License Manager for WooCommerce] Additional REST API Validation Help@aditheman nice to know that you solve your problem.
Regards
Forum: Plugins
In reply to: [License Manager for WooCommerce] Additional REST API Validation HelpHi @aditheman,
On response on your post when you said BODY is not used in GET request, that was that I tried to explain, that’s why I must change the code and read the param in the GET request.
In your code If you want to read the uuid you can use $request[‘uuid’], $body is a variable (an array) for which I kept the name from the original example. So, the variable can be used on that function.
$path = wp_upload_dir(); $fp = fopen($path['path']."/Test.csv", "w"); fputcsv($fp, array($licenseKey, $request['uuid'])); fclose($fp);Regards
- This reply was modified 5 years ago by Jorge Robles Ruiz.
Forum: Plugins
In reply to: [License Manager for WooCommerce] Additional REST API Validation HelpHi Adrian, indeed there is a lot to do to make it work. In other words, the example is not functional and only illustrates what you must do. So not, the example is not saving the uuid value into de database jet and you won’t see it when export the CVS.
As you can see in this part of the example, it uses lmfwc_get_license_meta() to read the license meta and check if the uuid has been used before, but we must save the value during activation using lmfwc_add_license_meta(), and that is not done in the example. Also, you must return the uuid so you must modify the REST API response, and I would check the uuid when validating the license.
// Check if the license key already has this UUID $previousActivation = lmfwc_get_license_meta($license->getId(), 'activation_uuid', true); // Throw an error if that's the case if ($previousActivation && $previousActivation === $body['uuid']) { return new WP_Error( 'lmfwc_rest_validation_error', 'The license was already activated using this UUID.', array('status' => 403) ); }As I mentioned earlier, I will be working on the complete change to validate a site-code or machine-id, so the user could not activate on different computers, because that is what I need, so I can validate an activation code on client side.
But I’m working on change design, so it fits my needs.
It would be great if @drazenbebic, guide us on where is the best way to add a filter or an action so we can save the uuid value. I know I can do it on the same validation example but i guest it is not the best place, because that method is to extend the validation. And also would love to hear if the change I made is right or we can really use the original code with a GET request.
Regards.
P.D. @drazenbebic thank you for your excelent work.
- This reply was modified 5 years ago by Jorge Robles Ruiz.
Forum: Plugins
In reply to: [License Manager for WooCommerce] Additional REST API Validation HelpHi Adrian, yesterday I was implementing the additional rest api validation example, and I got the same result as you.
I noticed that in the example code they use:
// Retrieve the body parameters $body = $request->get_json_params(); // The request body was empty, or the "uuid" property is missing. if (!$body || !array_key_exists('uuid', $body)) { return new WP_Error( 'lmfwc_rest_data_error', 'The UUID is missing from the request.', array('status' => 400) ); }I read the documentation and found that $request->get_json_params(); gets the BODY of a POST request when content type is json (Content-Type: application/json)
As the activate API REST endpoint is only enabled for GET requests, I made the following change.
$body = array("uuid"=>$request['uuid']);On Postman I passed the uuid param exactly as you did and now my example is working, I will continue implementing this for my use case, I want to store a site-code or machine-id so the user can’t activate on different computers, if you are interested, I can share my progress.
Best regards
- This reply was modified 5 years ago by Jorge Robles Ruiz.
- This reply was modified 5 years ago by Jorge Robles Ruiz.
- This reply was modified 5 years ago by Jorge Robles Ruiz.
- This reply was modified 5 years ago by Jorge Robles Ruiz.