Skip to content

Instantly share code, notes, and snippets.

@Snakeyyy
Created September 25, 2023 11:40
Show Gist options
  • Save Snakeyyy/d9d565242a217918a73900ca42a4b559 to your computer and use it in GitHub Desktop.
Save Snakeyyy/d9d565242a217918a73900ca42a4b559 to your computer and use it in GitHub Desktop.
PartnerJam - get discount - NodeJS
async function createDiscountedCharge(request) {
const [price, planName] = createCharge(request);
const discountToken = request.cookies.partner_jam_token;
if (discountToken) {
try {
const response = await axios.get(\`https://be-app.partnerjam.com/api/v1/discount-check/?token=\${discountToken}\`);
const { discount } = response.data;
if (discount) {
const discountedPrice = price - price * (discount / 100);
const discountedPlanName = `${planName} (${discount}% discount)`;
return [discountedPrice, discountedPlanName];
}
} catch (error) {
console.error('Error occurred while checking discount:', error);
}
}
return [price, planName];
}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment