get_recurly_group_prices.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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.js
  6. const recurly = require('recurly')
  7. const Settings = require('@overleaf/settings')
  8. const recurlySettings = Settings.apis.recurly
  9. const recurlyApiKey = recurlySettings ? recurlySettings.apiKey : undefined
  10. const client = new recurly.Client(recurlyApiKey)
  11. async function getRecurlyGroupPrices() {
  12. const prices = {}
  13. const plans = client.listPlans({ params: { limit: 200 } })
  14. for await (const plan of plans.each()) {
  15. if (plan.code.substr(0, 6) === 'group_') {
  16. const [, type, size, usage] = plan.code.split('_')
  17. plan.currencies.forEach(planPricing => {
  18. const { currency, unitAmount } = planPricing
  19. prices[usage] = prices[usage] || {}
  20. prices[usage][type] = prices[usage][type] || {}
  21. prices[usage][type][currency] = prices[usage][type][currency] || {}
  22. prices[usage][type][currency][size] = unitAmount
  23. })
  24. }
  25. }
  26. return prices
  27. }
  28. async function main() {
  29. const prices = await getRecurlyGroupPrices()
  30. console.log(JSON.stringify(prices, undefined, 2))
  31. }
  32. main()
  33. .then(() => {
  34. process.exit(0)
  35. })
  36. .catch(error => {
  37. console.error({ error })
  38. process.exit(1)
  39. })