Support » Plugin: License Manager for WooCommerce » API wrap around

  • Resolved kimherrero

    (@kimherrero)


    Hi to all, considering that my software has an InstallId that needs to get paired with the LicenseId and that I want to avoid to hard code the consumer keys, I made the following work around php that calls the rest API and does the extra job.

    As I am not a php expert, the question is, is it ok to make a call inside a call, or it could be a potentially server overloading problem?

    By the way, congrats for this excellent solution.

    P.D. I echo the results because I treat them as an INI file.

    Kim

    —————

    <?php

    if(isset($_GET[“id”])) {

    $iguid = $_GET[“id”];
    $ch = curl_init();

    curl_setopt_array($ch, array(
    CURLOPT_URL => “{host}/wp-json/lmfwc/v2/licenses/”.$iguid.”?consumer_key={consumer_key}&consumer_secret={consumer_secret}”,
    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($ch);
    $err = curl_error($ch);

    curl_close($ch);

    if ($err) {
    echo “Error #:” . $err;
    } else {

    $json = json_decode($response);
    if ( $json->success == true) {

    echo “Key=” . $json->data->licenseKey . “\n”;
    echo “Order=” . $json->data->orderId . “\n”;
    echo “Version=” . $json->data->productId . “\n”;
    echo “Status=” . $json->data->status . “\n”;
    echo “Expires=” . $json->data->expiresAt . “\n”;

    }

    // extra job here

    }

    }

    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Drazen Bebic

    (@drazenbebic)

    Hello @kimherrero,

    thank you for your message and for using my plugin.

    I have a question first: Is $iguid your license key? If so, all is good.

    It is always best to cut down on remote API calls as much as possible. You said that you don’t want to hardcode the consumer_key and consumer_secret, and that is reasonable. However, your “order” is wrong in your example. You would first need to do your extra job to obtain the consumer_key and consumer_secret, and then replace the placeholders on this line:

    CURLOPT_URL => “{host}/wp-json/lmfwc/v2/licenses/”.$iguid.”?consumer_key={consumer_key}&consumer_secret={consumer_secret}”

    I’m referring to {consumer_key} and {consumer_secret}. And it shouldn’t cause an overload by itself. However you will have to make 2 API calls to get the job done, which increases the risk of something going wrong. The request will also take longer to complete. But if you absolutely cannot have your keys hardcoded, then I don’t see another way.

    Let me know if you need further assistance

    Plugin Author Drazen Bebic

    (@drazenbebic)

    Hello @kimherrero,

    have you been able to work this one out? Do you need any more assistance?

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.