• Resolved frankgao714

    (@frankgao714)


    Hi Drazen

    thumbs up for your work. We have been making good use of the license manager.

    We are now implementing in C++ hoping to integrate the Rest API in a more convenient way.

    We are hoping to get a license details by an order ID. What you have is only by license key. I looked in to the route registration and the functions corrspondingly, but do not have php experience. Would if be possible for you to add an API for this purpose? Eventually one would need a better query function for retrieving license codes.

    I appreciate very much your help and happy new year

Viewing 14 replies - 1 through 14 (of 14 total)
  • Hi @frankgao714

    Hope you are doing well.

    Sorry for the inconvenience we don’t provide any customization assistance or any additional work, you can read our documentation given below and with the help of a developer, you can integrate API into your product to our license manager accordingly.

    https://www.licensemanager.at/docs/

    Thanks

    @frankgao714 @arsalantariq
    Hi,
    Here is a solution I use (of course it can be improved, all suggestions are welcome!)

    Instead of adding this feature to the plugin, I added it to Woocommerce API endpoint. This way; when you get an order from Woocommerce API, it would also contain info about purchased licenses.

    Here is the example output:
    GET https://example.com/wp-json/wc/v3/orders/1780

    Response snippet:

    
    ...
    "date_paid_gmt": "2022-04-22T17:52:51",
        "currency_symbol": "€",
        "license_lines": [
            {
                "id": 3,
                "product_id": 1761,
                "product_name": "Premium - 1 year",
                "order_id": 1780,
                "key": "XYZ-ABC-AG5V-9900-VPNM",
                "expires_at": "2023-04-22 17:52:51",
                "valid_for_days": 365,
                "source": 1,
                "status": 2,
                "times_activated": null,
                "times_activated_max": 1
            }
        ],
        "_links": {
            "self": [
    
    ...
    

    To make this happen; add this code to your theme’s functions.php file:

    function add_licenses_to_order_api_data ( $response, $order, $request ) {
    	$licenses = apply_filters('lmfwc_get_customer_license_keys', $order);
    	foreach ($licenses as $prd_id => $license) {
    		$prd_name = $license["name"];
    		$license = $license["keys"][0];
    		$license_line = [ "id" => $license->getId(),
    						  "product_id" => $license->getProductId(),
    						  "product_name" => $prd_name,
    						  "order_id" => $license->getOrderId(),
    						  "key" => $license->getDecryptedLicenseKey(),
    						  "expires_at" => $license->getExpiresAt(),
    						  "valid_for_days" => $license->getValidFor(),
    						  "source" => $license->getSource(),
    						  "status" => $license->getStatus(),
    						  "times_activated" => $license->getTimesActivated(),
    						  "times_activated_max" => $license->getTimesActivatedMax(),
    						];
    		$license_lines[] = $license_line;
    	}
    	$response->data['license_lines'] = $license_lines;
    	
    	return $response;
    }
    add_filter( 'woocommerce_rest_prepare_shop_order_object', 'add_licenses_to_order_api_data',10 ,3);

    @amirhmoradi

    Thanks for updating us, I will check it on my staging websites soon.

    Thanks

    Hi @haseeb0001

    Did you get to test the code and confirm that it works for multiple licenses?

    It works well but it only returns the first element?(say you have 5 licenses purchased, the code returns the first license, if one removes [0]; it fails to add licenses on the Woocommerce payload)

    If you have done so please confirm.

    • This reply was modified 2 years, 2 months ago by sammymlangeni.

    @sammymlangeni

    I will share updates with you in the next 4 – 5 days.

    Thanks

    @haseeb0001

    Thank you, and I will appreciate it.

    Hi @haseeb0001

    I might have slipped your mind on the feedback. Thank you in advance.

    @sammymlangeni Yes, we are testing and working on it, will share updates asap.

    Thanks

    Hi @sammymlangeni @haseeb0001 ,
    It should be quite simple to fix this. Before moving on, we shall check the type of $licenses and $license["keys"][0] in the example above, and act accordingly.

    To make sure I understand your request @haseeb0001, let me rephrase:
    NB: We shall not mix concepts of :
    number of license keys per product,
    number of activations possible per license
    number of licenses per order

    * A customer makes a purchase order (ORD_ID: 1780), containing multiple licenses (LIC_ID: 3, LIC_ID:4, LIC_ID:5,…) with each license having ONLY ONE key.

    * You expect WC API to have the following response structure:

    ...
    "date_paid_gmt": "2022-04-22T17:52:51",
        "currency_symbol": "€",
        "license_lines": [
            {
                "id": 3,
                "product_id": 1761,
                "product_name": "Premium - 1 year",
                "order_id": 1780,
                "key": "XYZ-ABC-AG5V-9900-VPNM",
                "expires_at": "2023-04-22 17:52:51",
                "valid_for_days": 365,
                "source": 1,
                "status": 2,
                "times_activated": null,
                "times_activated_max": 1
            },
            {
                "id": 4,
                "product_id": 1762,
                "product_name": "Premium - 2 year",
                "order_id": 1780,
                "key": "XYZ-ABC-AG5V-8800-VPNL",
                "expires_at": "2023-04-22 17:52:51",
                "valid_for_days": 365,
                "source": 1,
                "status": 2,
                "times_activated": null,
                "times_activated_max": 1
            },
            {
                "id": 5,
                "product_id": 1763,
                "product_name": "Premium - 3 year",
                "order_id": 1780,
                "key": "XYZ-ABC-AG5V-7700-VPNK",
                "expires_at": "2023-04-22 17:52:51",
                "valid_for_days": 365,
                "source": 1,
                "status": 2,
                "times_activated": null,
                "times_activated_max": 1
            }
        ],
        "_links": {
            "self": [
    
    ...

    Did I understand correctly?

    Hi @amirhmoradi

    Thank you for the elaborate response and your question. Your example is in line with what I think I need. You have actually expanded more to the payload, combining variable products as well. This is excellent. I like your example.

    My use case is number of licenses per order. See the sample image on this link below.

    https://ibb.co/z7HyNQz

    Hi @amirhmoradi

    You understood me correctly. The API response is exactly what I expect. Thank you for looking into this query.

    sammymlangeni

    (@sammymlangeni)

    Hi @amirhmoradi

    Any feedback?

    This problem is resolved on my side. No need for further solution. Thank you.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Retrieve license code by order_id’ is closed to new replies.