Stripe Subscriptions module API explorer

/api/administrator/subscriptions/products (GET)

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

Returns array

Exceptions

These exceptions are thrown (NodeJS) or returned as JSON (HTTP) if you provide incorrect data or do not meet the requirements:

Exception Circumstances

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 (edit on github)

If you see a problem with the source submit a pull request on Github.

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

module.exports = {
  get: async (req) => {
    req.query = req.query || {}
    let productids
    if (req.query.all) {
      productids = await subscriptions.StorageList.listAll(`${req.appid}/products`)
    } else {
      const offset = req.query.offset ? parseInt(req.query.offset, 10) : 0
      const limit = req.query.limit ? parseInt(req.query.limit, 10) : global.pageSize
      productids = await subscriptions.StorageList.list(`${req.appid}/products`, offset, limit)
    }
    if (!productids || !productids.length) {
      return null
    }
    const items = []
    for (const productid of productids) {
      req.query.productid = productid
      const product = await global.api.administrator.subscriptions.Product.get(req)
      items.push(product)
    }
    return items
  }
}

Test source (edit on github)

Tests perform real HTTP requests against a running Dashboard server.

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

describe('/api/administrator/subscriptions/products', function () {
  this.timeout(60 * 60 * 1000)
  const cachedResponses = {}
  const cachedProducts = []
  before(async () => {
    await DashboardTestHelper.setupBeforeEach()
    await TestHelper.setupBeforeEach()
    const administrator = await TestHelper.createOwner()
    for (let i = 0, len = global.pageSize + 2; i < len; i++) {
      await TestHelper.createProduct(administrator)
      cachedProducts.unshift(administrator.product.id)
    }
    const req1 = TestHelper.createRequest('/api/administrator/subscriptions/products?offset=1')
    req1.account = administrator.account
    req1.session = administrator.session
    cachedResponses.offset = await req1.get()
    const req2 = TestHelper.createRequest('/api/administrator/subscriptions/products?limit=1')
    req2.account = administrator.account
    req2.session = administrator.session
    cachedResponses.limit = await req2.get()
    const req3 = TestHelper.createRequest('/api/administrator/subscriptions/products?all=true')
    req3.account = administrator.account
    req3.session = administrator.session
    cachedResponses.all = await req3.get()
    const req4 = TestHelper.createRequest('/api/administrator/subscriptions/products')
    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()
  })
  describe('receives', () => {
    it('optional querystring offset (integer)', async () => {
      const offset = 1
      const productsNow = cachedResponses.offset
      for (let i = 0, len = global.pageSize; i < len; i++) {
        assert.strictEqual(productsNow[i].id, cachedProducts[offset + i])
      }
    })

    it('optional querystring limit (integer)', async () => {
      const limit = 1
      const productsNow = cachedResponses.limit
      assert.strictEqual(productsNow.length, limit)
    })

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

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

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