• Resolved davidxanatos

    (@davidxanatos)


    I would need the ability to get all keys generated for a given order-id, i have forked an older version to do that would be really great if you could add it to the official distribution.

    includes\api\v2\Licenses.php

        /**
         * GET licenses/by-order/{order_id}
         *
         * Retrieves a single licenses from the database.
         */
        register_rest_route(
            $this->namespace, $this->rest_base . '/by-order/(?P<order_id>[\w-]+)', array(
                array(
                    'methods'             => WP_REST_Server::READABLE,
                    'callback'            => array($this, 'getLicensesByOrder'),
                    'permission_callback' => array($this, 'permissionCallback'),
                    'args'                => array(
                        'order_id' => array(
                            'description' => 'Order ID',
                            'type'        => 'integer',
                        )
                    )
                )
            )
        );

    and

    public function getLicensesByOrder(WP_REST_Request $request)
    {
    if (!$this->isRouteEnabled($this->settings, '010')) {
    return $this->routeDisabledError();
    }

    if (!$this->permissionCheck('license', 'read')) {
    return new WP_Error(
    'lmfwc_rest_cannot_view',
    __('Sorry, you cannot list resources.', 'license-manager-for-woocommerce'),
    array(
    'status' => $this->authorizationRequiredCode()
    )
    );
    }

    $orderId = absint($request->get_param('order_id'));

    if (!$orderId) {
    return new WP_Error(
    'lmfwc_rest_data_error',
    'Order ID invalid.',
    array('status' => 404)
    );
    }

    try {
    /** @var LicenseResourceModel[] $licenses */
    $licenses = LicenseResourceRepository::instance()->findAllBy(
    array(
    'order_id' => $orderId
    )
    );
    } catch (Exception $e) {
    return new WP_Error(
    'lmfwc_rest_data_error',
    $e->getMessage(),
    array('status' => 404)
    );
    }

    if (!$licenses) {
    return new WP_Error(
    'lmfwc_rest_data_error',
    'No License Keys available',
    array('status' => 404)
    );
    }

    $response = array();

    /** @var LicenseResourceModel $license */
    foreach ($licenses as $license) {
    $licenseData = $license->toArray();

    // Remove the hash, decrypt the license key, and add it to the response
    unset($licenseData['hash']);
    $licenseData['licenseKey'] = $license->getDecryptedLicenseKey();
    $response[] = $licenseData;
    }

    return $this->response(true, $response, 200, 'v2/licenses/by-order');
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Ibaad Ahmed Khan

    (@ibaad06)

    Dear @davidxanatos

    We have responded to your other thread. Please check and acknowledge.

    Thank you and kind regards.

    Plugin Support Ibaad Ahmed Khan

    (@ibaad06)

    Dear @davidxanatos

    Hope you’re doing well,

    We have forwarded this request to our technical team. While we can’t implement this feature in a quick update, it will be added in a future release.
    We appreciate your understanding and patience. Could you please confirm if we can close this thread?

    Thank you and kind regards.

    Plugin Support Ibaad Ahmed Khan

    (@ibaad06)

    Dear @davidxanatos

    We are closing this thread due to inactivity. If you have any further questions regarding our plugin, please open a new thread.

    Thank you and kind regards.

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