Stripe Subscriptions module API explorer

/api/administrator/subscriptions/products (GET)

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

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

Returns array

[
  {
    "productid": "prod_LwGuvgaNH23Ws7",
    "object": "product",
    "stripeObject": {
      "id": "prod_LwGuvgaNH23Ws7",
      "object": "product",
      "active": true,
      "attributes": [],
      "created": 1656122690,
      "default_price": null,
      "description": null,
      "images": [],
      "livemode": false,
      "metadata": {},
      "name": "product192",
      "package_dimensions": null,
      "shippable": null,
      "statement_descriptor": "product192 description",
      "tax_code": "txcd_41060003",
      "type": "service",
      "unit_label": "thing",
      "updated": 1656122690,
      "url": null
    },
    "active": true,
    "appid": "tests_1656122688",
    "createdAt": "2022-06-25T02:04:50.432Z",
    "updatedAt": "2022-06-25T02:04:50.433Z"
  },
  {
    "productid": "prod_LwGuDBUkDaJXLl",
    "object": "product",
    "stripeObject": {
      "id": "prod_LwGuDBUkDaJXLl",
      "object": "product",
      "active": true,
      "attributes": [],
      "created": 1656122689,
      "default_price": null,
      "description": null,
      "images": [],
      "livemode": false,
      "metadata": {},
      "name": "product191",
      "package_dimensions": null,
      "shippable": null,
      "statement_descriptor": "product191 description",
      "tax_code": "txcd_41060003",
      "type": "service",
      "unit_label": "thing",
      "updated": 1656122689,
      "url": null
    },
    "active": true,
    "appid": "tests_1656122688",
    "createdAt": "2022-06-25T02:04:50.089Z",
    "updatedAt": "2022-06-25T02:04:50.475Z"
  },
  {
    "productid": "prod_LwGujMbDWuGrFf",
    "object": "product",
    "stripeObject": {
      "id": "prod_LwGujMbDWuGrFf",
      "object": "product",
      "active": true,
      "attributes": [],
      "created": 1656122689,
      "default_price": null,
      "description": null,
      "images": [],
      "livemode": false,
      "metadata": {},
      "name": "product190",
      "package_dimensions": null,
      "shippable": null,
      "statement_descriptor": "product190 description",
      "tax_code": "txcd_41060003",
      "type": "service",
      "unit_label": "thing",
      "updated": 1656122689,
      "url": null
    },
    "active": true,
    "appid": "tests_1656122688",
    "createdAt": "2022-06-25T02:04:49.730Z",
    "updatedAt": "2022-06-25T02:04:50.160Z"
  }
]

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 productids
    if (req.query.all) {
      productids = await subscriptions.Storage.Product.findAll({
        where,
        attributes: ['productid'],
        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
      productids = await subscriptions.Storage.Product.findAll({
        where,
        attributes: ['productid'],
        offset,
        limit,
        order: [
          ['createdAt', 'DESC']
        ]
      })
    }
    if (!productids || !productids.length) {
      return null
    }
    const items = []
    for (const productInfo of productids) {
      req.query.productid = productInfo.dataValues.productid
      const product = await global.api.administrator.subscriptions.Product.get(req)
      items.push(product)
    }
    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/products', function () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  let cachedResponses, cachedProducts
  async function bundledData (retryNumber) {
    if (retryNumber > 0) {
      cachedResponses = {}
    }
    if (cachedResponses && cachedResponses.finished) {
      return
    }
    cachedResponses = {}
    cachedProducts = []
    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.productid)
    }
    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()
    global.pageSize = 2
    cachedResponses.finished = true
  }
  describe('receives', () => {
    it('optional querystring offset (integer)', async function () {
      await bundledData(this.test.currentRetry())
      const offset = 1
      const productsNow = cachedResponses.offset
      for (let i = 0, len = global.pageSize; i < len; i++) {
        assert.strictEqual(productsNow[i].productid, cachedProducts[offset + i])
      }
    })

    it('optional querystring limit (integer)', async function () {
      await bundledData(this.test.currentRetry())
      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 () => {
      const productsNow = cachedResponses.pageSize
      assert.strictEqual(productsNow.length, global.pageSize + 1)
    })
  })
})