get_recurly_group_prices.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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] = {
  23. price_in_cents: unitAmount * 100,
  24. }
  25. })
  26. }
  27. }
  28. return prices
  29. }
  30. async function main() {
  31. const prices = await getRecurlyGroupPrices()
  32. console.log(JSON.stringify(prices, undefined, 2))
  33. }
  34. main()
  35. .then(() => {
  36. process.exit(0)
  37. })
  38. .catch(error => {
  39. console.error({ error })
  40. process.exit(1)
  41. })