get_recurly_group_prices.mjs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Get prices from Recurly in GroupPlansData format, ie to update:
  2. // app/templates/plans/groups.json
  3. //
  4. // Usage example:
  5. // node scripts/recurly/get_recurly_group_prices.mjs
  6. import recurly from 'recurly'
  7. import Settings from '@overleaf/settings'
  8. import { scriptRunner } from '../lib/ScriptRunner.mjs'
  9. const recurlySettings = Settings.apis.recurly
  10. const recurlyApiKey = recurlySettings ? recurlySettings.apiKey : undefined
  11. const client = new recurly.Client(recurlyApiKey)
  12. async function getRecurlyGroupPrices() {
  13. const prices = {}
  14. const plans = client.listPlans({ params: { limit: 200 } })
  15. for await (const plan of plans.each()) {
  16. if (plan.code.substr(0, 6) === 'group_') {
  17. const [, type, size, usage] = plan.code.split('_')
  18. plan.currencies.forEach(planPricing => {
  19. const { currency, unitAmount } = planPricing
  20. prices[usage] = prices[usage] || {}
  21. prices[usage][type] = prices[usage][type] || {}
  22. prices[usage][type][currency] = prices[usage][type][currency] || {}
  23. prices[usage][type][currency][size] = {
  24. price_in_cents: unitAmount * 100,
  25. }
  26. })
  27. }
  28. }
  29. return prices
  30. }
  31. async function main() {
  32. const prices = await getRecurlyGroupPrices()
  33. console.log(JSON.stringify(prices, undefined, 2))
  34. }
  35. try {
  36. await scriptRunner(main)
  37. process.exit(0)
  38. } catch (error) {
  39. console.error({ error })
  40. process.exit(1)
  41. }