Stripe Subscriptions module API explorer

/api/administrator/subscriptions/set-price-inactive (PATCH)

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

await global.api.administrator.subscriptions.SetPriceInactive.patch(req)

Returns object

{
  "priceid": "price_1LEORwHHqepMFuCXoO8pMykq",
  "object": "price",
  "stripeObject": {
    "id": "price_1LEORwHHqepMFuCXoO8pMykq",
    "object": "price",
    "active": false,
    "billing_scheme": "per_unit",
    "created": 1656123016,
    "currency": "usd",
    "custom_unit_amount": null,
    "livemode": false,
    "lookup_key": null,
    "metadata": {},
    "nickname": null,
    "product": "prod_LwGznSuGOqTYXC",
    "recurring": {
      "aggregate_usage": null,
      "interval": "month",
      "interval_count": 1,
      "trial_period_days": null,
      "usage_type": "licensed"
    },
    "tax_behavior": "inclusive",
    "tiers_mode": null,
    "transform_quantity": null,
    "type": "recurring",
    "unit_amount": 1000,
    "unit_amount_decimal": "1000"
  },
  "productid": "prod_LwGznSuGOqTYXC",
  "active": false,
  "appid": "tests_1656123015",
  "createdAt": "2022-06-25T02:10:16.840Z",
  "updatedAt": "2022-06-25T02:10:17.219Z"
}

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-price ineligible querystring price is not active
ineligible querystring price is already inactive
invalid-priceid missing querystring priceid
invalid querystring priceid

NodeJS source (view on github)

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

module.exports = {
  patch: async (req) => {
    if (!req.query || !req.query.priceid) {
      throw new Error('invalid-priceid')
    }
    const price = await global.api.administrator.subscriptions.Price.get(req)
    if (!price) {
      throw new Error('invalid-priceid')
    }
    if (!price.stripeObject.active) {
      throw new Error('invalid-price')
    }
    const updateInfo = {
      active: 'false'
    }
    const priceNow = await stripeCache.execute('prices', 'update', req.query.priceid, updateInfo, req.stripeKey)
    await subscriptions.Storage.Price.update({
      stripeObject: priceNow,
      active: priceNow.active
    }, {
      where: {
        priceid: req.query.priceid,
        appid: req.appid || global.appid
      }
    })
    await dashboard.StorageCache.remove(req.query.priceid)
    return global.api.administrator.subscriptions.Price.get(req)
  }
}

Test source (view on github)

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

describe('/api/administrator/subscriptions/set-price-inactive', function () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  describe('exceptions', () => {
    describe('invalid-priceid', () => {
      it('missing querystring priceid', async () => {
        const administrator = await TestHelper.createOwner()
        const req = TestHelper.createRequest('/api/administrator/subscriptions/set-price-inactive')
        req.account = administrator.account
        req.session = administrator.session
        let errorMessage
        try {
          await req.patch(req)
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-priceid')
      })

      it('invalid querystring priceid', async () => {
        const administrator = await TestHelper.createOwner()
        const req = TestHelper.createRequest('/api/administrator/subscriptions/set-price-inactive?priceid=invalid')
        req.account = administrator.account
        req.session = administrator.session
        let errorMessage
        try {
          await req.patch(req)
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-priceid')
      })
    })

    describe('invalid-price', () => {
      it('ineligible querystring price is not active', async () => {
        const administrator = await TestStripeAccounts.createOwnerWithInactivePrice()
        const req = TestHelper.createRequest(`/api/administrator/subscriptions/set-price-inactive?priceid=${administrator.price.priceid}`)
        req.account = administrator.account
        req.session = administrator.session
        let errorMessage
        try {
          await req.patch(req)
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-price')
      })

      it('ineligible querystring price is already inactive', async () => {
        const administrator = await TestStripeAccounts.createOwnerWithInactivePrice()
        const req = TestHelper.createRequest(`/api/administrator/subscriptions/set-price-inactive?priceid=${administrator.price.priceid}`)
        req.account = administrator.account
        req.session = administrator.session
        let errorMessage
        try {
          await req.patch(req)
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-price')
      })
    })
  })

  describe('returns', () => {
    it('object', async () => {
      const administrator = await TestStripeAccounts.createOwnerWithPrice()
      const req = TestHelper.createRequest(`/api/administrator/subscriptions/set-price-inactive?priceid=${administrator.price.priceid}`)
      req.account = administrator.account
      req.session = administrator.session
      req.filename = __filename
      req.saveResponse = true
      const price = await req.patch()
      assert.strictEqual(price.stripeObject.active, false)
    })
  })
})