I am managing subscriptions to my licenses through Stripe, which calls a Cloudflare worker. And that worker calls Cryptlex API for license creation/renewal.
Currently, I am looking for active license and renewing it by 30 days when the payment happens successfully.
But in the case when license renewal is attempted (for whatever reason) post the license expiry, how should I handle renewals? What is the most commonly accepted case here? Creation of a new license, or renewal of the expired one? And how do we renew the expired license?
Hi @Siddharth21,
Thank you for reaching out!
Your approach of extending the license validity by 30 days upon successful payment is a standard practice. However, if a license has already expired, renewing or extending it is generally preferable over generating a new one unless there is a strong reason to issue a fresh license. This helps avoid complexities such as redistributing new license keys to users.
To renew/extend a license, whether active or expired, you can use the following approach:
-
For active licenses: Send a
POST
request to the https://api.cryptlex.com/v3/licenses/{id}/renew
endpoint, where {id}
is the license ID. It will renew the license with the original validity set for the license and update expiresAt
value of the license.
- For expired licenses:
- Retrieve the current expiry date from Stripe.
- Calculate the number of days since expiration till current date and add it to the extension period. For example “15 days + 30 days”.
- Send a
POST
request to https://api.cryptlex.com/v3/licenses/{id}/extend
with the calculated days as a value to the extensionLength
property to be specified in the request body.
Let me know if it helps!