Stripe Subscriptions module API explorer

/api/administrator/subscriptions/tax-codes (GET)

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

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

Returns array

[
  {
    "taxcodeid": "txcd_92010001",
    "object": "taxcode",
    "description": "A shipping charge for the delivery of physical goods in conjunction with the sale of these goods. This tax category is not appropriate for stand alone transportation charges that are not associated with the sale of the goods being delivered.",
    "name": "Shipping",
    "createdAt": "2022-06-25T00:53:27.462Z",
    "updatedAt": "2022-06-25T00:53:27.462Z"
  },
  {
    "taxcodeid": "txcd_41060003",
    "object": "taxcode",
    "description": "Milk type beverages from non-animal sources, such as soy, rice, almond, coconut, peanut, and hemp.",
    "name": "Milk substitutes",
    "createdAt": "2022-06-25T00:53:27.461Z",
    "updatedAt": "2022-06-25T00:53:27.461Z"
  },
  {
    "taxcodeid": "txcd_41060006",
    "object": "taxcode",
    "description": "Milk or milk substitutes, or drinks with bases of milk, coffee, unsweetened tea or cocoa.",
    "name": "Milk, coffee, tea, and cocoa beverages",
    "createdAt": "2022-06-25T00:53:27.461Z",
    "updatedAt": "2022-06-25T00:53:27.461Z"
  }
]

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 || {}
    let taxcodeids
    if (req.query.all) {
      taxcodeids = await subscriptions.Storage.TaxCode.findAll({
        attributes: ['taxcodeid'],
        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
      taxcodeids = await subscriptions.Storage.TaxCode.findAll({
        attributes: ['taxcodeid'],
        offset,
        limit,
        order: [
          ['createdAt', 'DESC']
        ]
      })
    }
    if (!taxcodeids || !taxcodeids.length) {
      return null
    }
    const items = []
    for (const taxCodeInfo of taxcodeids) {
      req.query.taxcodeid = taxCodeInfo.dataValues.taxcodeid
      const taxCode = await global.api.administrator.subscriptions.TaxCode.get(req)
      items.push(taxCode)
    }
    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/tax-codes', function () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  let cachedResponses
  async function bundledData (retryNumber) {
    if (retryNumber > 0) {
      cachedResponses = {}
    }
    if (cachedResponses && cachedResponses.finished) {
      return
    }
    cachedResponses = {}
    await TestHelper.setupBefore()
    await DashboardTestHelper.setupBeforeEach()
    await TestHelper.setupBeforeEach()
    const administrator = await TestHelper.createOwner()
    const req1 = TestHelper.createRequest('/api/administrator/subscriptions/tax-codes?offset=1')
    req1.account = administrator.account
    req1.session = administrator.session
    cachedResponses.offset = await req1.get()
    const req2 = TestHelper.createRequest('/api/administrator/subscriptions/tax-codes?limit=1')
    req2.account = administrator.account
    req2.session = administrator.session
    cachedResponses.limit = await req2.get()
    const req3 = TestHelper.createRequest('/api/administrator/subscriptions/tax-codes?all=true')
    req3.account = administrator.account
    req3.session = administrator.session
    cachedResponses.all = await req3.get()
    const req4 = TestHelper.createRequest('/api/administrator/subscriptions/tax-codes')
    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 secondTaxCode = cachedResponses.returns[1]
      const taxCodesNow = cachedResponses.offset
      assert.strictEqual(taxCodesNow[0].taxcodeid, secondTaxCode.taxcodeid)
    })

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

    it('optional querystring all (boolean)', async () => {
      const taxCodesNow = cachedResponses.all
      assert.notStrictEqual(taxCodesNow.length, global.pageSize)
    })
  })

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

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