Created
September 25, 2023 11:40
-
-
Save Snakeyyy/d9d565242a217918a73900ca42a4b559 to your computer and use it in GitHub Desktop.
PartnerJam - get discount - NodeJS
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
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