Add field to license mgr
-
I would like to confirm email address and serial number via the api. Can you think of a simple way to implement this? Can it be added from the order?
-
Following up – Can you suggest an easy way to add email address field?
Hello @marshallapparelautomation
thank you for your message and for using my plugin.
I apologize for the late reply, I’ve been quite busy with the new update that came out just a few minutes ago (Version 2.2.0).
There is a hook which allows you to perform additional validation in the REST API, before the actual call even begins. Take a look here:
If the
lmfwc_rest_api_validation
filter returns aWP_Error
object the API call will fail.And to answer your second question: you can modify the REST API response with the
lmfwc_rest_api_pre_response
filter.Let me know if you need further help with this.
Hi Drazen, thanks a lot for the plugin. It’s really a good plugin. I have a question. It’s related with this. You suggest to use a validate filter before any action (Activate, Vaidate, Create) and then if all of this is ok then we can handle the response in another filter “lmfwc_rest_api_pre_response”. Everything looks ok so far. In your example of validation you use an “activation_uuid” meta data with a previous data storage in DB, my question is how we save this data as a previous data??? I mean:
// 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) ); }
In what place or function or filter or action we save the $previousActivation var??? This param we sent to api server and we can use it in “lmfwc_rest_api_validation” with this:
// Retrieve the body parameters $body = $request->get_json_params();
but in the lmfwc_rest_api_pre_response filter we can not access to this params. Can you provide us a code or example of this??? We appreciate all your help. Thansk in advance. PD: Sorry for my english
- This reply was modified 4 years, 4 months ago by anibalmauricio.
Hello @anibalmauricio
Thank you for your message and for using my plugin.
Check out this guide: https://www.licensemanager.at/docs/tutorials-how-to/modifying-the-rest-api-response/
Basically, you can use the
lmfwc_rest_api_pre_response
filter, which will allow you to modify the REST API response. But it’s important to know that this hook fires right before the REST API is about to send out the response to the client.This means that you can send an additional parameter in your request, and/or store any additional parameters somewhere in the database (i.e. license meta).
Let me know if you need further help with this.
Thank you Drazen for you feedback. I appreaciate. Well, that’s the problem. We do not know how to send that data. we use de body param of the “wp_remote_get” function of wordpress, and in the validation filter we can handle this data, but we can not get that data to enter in our database. Can you provide me an example of call the api to get that data on the response filter??? Thank you for all your help. This is what we got until now:
// Make the request $remote_url = sprintf('%s%s', $this->endpoint, $license_code); $api_params = array( 'host' => home_url() ); $response = wp_remote_get( $remote_url, array( 'headers' => [ 'Authorization' => 'Basic ' . base64_encode( sprintf( '%s:%s', $this->consumer_key, $this->consumer_secret ) ), 'Content-Type' => 'application/json' ], 'method' => 'GET', 'timeout' => 45, 'body' => $api_params ) );
the host param of body we can access to it in validation filter bu not on the response filter
- This reply was modified 4 years, 4 months ago by anibalmauricio.
Hi @drazenbebic, could you help me with this??? I appreaciate all your help with this amazing plugin
- The topic ‘Add field to license mgr’ is closed to new replies.