Monetize your Products with Simple API Integrations
Most of us create some apps or platforms which we want to monetize but because of the hassle of managing the payments and subscriptions, it's very hard to do that.
In this article, I will show you step by step how you can monetize your product with simple APIs and a very simple platform.
Today we are going to talk about a platform called LemonSqueezy.
LemonSqueezy.com is a platform that will handle all the payments and subscription-related things for you. You just need to create a product and set the pricing for your product.
Step 1: Create a new Product in LemonSqueezy
You just need to fill in the details related to your product.
Step 2: Get the Payment Page Link
Once done. It will give you the link which you can share with your customers.
Once you have this link, You can set up the Payment button in your platform which will be used by your customers.
Step 3: Activation of License Key
When a customer buys your product via Lemon Squeezy, It will generate a License key for that order. You can ask your users to enter that License Key in your platform, so you can validate that the user has paid for your services.
For Activating the License Key, the Following is the sample code
activeLicenseKey: async (licenseKey) => {
const apiUrl = "https://api.lemonsqueezy.com/v1/licenses/activate";
try {
const body = new URLSearchParams({
license_key: licenseKey,
instance_name: uuidv4(),
});
const response = await fetch(apiUrl, {
method: "POST",
headers: {
Accept: "application/json",
},
body: body,
});
const data = await response.json();
console.log(licenseKey);
console.log(data);
if (data.activated) {
return { isActivated: true };
} else {
return { isActivated: false, error: data.error };
}
} catch (error) {
return { isActivated: false };
}
}
Above code will call the Lemon Squeezy API to activate the License Key entered by your user. Once activated, Now you just have to validate the License Key when users are accessing the paid features in your product.
Step 4: Validating the License Key
validateLicenseKey: async (licenseKey) => {
const apiUrl = "https://api.lemonsqueezy.com/v1/licenses/validate";
try {
const response = await fetch(apiUrl, {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/x-www-form-urlencoded",
},
body: `license_key=${licenseKey}`,
});
const data = await response.json();
console.log(licenseKey);
console.log(data);
if (data.valid) {
const storeId = "YOUR_STORE_ID";
if (
data.meta.store_id == storeId &&
data.license_key.activation_usage == 1
) {
return { isValid: true };
} else {
return { isValid: false };
}
} else {
return { isValid: false };
}
} catch (error) {
return { isValid: false };
}
}
You can validate the License Key and also check whether the license key was generated for your store.
Nowadays It's very simple to get your product up and running with Payment integrations. with LemonSqueezy you don't need to worry about any payment gateways. The best thing is you can get payouts directly via Paypal from Lemon Squeezy.
Cheers!!