Stripe Subscriptions module API explorer

/api/user/subscriptions/set-setup-intent-canceled (PATCH)

await global.api.user.subscriptions.SetSetupIntentCanceled.patch(req)

Returns object

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 querystring setupintentid
invalid-setupintentid missing querystring setupintentid
invalid-account ineligible accessing account

NodeJS source (edit on github)

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

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

module.exports = {
  patch: async (req) => {
    if (!req.query || !req.query.setupintentid) {
      throw new Error('invalid-setupintentid')
    }
    const setupIntent = await global.api.user.subscriptions.SetupIntent.get(req)
    if (!setupIntent) {
      throw new Error('invalid-setupintentid')
    }
    req.query.customerid = setupIntent.customer
    const customer = await global.api.user.subscriptions.Customer.get(req)
    if (!customer) {
      throw new Error('invalid-setupintentid')
    }
    try {
      await subscriptions.StorageList.remove(`${req.appid}/setupIntents`, req.query.setupintentid)
    } catch (error) {
    }
    try {
      await subscriptions.StorageList.remove(`${req.appid}/account/setupIntents/${req.account.accountid}`, req.query.setupintentid)
    } catch (error) {
    }
    try {
      await subscriptions.Storage.delete(`${req.appid}/map/accountid/setupintentid/${req.query.setupintentid}`)
    } catch (error) {
    }
    const setupIntentNow = await stripeCache.execute('setupIntents', 'cancel', req.query.setupintentid, req.stripeKey)
    await stripeCache.delete(req.query.setupintentid, req.stripeKey)
    return setupIntentNow
  }
}

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 TestStripeAccounts = require('../../../../../test-stripe-accounts.js')

describe('/api/user/subscriptions/set-setup-intent-canceled', function () {
  this.timeout(60 * 60 * 1000)
  after(TestHelper.deleteOldWebhooks)
  before(TestHelper.setupWebhook)
  describe('exceptions', () => {
    describe('invalid-setupintentid', () => {
      it('missing querystring setupintentid', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest('/api/user/subscriptions/set-setup-intent-canceled')
        req.account = user.account
        req.session = user.session
        let errorMessage
        try {
          await req.patch()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-setupintentid')
      })

      it('invalid querystring setupintentid', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest('/api/user/subscriptions/set-setup-intent-canceled?setupintentid=invalid')
        req.account = user.account
        req.session = user.session
        let errorMessage
        try {
          await req.patch()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-setupintentid')
      })
    })

    describe('invalid-account', () => {
      it('ineligible accessing account', async () => {
        const user = await TestStripeAccounts.createUserWithPaymentMethod()
        const user2 = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/subscriptions/set-setup-intent-canceled?setupintentid=${user.setupIntent.id}`)
        req.account = user2.account
        req.session = user2.session
        let errorMessage
        try {
          await req.patch()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-account')
      })
    })
  })

  describe('returns', () => {
    it('object', async () => {
      const user = await TestStripeAccounts.createUserWithPaymentMethod()
      const req = TestHelper.createRequest(`/api/user/subscriptions/set-setup-intent-canceled?setupintentid=${user.setupIntent.id}`)
      req.account = user.account
      req.session = user.session
      req.filename = __filename
      req.saveResponse = true
      const setupIntentNow = await req.patch()
      assert.strictEqual(setupIntentNow.status, 'canceled')
    })
  })
})