Last active
December 14, 2018 08:04
-
-
Save alexanderisora/fcbcf1ba75ed63cf717d4be0ca31c3e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 protected]"; | |
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