Skip to content

Instantly share code, notes, and snippets.

@alexanderisora
Last active December 14, 2018 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexanderisora/fcbcf1ba75ed63cf717d4be0ca31c3e7 to your computer and use it in GitHub Desktop.
Save alexanderisora/fcbcf1ba75ed63cf717d4be0ca31c3e7 to your computer and use it in GitHub Desktop.
checkIfPro(){
// Send email and PRO_PRODUCT_ID to check.php.
// check.php must get the list of all users from Paddle, then see if current user is among Pro users.
const userEmail = "email@example.com";
const PRODUCT_ID = 11111; //See this ID in the Paddle dashboard.
const URL = 'https://unicornplatform.com/api/check.php';
const data = {
email: userEmail,
productID: PRODUCT_ID
};
const PARAMS = {
headers: {
"Accept": "application/json",
"Content-Type": "application/json; charset=UTF-8"
},
body: JSON.stringify(data),
method: 'POST'
};
fetch(URL, params)
.then(res => res.text())
.then(response => {
let res = JSON.parse(response);
//PHP script returns an object.
if(res.isPro === 'true'){
// It's a Pro user.
}else{
// It's a free-plan user.
}
})
.catch(error => console.error('Error:', error));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment