Stripe Subscriptions module API explorer

/api/administrator/subscriptions/prices (GET)

Account information like email addresses is generated with faker-js it is not real user information.

await global.api.administrator.subscriptions.Prices.get(req)

Returns array

[
  {
    "priceid": "price_1LEOMVHHqepMFuCX9XeGwuMk",
    "object": "price",
    "stripeObject": {
      "id": "price_1LEOMVHHqepMFuCX9XeGwuMk",
      "object": "price",
      "active": true,
      "billing_scheme": "tiered",
      "created": 1656122679,
      "currency": "usd",
      "custom_unit_amount": null,
      "livemode": false,
      "lookup_key": null,
      "metadata": {},
      "nickname": null,
      "product": "prod_LwGuoIpJIUClkU",
      "recurring": {
        "aggregate_usage": "sum",
        "interval": "month",
        "interval_count": 1,
        "trial_period_days": null,
        "usage_type": "metered"
      },
      "tax_behavior": "inclusive",
      "tiers": [
        {
          "flat_amount": 9999,
          "flat_amount_decimal": "9999",
          "unit_amount": null,
          "unit_amount_decimal": null,
          "up_to": 1000
        },
        {
          "flat_amount": 8999,
          "flat_amount_decimal": "8999",
          "unit_amount": null,
          "unit_amount_decimal": null,
          "up_to": null
        }
      ],
      "tiers_mode": "volume",
      "transform_quantity": null,
      "type": "recurring",
      "unit_amount": null,
      "unit_amount_decimal": null
    },
    "productid": "prod_LwGuoIpJIUClkU",
    "active": true,
    "appid": "tests_1656122677",
    "createdAt": "2022-06-25T02:04:39.870Z",
    "updatedAt": "2022-06-25T02:04:39.870Z"
  },
  {
    "priceid": "price_1LEOMUHHqepMFuCX0ya4MBnU",
    "object": "price",
    "stripeObject": {
      "id": "price_1LEOMUHHqepMFuCX0ya4MBnU",
      "object": "price",
      "active": true,
      "billing_scheme": "tiered",
      "created": 1656122678,
      "currency": "usd",
      "custom_unit_amount": null,
      "livemode": false,
      "lookup_key": null,
      "metadata": {},
      "nickname": null,
      "product": "prod_LwGuoIpJIUClkU",
      "recurring": {
        "aggregate_usage": "sum",
        "interval": "month",
        "interval_count": 1,
        "trial_period_days": null,
        "usage_type": "metered"
      },
      "tax_behavior": "inclusive",
      "tiers": [
        {
          "flat_amount": 9999,
          "flat_amount_decimal": "9999",
          "unit_amount": null,
          "unit_amount_decimal": null,
          "up_to": 1000
        },
        {
          "flat_amount": 8999,
          "flat_amount_decimal": "8999",
          "unit_amount": null,
          "unit_amount_decimal": null,
          "up_to": null
        }
      ],
      "tiers_mode": "volume",
      "transform_quantity": null,
      "type": "recurring",
      "unit_amount": null,
      "unit_amount_decimal": null
    },
    "productid": "prod_LwGuoIpJIUClkU",
    "active": true,
    "appid": "tests_1656122677",
    "createdAt": "2022-06-25T02:04:39.278Z",
    "updatedAt": "2022-06-25T02:04:39.278Z"
  },
  {
    "priceid": "price_1LEOMUHHqepMFuCX9tbkvRFb",
    "object": "price",
    "stripeObject": {
      "id": "price_1LEOMUHHqepMFuCX9tbkvRFb",
      "object": "price",
      "active": true,
      "billing_scheme": "tiered",
      "created": 1656122678,
      "currency": "usd",
      "custom_unit_amount": null,
      "livemode": false,
      "lookup_key": null,
      "metadata": {},
      "nickname": null,
      "product": "prod_LwGuoIpJIUClkU",
      "recurring": {
        "aggregate_usage": "sum",
        "interval": "month",
        "interval_count": 1,
        "trial_period_days": null,
        "usage_type": "metered"
      },
      "tax_behavior": "inclusive",
      "tiers": [
        {
          "flat_amount": 9999,
          "flat_amount_decimal": "9999",
          "unit_amount": null,
          "unit_amount_decimal": null,
          "up_to": 1000
        },
        {
          "flat_amount": 8999,
          "flat_amount_decimal": "8999",
          "unit_amount": null,
          "unit_amount_decimal": null,
          "up_to": null
        }
      ],
      "tiers_mode": "volume",
      "transform_quantity": null,
      "type": "recurring",
      "unit_amount": null,
      "unit_amount_decimal": null
    },
    "productid": "prod_LwGuoIpJIUClkU",
    "active": true,
    "appid": "tests_1656122677",
    "createdAt": "2022-06-25T02:04:38.686Z",
    "updatedAt": "2022-06-25T02:04:38.686Z"
  }
]

Receives

API routes may receive parameters from the URL and POST supporting simple and multipart:

Field Value Required Type
all boolean optional URL
limit integer optional URL
offset integer optional URL

NodeJS source (view on github)

const subscriptions = require('../../../../../index.js')

module.exports = {
  get: async (req) => {
    req.query = req.query || {}
    const where = {
      appid: req.appid || global.appid
    }
    let priceids
    if (req.query.all) {
      priceids = await subscriptions.Storage.Price.findAll({
        where,
        attributes: ['priceid'],
        order: [
          ['createdAt', 'DESC']
        ]
      })
    } else {
      const offset = req.query.offset ? parseInt(req.query.offset, 10) : 0
      const limit = req.query.limit ? parseInt(req.query.limit, 10) : global.pageSize
      priceids = await subscriptions.Storage.Price.findAll({
        where,
        attributes: ['priceid'],
        offset,
        limit,
        order: [
          ['createdAt', 'DESC']
        ]
      })
    }
    if (!priceids || !priceids.length) {
      return null
    }
    const items = []
    for (const priceInfo of priceids) {
      req.query.priceid = priceInfo.dataValues.priceid
      const price = await global.api.administrator.subscriptions.Price.get(req)
      items.push(price)
    }
    return items
  }
}

Test source (view on github)

/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../../test-helper.js')
const DashboardTestHelper = require('@layeredapps/dashboard/test-helper.js')

describe('/api/administrator/subscriptions/prices', function () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  let cachedResponses, cachedPrices
  async function bundledData (retryNumber) {
    if (retryNumber > 0) {
      cachedResponses = {}
    }
    if (cachedResponses && cachedResponses.finished) {
      return
    }
    cachedResponses = {}
    cachedPrices = []
    await DashboardTestHelper.setupBeforeEach()
    await TestHelper.setupBeforeEach()
    const administrator = await TestHelper.createOwner()
    await TestHelper.createProduct(administrator, {
      active: 'true'
    })
    for (let i = 0, len = global.pageSize + 2; i < len; i++) {
      await TestHelper.createPrice(administrator, {
        productid: administrator.product.productid,
        currency: 'usd',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'metered',
        recurring_aggregate_usage: 'sum',
        billing_scheme: 'tiered',
        tax_behavior: 'inclusive',
        tiers_mode: 'volume',
        tier1_up_to: '1000',
        tier1_flat_amount: '9999',
        tier2_up_to: 'inf',
        tier2_flat_amount: '8999',
        active: 'true'
      })
      cachedPrices.unshift(administrator.price.priceid)
    }
    const req1 = TestHelper.createRequest('/api/administrator/subscriptions/prices?offset=1')
    req1.account = administrator.account
    req1.session = administrator.session
    cachedResponses.offset = await req1.get()
    const req2 = TestHelper.createRequest('/api/administrator/subscriptions/prices?limit=1')
    req2.account = administrator.account
    req2.session = administrator.session
    cachedResponses.limit = await req2.get()
    const req3 = TestHelper.createRequest('/api/administrator/subscriptions/prices?all=true')
    req3.account = administrator.account
    req3.session = administrator.session
    cachedResponses.all = await req3.get()
    const req4 = TestHelper.createRequest('/api/administrator/subscriptions/prices')
    req4.account = administrator.account
    req4.session = administrator.session
    req4.filename = __filename
    req4.saveResponse = true
    cachedResponses.returns = await req4.get()
    global.pageSize = 3
    cachedResponses.pageSize = await req4.get()
    global.pageSize = 2
    cachedResponses.finished = true
  }
  describe('receives', () => {
    it('optional querystring offset (integer)', async function () {
      await bundledData(this.test.currentRetry())
      const offset = 1
      const pricesNow = cachedResponses.offset
      for (let i = 0, len = global.pageSize; i < len; i++) {
        assert.strictEqual(pricesNow[i].priceid, cachedPrices[offset + i])
      }
    })

    it('optional querystring limit (integer)', async function () {
      await bundledData(this.test.currentRetry())
      const limit = 1
      const pricesNow = cachedResponses.limit
      assert.strictEqual(pricesNow.length, limit)
    })

    it('optional querystring all (boolean)', async () => {
      const pricesNow = cachedResponses.all
      assert.strictEqual(pricesNow.length, cachedPrices.length)
    })
  })

  describe('returns', () => {
    it('array', async () => {
      const pricesNow = cachedResponses.returns
      assert.strictEqual(pricesNow.length, global.pageSize)
    })
  })

  describe('configuration', () => {
    it('environment PAGE_SIZE', async () => {
      const pricesNow = cachedResponses.pageSize
      assert.strictEqual(pricesNow.length, global.pageSize + 1)
    })
  })
})