Stripe Subscriptions module API explorer

/api/user/subscriptions/delete-tax-id (DELETE)

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

await global.api.user.subscriptions.DeleteTaxId.delete(req)

Exceptions

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

Exception Circumstances
invalid-account ineligible accessing account
invalid-taxid missing querystring taxid
invalid querystring taxid

NodeJS source (view on github)

const subscriptions = require('../../../../../index.js')
const stripeCache = require('../../../../stripe-cache.js')

module.exports = {
  delete: async (req) => {
    if (!req.query || !req.query.taxid) {
      throw new Error('invalid-taxid')
    }
    const taxid = await global.api.user.subscriptions.TaxId.get(req)
    if (!taxid) {
      throw new Error('invalid-taxid')
    }
    await stripeCache.execute('customers', 'deleteTaxId', taxid.customerid, req.query.taxid, req.stripeKey)
    await subscriptions.Storage.TaxId.destroy({
      where: {
        taxid: req.query.taxid,
        appid: req.appid || global.appid
      }
    })
    return true
  }
}

Test source (view on github)

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

describe('/api/user/subscriptions/delete-tax-id', function () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  describe('exceptions', () => {
    describe('invalid-taxid', () => {
      it('missing querystring taxid', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest('/api/user/subscriptions/delete-tax-id')
        req.account = user.account
        req.session = user.session
        let errorMessage
        try {
          await req.delete()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-taxid')
      })

      it('invalid querystring taxid', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest('/api/user/subscriptions/delete-tax-id?taxid=invalid')
        req.account = user.account
        req.session = user.session
        let errorMessage
        try {
          await req.delete()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-taxid')
      })
    })

    describe('invalid-account', () => {
      it('ineligible accessing account', async () => {
        const user = await TestHelper.createUser()
        const user2 = await TestHelper.createUser()
        await TestHelper.createCustomer(user2, {
          email: user2.profile.contactEmail
        })
        await TestHelper.createTaxId(user2, user2.customer)
        const req = TestHelper.createRequest(`/api/user/subscriptions/delete-tax-id?taxid=${user2.taxid.taxid}`)
        req.account = user.account
        req.session = user.session
        let errorMessage
        try {
          await req.delete()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-account')
      })
    })
  })

  describe('returns', () => {
    it('boolean', async () => {
      const user = await TestHelper.createUser()
      await TestHelper.createCustomer(user, {
        email: user.profile.contactEmail
      })
      await TestHelper.createTaxId(user, user.customer)
      const req = TestHelper.createRequest(`/api/user/subscriptions/delete-tax-id?taxid=${user.taxid.taxid}`)
      req.account = user.account
      req.session = user.session
      req.filename = __filename
      req.saveResponse = true
      const deleted = await req.delete()
      assert.strictEqual(deleted, true)
    })
  })
})