2022-01-11 09:57:03 -05:00
|
|
|
// Get prices from Recurly in GroupPlansData format, ie to update:
|
|
|
|
// app/templates/plans/groups.json
|
|
|
|
//
|
|
|
|
// Usage example:
|
2024-10-22 04:21:39 -04:00
|
|
|
// node scripts/recurly/get_recurly_group_prices.mjs
|
2022-01-11 09:57:03 -05:00
|
|
|
|
2024-10-22 04:21:39 -04:00
|
|
|
import recurly from 'recurly'
|
|
|
|
|
|
|
|
import Settings from '@overleaf/settings'
|
2022-01-11 09:57:03 -05:00
|
|
|
|
|
|
|
const recurlySettings = Settings.apis.recurly
|
|
|
|
const recurlyApiKey = recurlySettings ? recurlySettings.apiKey : undefined
|
|
|
|
|
|
|
|
const client = new recurly.Client(recurlyApiKey)
|
|
|
|
|
|
|
|
async function getRecurlyGroupPrices() {
|
|
|
|
const prices = {}
|
|
|
|
const plans = client.listPlans({ params: { limit: 200 } })
|
|
|
|
for await (const plan of plans.each()) {
|
|
|
|
if (plan.code.substr(0, 6) === 'group_') {
|
|
|
|
const [, type, size, usage] = plan.code.split('_')
|
|
|
|
plan.currencies.forEach(planPricing => {
|
|
|
|
const { currency, unitAmount } = planPricing
|
|
|
|
prices[usage] = prices[usage] || {}
|
|
|
|
prices[usage][type] = prices[usage][type] || {}
|
|
|
|
prices[usage][type][currency] = prices[usage][type][currency] || {}
|
2022-01-12 05:07:21 -05:00
|
|
|
prices[usage][type][currency][size] = {
|
|
|
|
price_in_cents: unitAmount * 100,
|
|
|
|
}
|
2022-01-11 09:57:03 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return prices
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const prices = await getRecurlyGroupPrices()
|
|
|
|
console.log(JSON.stringify(prices, undefined, 2))
|
|
|
|
}
|
|
|
|
|
2024-10-22 04:21:39 -04:00
|
|
|
try {
|
|
|
|
await main()
|
|
|
|
process.exit(0)
|
|
|
|
} catch (error) {
|
|
|
|
console.error({ error })
|
|
|
|
process.exit(1)
|
|
|
|
}
|