From 47fb3a644cec21baed7adbecaa6dceebb7d75b7d Mon Sep 17 00:00:00 2001 From: Domagoj Kriskovic Date: Wed, 19 Mar 2025 14:32:33 +0100 Subject: [PATCH] Script for generating add-on prices (from recurly) (#24051) * Script for generating addon prices (from recurly) * addon code as param GitOrigin-RevId: b1a45a806c29de56a10532398b56468f9732593f --- .../scripts/recurly/generate_addon_prices.mjs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 services/web/scripts/recurly/generate_addon_prices.mjs diff --git a/services/web/scripts/recurly/generate_addon_prices.mjs b/services/web/scripts/recurly/generate_addon_prices.mjs new file mode 100644 index 0000000000..9885d46b06 --- /dev/null +++ b/services/web/scripts/recurly/generate_addon_prices.mjs @@ -0,0 +1,55 @@ +// @ts-check +import settings from '@overleaf/settings' +import recurly from 'recurly' + +const ADD_ON_CODE = process.argv[2] + +async function main() { + if (!ADD_ON_CODE) { + console.error('Missing add-on code') + console.error( + 'Usage: node scripts/recurly/generate_addon_prices.mjs ADD_ON_CODE' + ) + process.exit(1) + } + + const localizedAddOnsPricing = {} + + const monthlyPlan = await getPlan(ADD_ON_CODE) + if (monthlyPlan == null) { + console.error(`Monthly plan missing in Recurly: ${ADD_ON_CODE}`) + process.exit(1) + } + for (const { currency, unitAmount } of monthlyPlan.currencies ?? []) { + if (!localizedAddOnsPricing[currency]) { + localizedAddOnsPricing[currency] = { [ADD_ON_CODE]: {} } + } + localizedAddOnsPricing[currency][ADD_ON_CODE].monthly = unitAmount + } + + const annualPlan = await getPlan(`${ADD_ON_CODE}-annual`) + if (annualPlan == null) { + console.error(`Annual plan missing in Recurly: ${ADD_ON_CODE}-annual`) + process.exit(1) + } + for (const { currency, unitAmount } of annualPlan.currencies ?? []) { + if (!localizedAddOnsPricing[currency]) { + localizedAddOnsPricing[currency] = { [ADD_ON_CODE]: {} } + } + localizedAddOnsPricing[currency][ADD_ON_CODE].annual = unitAmount + } + + console.log(JSON.stringify({ localizedAddOnsPricing }, null, 2)) +} + +/** + * Get a plan configuration from Recurly + * + * @param {string} planCode + */ +async function getPlan(planCode) { + const recurlyClient = new recurly.Client(settings.apis.recurly.apiKey) + return await recurlyClient.getPlan(`code-${planCode}`) +} + +await main()