Stripe Subscriptions module API explorer

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

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

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

Returns array

[
  {
    "taxrateid": "txr_1LEOWpHHqepMFuCXt4BA5q8r",
    "object": "taxrate",
    "stripeObject": {
      "id": "txr_1LEOWpHHqepMFuCXt4BA5q8r",
      "object": "tax_rate",
      "active": true,
      "country": "US",
      "created": 1656123319,
      "description": "Sales tax in NY",
      "display_name": "NY Sales Tax",
      "inclusive": true,
      "jurisdiction": "US",
      "livemode": false,
      "metadata": {},
      "percentage": 17.5,
      "state": "NY",
      "tax_type": "sales_tax"
    },
    "appid": "tests_1656123318",
    "createdAt": "2022-06-25T02:15:19.863Z",
    "updatedAt": "2022-06-25T02:15:19.863Z"
  },
  {
    "taxrateid": "txr_1LEOWpHHqepMFuCXVvE96laM",
    "object": "taxrate",
    "stripeObject": {
      "id": "txr_1LEOWpHHqepMFuCXVvE96laM",
      "object": "tax_rate",
      "active": true,
      "country": "US",
      "created": 1656123319,
      "description": "Sales tax in NY",
      "display_name": "NY Sales Tax",
      "inclusive": true,
      "jurisdiction": "US",
      "livemode": false,
      "metadata": {},
      "percentage": 17.5,
      "state": "NY",
      "tax_type": "sales_tax"
    },
    "appid": "tests_1656123318",
    "createdAt": "2022-06-25T02:15:19.498Z",
    "updatedAt": "2022-06-25T02:15:19.498Z"
  },
  {
    "taxrateid": "txr_1LEOWpHHqepMFuCXcG3hIsBs",
    "object": "taxrate",
    "stripeObject": {
      "id": "txr_1LEOWpHHqepMFuCXcG3hIsBs",
      "object": "tax_rate",
      "active": true,
      "country": "US",
      "created": 1656123319,
      "description": "Sales tax in NY",
      "display_name": "NY Sales Tax",
      "inclusive": true,
      "jurisdiction": "US",
      "livemode": false,
      "metadata": {},
      "percentage": 17.5,
      "state": "NY",
      "tax_type": "sales_tax"
    },
    "appid": "tests_1656123318",
    "createdAt": "2022-06-25T02:15:19.203Z",
    "updatedAt": "2022-06-25T02:15:19.203Z"
  }
]

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 taxrateids
    if (req.query.all) {
      taxrateids = await subscriptions.Storage.TaxRate.findAll({
        where,
        attributes: ['taxrateid'],
        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
      taxrateids = await subscriptions.Storage.TaxRate.findAll({
        where,
        attributes: ['taxrateid'],
        offset,
        limit,
        order: [
          ['createdAt', 'DESC']
        ]
      })
    }
    if (!taxrateids || !taxrateids.length) {
      return null
    }
    const items = []
    for (const taxRateInfo of taxrateids) {
      req.query.taxrateid = taxRateInfo.dataValues.taxrateid
      const taxRate = await global.api.administrator.subscriptions.TaxRate.get(req)
      items.push(taxRate)
    }
    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-rates', 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()
    for (let i = 0, len = global.pageSize + 2; i < len; i++) {
      await TestHelper.createTaxRate(administrator)
    }
    const req1 = TestHelper.createRequest('/api/administrator/subscriptions/tax-rates?offset=1')
    req1.account = administrator.account
    req1.session = administrator.session
    cachedResponses.offset = await req1.get()
    const req2 = TestHelper.createRequest('/api/administrator/subscriptions/tax-rates?limit=1')
    req2.account = administrator.account
    req2.session = administrator.session
    cachedResponses.limit = await req2.get()
    const req3 = TestHelper.createRequest('/api/administrator/subscriptions/tax-rates?all=true')
    req3.account = administrator.account
    req3.session = administrator.session
    cachedResponses.all = await req3.get()
    const req4 = TestHelper.createRequest('/api/administrator/subscriptions/tax-rates')
    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].taxrateid, secondTaxCode.taxrateid)
    })

    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)
    })
  })
})