Skip to content

Instantly share code, notes, and snippets.

@vovafeldman
Last active November 4, 2024 09:14
Show Gist options
  • Save vovafeldman/2bc86bed60f488e0e1f1b3d5f790f7e7 to your computer and use it in GitHub Desktop.
Save vovafeldman/2bc86bed60f488e0e1f1b3d5f790f7e7 to your computer and use it in GitHub Desktop.
Freemius Buy Button Code for a Multi-Plans Table
<script src="https://checkout.freemius.com/js/v1/"></script>
<select id="starter-licenses">
<option value="1" selected="selected">Single Site License</option>
<option value="5">5-Site License</option>
<option value="25">25-Site License</option>
<option value="unlimited">Unlimited Sites License</option>
</select>
<button id="starter-purchase">Buy Starter</button>
<select id="pro-licenses">
<option value="1" selected="selected">Single Site License</option>
<option value="5">5-Site License</option>
<option value="25">25-Site License</option>
<option value="unlimited">Unlimited Sites License</option>
</select>
<button id="pro-purchase">Buy Professional</button>
<select id="bus-licenses">
<option value="1" selected="selected">Single Site License</option>
<option value="5">5-Site License</option>
<option value="25">25-Site License</option>
<option value="unlimited">Unlimited Sites License</option>
</select>
<button id="bus-purchase">Buy Professional</button>
<script type="text/javascript">
(function(){
const freemiusHandler = new FS.Checkout({
title : '<productTitle>',
plugin_id: '<productID>',
public_key: '<publicKey>'
});
const plans = {
starter: '104',
pro: '105',
bus: '106'
};
function addBuyHandler(plan, planID){
document.querySelector('#' + plan + '-purchase').addEventListener('click', function (e) {
freemiusHandler.open({
plan_id : planID,
licenses: document.querySelector('#' + plan + '-licenses').value,
// You can consume the response for after purchase logic.
success : function (response) {
// alert(response.user.email);
}
});
e.preventDefault();
});
}
Object.entries(plans).forEach(([plan, planID]) => {
addBuyHandler(plan, planID);
});
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment