Stripe Subscriptions module API explorer

/api/administrator/subscriptions/create-price (POST)

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

await global.api.administrator.subscriptions.CreatePrice.post(req)

Returns object

{
  "priceid": "price_1LEOHcHHqepMFuCXqwmisJA0",
  "object": "price",
  "stripeObject": {
    "id": "price_1LEOHcHHqepMFuCXqwmisJA0",
    "object": "price",
    "active": true,
    "billing_scheme": "per_unit",
    "created": 1656122376,
    "currency": "usd",
    "custom_unit_amount": null,
    "livemode": false,
    "lookup_key": null,
    "metadata": {},
    "nickname": null,
    "product": "prod_LwGp5kMISl1vS2",
    "recurring": {
      "aggregate_usage": "sum",
      "interval": "month",
      "interval_count": 1,
      "trial_period_days": null,
      "usage_type": "metered"
    },
    "tax_behavior": "inclusive",
    "tiers_mode": null,
    "transform_quantity": null,
    "type": "recurring",
    "unit_amount": 1000,
    "unit_amount_decimal": "1000"
  },
  "productid": "prod_LwGp5kMISl1vS2",
  "active": true,
  "appid": "tests_1656122375",
  "createdAt": "2022-06-25T01:59:36.397Z",
  "updatedAt": "2022-06-25T01:59:36.397Z"
}

Receives

API routes may receive parameters from the URL and POST supporting simple and multipart:

Field Value Required Type
active boolean optional POST
billing_scheme per_unit, tiered optional POST
currency string required POST
productid string required POST
recurring_aggregate_usage sum, max, last_ever, last_during_period configurable as required POST
recurring_interval day, week, month, year optional POST
recurring_interval_count string configurable as required POST
recurring_usage_type licensed, metered optional POST
tax_behavior string required POST
tier 1... optional POST
tier 1... optional POST
tier 1... optional POST
tiers_mode graduated, volume configurable as required POST
transform_quantity_divide_by string optional POST
transform_quantity_round up, down configurable as required POST
unit_amount string configurable as required POST

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-billing_scheme invalid posted billing_scheme
invalid-currency missing posted currency
invalid posted currency
invalid-product ineligible posted product is not active
invalid-productid missing posted productid
invalid posted productid
invalid-recurring_aggregate_usage invalid posted recurring_aggregate_usage
invalid-recurring_interval invalid posted recurring_interval
invalid-recurring_interval_count missing posted recurring_interval_count
invalid posted recurring_interval_count
invalid posted recurring_interval_count exceeds one year
invalid-recurring_usage_type invalid posted recurring_usage_type
invalid-tax_behavior invalid posted tax_behavior
invalid-tier_flat_amount invalid posted tier_flat_amount
invalid-tier_unit_amount invalid posted tier_unit_amount
invalid-tier_up_to invalid posted tier_up_to
invalid-tiers_mode invalid posted tiers_mode
invalid-transform_quantity_divide_by invalid posted transform_quantity_divide_by
invalid-transform_quantity_round invalid posted transform_quantity_round
invalid-unit_amount invalid posted unit_amount

NodeJS source (view on github)

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

module.exports = {
  post: async (req) => {
    if (!req.body || !req.body.productid || !req.body.productid.length) {
      throw new Error('invalid-productid')
    }
    if (!req.body.currency || req.body.currency.length !== 3) {
      throw new Error('invalid-currency')
    }
    req.query = req.query || {}
    req.query.productid = req.body.productid
    const product = await global.api.administrator.subscriptions.Product.get(req)
    if (!product) {
      throw new Error('invalid-productid')
    }
    if (!product.active) {
      throw new Error('invalid-product')
    }
    if (!req.body.tax_behavior || (req.body.tax_behavior !== 'inclusive' && req.body.tax_behavior !== 'exclusive')) {
      throw new Error('invalid-tax_behavior')
    }
    if (req.body.recurring_usage_type && req.body.recurring_usage_type !== 'metered' && req.body.recurring_usage_type !== 'licensed') {
      throw new Error('invalid-recurring_usage_type')
    }
    if (!req.body.unit_amount && req.body.billing_scheme === 'per_unit') {
      throw new Error('invalid-unit_amount')
    }
    if (req.body.unit_amount) {
      if (req.body.unit_amount.indexOf('.') === -1) {
        try {
          const amount = parseInt(req.body.unit_amount, 10)
          if (req.body.unit_amount !== amount.toString()) {
            throw new Error('invalid-unit_amount')
          }
          if (amount < 0) {
            throw new Error('invalid-unit_amount')
          }
        } catch (s) {
          throw new Error('invalid-unit_amount')
        }
      } else {
        try {
          const amount = parseFloat(req.body.unit_amount)
          if (req.body.unit_amount !== amount.toString()) {
            throw new Error('invalid-unit_amount')
          }
          if (amount < 0) {
            throw new Error('invalid-unit_amount')
          }
        } catch (s) {
          throw new Error('invalid-unit_amount')
        }
        req.body.unit_amount_decimal = req.body.unit_amount
        delete (req.body.unit_amount)
      }
    }
    if (req.body.recurring_interval &&
        req.body.recurring_interval !== 'day' &&
        req.body.recurring_interval !== 'week' &&
        req.body.recurring_interval !== 'month' &&
        req.body.recurring_interval !== 'year') {
      throw new Error('invalid-recurring_interval')
    }
    if (req.body.recurring_interval && !req.body.recurring_interval_count) {
      throw new Error('invalid-recurring_interval_count')
    }
    if (req.body.recurring_interval) {
      try {
        req.body.recurring_interval_count = parseInt(req.body.recurring_interval_count, 10)
        if (!req.body.recurring_interval_count) {
          throw new Error('invalid-recurring_interval_count')
        }
      } catch (s) {
        throw new Error('invalid-recurring_interval_count')
      }
      if (req.body.recurring_interval_count < 1) {
        throw new Error('invalid-recurring_interval_count')
      }
      if (req.body.recurring_interval === 'day' && req.body.recurring_interval_count > 365) {
        throw new Error('invalid-recurring_interval_count')
      } else if (req.body.recurring_interval === 'week' && req.body.recurring_interval_count > 52) {
        throw new Error('invalid-recurring_interval_count')
      } else if (req.body.recurring_interval === 'month' && req.body.recurring_interval_count > 12) {
        throw new Error('invalid-recurring_interval_count')
      } else if (req.body.recurring_interval_count > 1) {
        throw new Error('invalid-recurring_interval_count')
      }
    }
    if (req.body.recurring_usage_type === 'metered') {
      if (req.body.recurring_aggregate_usage !== 'sum' &&
          req.body.recurring_aggregate_usage !== 'last_during_period' &&
          req.body.recurring_aggregate_usage !== 'last_ever' &&
          req.body.recurring_aggregate_usage !== 'max') {
        throw new Error('invalid-recurring_aggregate_usage')
      }
    }
    if (req.body.billing_scheme && req.body.billing_scheme !== 'per_unit' && req.body.billing_scheme !== 'tiered') {
      throw new Error('invalid-billing_scheme')
    }
    if (req.body.billing_scheme === 'per_unit') {
      if (req.body.transform_quantity_divide_by) {
        try {
          const amount = parseFloat(req.body.transform_quantity_divide_by)
          if (req.body.transform_quantity_divide_by !== amount.toString()) {
            throw new Error('invalid-transform_quantity_divide_by')
          }
          if (amount < 0) {
            throw new Error('invalid-transform_quantity_divide_by')
          }
        } catch (s) {
          throw new Error('invalid-transform_quantity_divide_by')
        }
        if (req.body.transform_quantity_round !== 'up' && req.body.transform_quantity_round !== 'down') {
          throw new Error('invalid-transform_quantity_round')
        }
      }
    } else if (req.body.billing_scheme === 'tiered') {
      if (req.body.tiers_mode !== 'graduated' && req.body.tiers_mode !== 'volume') {
        throw new Error('invalid-tiers_mode')
      }
    }
    const priceInfo = {
      billing_scheme: req.body.billing_scheme,
      nickname: req.body.nickname,
      product: req.body.productid,
      currency: req.body.currency,
      tax_behavior: req.body.tax_behavior,
      unit_amount: req.body.unit_amount || undefined,
      unit_amount_decimal: req.body.unit_amount_decimal || undefined,
      recurring: {
        interval: req.body.recurring_interval,
        interval_count: req.body.recurring_interval_count || 0,
        usage_type: req.body.recurring_usage_type || 'licensed'
      }
    }
    if (req.body.recurring_usage_type === 'metered') {
      priceInfo.recurring.aggregate_usage = req.body.recurring_aggregate_usage
    }
    if (req.body.billing_scheme === 'tiered') {
      priceInfo.tiers_mode = req.body.tiers_mode
      priceInfo.tiers = []
      let tierNumber = 1
      while (true) {
        if (!req.body[`tier${tierNumber}_up_to`]) {
          break
        }
        if (req.body[`tier${tierNumber}_up_to`] !== 'inf') {
          try {
            const upto = parseInt(req.body[`tier${tierNumber}_up_to`], 10)
            if (req.body[`tier${tierNumber}_up_to`] !== upto.toString()) {
              throw new Error('invalid-tier_up_to')
            }
            if (upto < 0) {
              throw new Error('invalid-tier_up_to')
            }
          } catch (s) {
            throw new Error('invalid-tier_up_to')
          }
        }
        const tier = {
          up_to: req.body[`tier${tierNumber}_up_to`]
        }
        if (req.body[`tier${tierNumber}_unit_amount`]) {
          if (req.body[`tier${tierNumber}_unit_amount`].indexOf('.') === -1) {
            try {
              const amount = parseInt(req.body[`tier${tierNumber}_unit_amount`], 10)
              if (req.body[`tier${tierNumber}_unit_amount`] !== amount.toString()) {
                throw new Error('invalid-tier_unit_amount')
              }
              if (amount < 0) {
                throw new Error('invalid-tier_unit_amount')
              }
            } catch (s) {
              throw new Error('invalid-tier_unit_amount')
            }
            tier.unit_amount = req.body[`tier${tierNumber}_unit_amount`]
          } else {
            try {
              const amount = parseFloat(req.body[`tier${tierNumber}_unit_amount`])
              if (req.body[`tier${tierNumber}_unit_amount`] !== amount.toString()) {
                throw new Error('invalid-tier_unit_amount')
              }
              if (amount < 0) {
                throw new Error('invalid-tier_unit_amount')
              }
            } catch (s) {
              throw new Error('invalid-tier_unit_amount')
            }
            tier.unit_amount_decimal = req.body[`tier${tierNumber}_unit_amount`]
          }
        } else if (req.body[`tier${tierNumber}_flat_amount`]) {
          if (req.body[`tier${tierNumber}_flat_amount`].indexOf('.') === -1) {
            try {
              const amount = parseInt(req.body[`tier${tierNumber}_flat_amount`], 10)
              if (req.body[`tier${tierNumber}_flat_amount`] !== amount.toString()) {
                throw new Error('invalid-tier_flat_amount')
              }
              if (amount < 0) {
                throw new Error('invalid-tier_flat_amount')
              }
            } catch (s) {
              throw new Error('invalid-tier_flat_amount')
            }
            tier.flat_amount = req.body[`tier${tierNumber}_flat_amount`]
          } else {
            try {
              const amount = parseFloat(req.body[`tier${tierNumber}_flat_amount`])
              if (req.body[`tier${tierNumber}_flat_amount`] !== amount.toString()) {
                throw new Error('invalid-tier_flat_amount')
              }
              if (amount < 0) {
                throw new Error('invalid-tier_flat_amount')
              }
            } catch (s) {
              throw new Error('invalid-tier_flat_amount')
            }
            tier.flat_amount_decimal = req.body[`tier${tierNumber}_flat_amount`]
            delete (req.body[`tier${tierNumber}_flat_amount`])
          }
        }
        priceInfo.tiers.push(tier)
        tierNumber++
      }
    } else {
      if (req.body.transform_quantity_divide_by) {
        priceInfo.transform_quantity = {
          divide_by: req.body.transform_quantity_divide_by,
          round: req.body.transform_quantity_round
        }
      }
    }
    if (req.body.active) {
      priceInfo.active = true
    }
    const price = await stripeCache.execute('prices', 'create', priceInfo, req.stripeKey)
    const priceExpanded = await stripeCache.execute('prices', 'retrieve', price.id, {
      expand: ['tiers']
    }, req.stripeKey)
    await subscriptions.Storage.Price.create({
      appid: req.appid || global.appid,
      priceid: price.id,
      productid: req.body.productid,
      stripeObject: priceExpanded,
      active: price.active
    })
    req.query.priceid = price.id
    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')

describe('/api/administrator/subscriptions/create-price', function () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  describe('exceptions', () => {
    describe('invalid-productid', () => {
      it('missing posted productid', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'true'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: 'usd',
          unit_amount: '1000',
          recurring_interval: 'month',
          recurring_interval_count: '1',
          tax_behavior: 'inclusive',
          productid: ''
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-productid')
      })

      it('invalid posted productid', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'true'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: 'usd',
          unit_amount: '1000',
          recurring_interval: 'month',
          recurring_interval_count: '1',
          tax_behavior: 'inclusive',
          productid: 'invalid'
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-productid')
      })
    })

    describe('invalid-product', () => {
      it('ineligible posted product is not active', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'false'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: 'usd',
          unit_amount: '1000',
          recurring_interval: 'month',
          recurring_interval_count: '1',
          productid: administrator.product.productid,
          tax_behavior: 'inclusive'
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-product')
      })
    })

    describe('invalid-tax_behavior', () => {
      it('invalid posted tax_behavior', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'true'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: 'usd',
          unit_amount: '1000',
          tax_behavior: 'invalid',
          recurring_interval: 'month',
          recurring_interval_count: '1',
          productid: administrator.product.productid
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-tax_behavior')
      })
    })

    describe('invalid-unit_amount', () => {
      it('invalid posted unit_amount', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'true'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: 'usd',
          unit_amount: 'invalid',
          tax_behavior: 'inclusive',
          recurring_interval: 'month',
          recurring_interval_count: '1',
          productid: administrator.product.productid
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-unit_amount')
      })
    })

    describe('invalid-currency', () => {
      it('missing posted currency', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'true'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: '',
          unit_amount: '1000',
          tax_behavior: 'inclusive',
          recurring_interval: 'month',
          recurring_interval_count: '1',
          productid: administrator.product.productid
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-currency')
      })

      it('invalid posted currency', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'true'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: 'invalid',
          unit_amount: '1000',
          tax_behavior: 'inclusive',
          recurring_interval: 'month',
          recurring_interval_count: '1',
          productid: administrator.product.productid
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-currency')
      })
    })

    describe('invalid-recurring_interval', () => {
      it('invalid posted recurring_interval', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'true'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: 'usd',
          unit_amount: '1000',
          tax_behavior: 'inclusive',
          recurring_interval: 'invalid',
          recurring_interval_count: '1',
          productid: administrator.product.productid
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-recurring_interval')
      })
    })

    describe('invalid-recurring_interval_count', () => {
      it('missing posted recurring_interval_count', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'true'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: 'usd',
          unit_amount: '1000',
          tax_behavior: 'inclusive',
          recurring_interval: 'month',
          recurring_interval_count: '',
          productid: administrator.product.productid
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-recurring_interval_count')
      })

      it('invalid posted recurring_interval_count', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'true'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: 'usd',
          unit_amount: '1000',
          tax_behavior: 'inclusive',
          recurring_interval: 'month',
          recurring_interval_count: 'nvalid',
          productid: administrator.product.productid
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-recurring_interval_count')
      })

      it('invalid posted recurring_interval_count exceeds one year', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'true'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: 'usd',
          unit_amount: '1000',
          tax_behavior: 'inclusive',
          recurring_interval: 'month',
          recurring_interval_count: '14',
          productid: administrator.product.productid
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-recurring_interval_count')
      })
    })

    describe('invalid-recurring_aggregate_usage', () => {
      it('invalid posted recurring_aggregate_usage', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'true'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: 'usd',
          unit_amount: '1000',
          tax_behavior: 'inclusive',
          recurring_interval: 'month',
          recurring_interval_count: '1',
          recurring_aggregate_usage: 'invalid',
          recurring_usage_type: 'metered',
          productid: administrator.product.productid
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-recurring_aggregate_usage')
      })
    })

    describe('invalid-recurring_usage_type', () => {
      it('invalid posted recurring_usage_type', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'true'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: 'usd',
          unit_amount: '1000',
          tax_behavior: 'inclusive',
          recurring_interval: 'month',
          recurring_interval_count: '1',
          recurring_usage_type: 'invalid',
          recurring_aggregate_usage: 'sum',
          productid: administrator.product.productid
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-recurring_usage_type')
      })
    })

    describe('invalid-billing_scheme', () => {
      it('invalid posted billing_scheme', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'true'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: 'usd',
          unit_amount: '1000',
          tax_behavior: 'inclusive',
          recurring_interval: 'month',
          recurring_interval_count: '1',
          recurring_usage_type: 'metered',
          recurring_aggregate_usage: 'sum',
          billing_scheme: 'invalid',
          productid: administrator.product.productid
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-billing_scheme')
      })
    })

    describe('invalid-transform_quantity_divide_by', () => {
      it('invalid posted transform_quantity_divide_by', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'true'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: 'usd',
          unit_amount: '1000',
          tax_behavior: 'inclusive',
          recurring_interval: 'month',
          recurring_interval_count: '1',
          recurring_usage_type: 'metered',
          recurring_aggregate_usage: 'sum',
          billing_scheme: 'per_unit',
          transform_quantity_divide_by: 'invalid',
          transform_quantity_round: 'up',
          productid: administrator.product.productid
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-transform_quantity_divide_by')
      })
    })

    describe('invalid-transform_quantity_round', () => {
      it('invalid posted transform_quantity_round', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'true'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: 'usd',
          unit_amount: '1000',
          tax_behavior: 'inclusive',
          recurring_interval: 'month',
          recurring_interval_count: '1',
          recurring_usage_type: 'metered',
          recurring_aggregate_usage: 'sum',
          billing_scheme: 'per_unit',
          transform_quantity_divide_by: '1.2',
          transform_quantity_round: 'invalid',
          productid: administrator.product.productid
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-transform_quantity_round')
      })
    })

    describe('invalid-tiers_mode', () => {
      it('invalid posted tiers_mode', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'true'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: 'usd',
          unit_amount: '1000',
          tax_behavior: 'inclusive',
          recurring_interval: 'month',
          recurring_interval_count: '1',
          recurring_usage_type: 'metered',
          recurring_aggregate_usage: 'sum',
          billing_scheme: 'tiered',
          tiers_mode: 'invalid',
          productid: administrator.product.productid
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-tiers_mode')
      })
    })

    describe('invalid-tier_up_to', () => {
      it('invalid posted tier_up_to', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'true'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: 'usd',
          tax_behavior: 'inclusive',
          recurring_interval: 'month',
          recurring_interval_count: '1',
          recurring_usage_type: 'metered',
          recurring_aggregate_usage: 'sum',
          billing_scheme: 'tiered',
          tiers_mode: 'volume',
          tier1_up_to: 'invalid',
          tier1_unit_amount: '9999',
          tier2_up_to: 'inf',
          tier2_unit_amount: '9999',
          productid: administrator.product.productid
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-tier_up_to')
      })
    })

    describe('invalid-tier_unit_amount', () => {
      it('invalid posted tier_unit_amount', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'true'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: 'usd',
          tax_behavior: 'inclusive',
          unit_amount: '1000',
          recurring_interval: 'month',
          recurring_interval_count: '1',
          recurring_usage_type: 'metered',
          recurring_aggregate_usage: 'sum',
          billing_scheme: 'tiered',
          tiers_mode: 'volume',
          tier1_up_to: '1000',
          tier1_unit_amount: 'invalid',
          productid: administrator.product.productid
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-tier_unit_amount')
      })
    })

    describe('invalid-tier_flat_amount', () => {
      it('invalid posted tier_flat_amount', async () => {
        const administrator = await TestHelper.createOwner()
        await TestHelper.createProduct(administrator, {
          active: 'true'
        })
        const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
        req.account = administrator.account
        req.session = administrator.session
        req.body = {
          currency: 'usd',
          tax_behavior: 'inclusive',
          unit_amount: '1000',
          recurring_interval: 'month',
          recurring_interval_count: '1',
          recurring_usage_type: 'metered',
          recurring_aggregate_usage: 'sum',
          billing_scheme: 'tiered',
          tiers_mode: 'volume',
          tier1_up_to: '1000',
          tier1_flat_amount: 'invalid',
          productid: administrator.product.productid
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-tier_flat_amount')
      })
    })
  })

  describe('receives', () => {
    it('required posted productid', async () => {
      const administrator = await TestHelper.createOwner()
      await TestHelper.createProduct(administrator, {
        active: 'true'
      })
      const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
      req.account = administrator.account
      req.session = administrator.session
      req.body = {
        currency: 'usd',
        tax_behavior: 'inclusive',
        unit_amount: '1000',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'metered',
        recurring_aggregate_usage: 'sum',
        productid: administrator.product.productid
      }
      const price = await req.post()
      assert.strictEqual(price.stripeObject.product, administrator.product.productid)
    })

    it('required posted tax_behavior', async () => {
      const administrator = await TestHelper.createOwner()
      await TestHelper.createProduct(administrator, {
        active: 'true'
      })
      const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
      req.account = administrator.account
      req.session = administrator.session
      req.body = {
        currency: 'usd',
        tax_behavior: 'inclusive',
        unit_amount: '1000',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'metered',
        recurring_aggregate_usage: 'sum',
        productid: administrator.product.productid
      }
      const price = await req.post()
      assert.strictEqual(price.stripeObject.tax_behavior, 'inclusive')
    })

    it('required posted currency', async () => {
      const administrator = await TestHelper.createOwner()
      await TestHelper.createProduct(administrator, {
        active: 'true'
      })
      const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
      req.account = administrator.account
      req.session = administrator.session
      req.body = {
        currency: 'usd',
        tax_behavior: 'inclusive',
        unit_amount: '1000',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'metered',
        recurring_aggregate_usage: 'sum',
        productid: administrator.product.productid
      }
      const price = await req.post()
      assert.strictEqual(price.stripeObject.currency, 'usd')
    })

    it('optionally-required posted unit_amount', async () => {
      const administrator = await TestHelper.createOwner()
      await TestHelper.createProduct(administrator, {
        active: 'true'
      })
      const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
      req.account = administrator.account
      req.session = administrator.session
      req.body = {
        currency: 'usd',
        tax_behavior: 'inclusive',
        unit_amount: '1000',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'metered',
        recurring_aggregate_usage: 'sum',
        productid: administrator.product.productid
      }
      const price = await req.post()
      assert.strictEqual(price.stripeObject.unit_amount, 1000)
    })

    it('optional posted active (boolean)', async () => {
      const administrator = await TestHelper.createOwner()
      await TestHelper.createProduct(administrator)
      const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
      req.account = administrator.account
      req.session = administrator.session
      req.body = {
        currency: 'usd',
        tax_behavior: 'inclusive',
        unit_amount: '1000',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        productid: administrator.product.productid,
        active: 'true'
      }
      const price = await req.post()
      assert.strictEqual(price.stripeObject.active, true)
    })

    it('optional posted billing_scheme (per_unit|tiered)', async () => {
      const administrator = await TestHelper.createOwner()
      await TestHelper.createProduct(administrator, {
        active: 'true'
      })
      const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
      req.account = administrator.account
      req.session = administrator.session
      req.body = {
        currency: 'usd',
        tax_behavior: 'inclusive',
        unit_amount: '1000',
        billing_scheme: 'per_unit',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'metered',
        recurring_aggregate_usage: 'sum',
        productid: administrator.product.productid
      }
      const price = await req.post()
      assert.strictEqual(price.stripeObject.billing_scheme, 'per_unit')
    })

    it('optional posted recurring_usage_type (licensed|metered)', async () => {
      const administrator = await TestHelper.createOwner()
      await TestHelper.createProduct(administrator, {
        active: 'true'
      })
      const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
      req.account = administrator.account
      req.session = administrator.session
      req.body = {
        currency: 'usd',
        tax_behavior: 'inclusive',
        unit_amount: '1000',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'metered',
        recurring_aggregate_usage: 'sum',
        productid: administrator.product.productid
      }
      const price = await req.post()
      assert.strictEqual(price.stripeObject.recurring.usage_type, 'metered')
    })

    it('optional posted recurring_interval (day|week|month|year)', async () => {
      const administrator = await TestHelper.createOwner()
      await TestHelper.createProduct(administrator, {
        active: 'true'
      })
      const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
      req.account = administrator.account
      req.session = administrator.session
      req.body = {
        currency: 'usd',
        tax_behavior: 'inclusive',
        unit_amount: '1000',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'metered',
        recurring_aggregate_usage: 'sum',
        productid: administrator.product.productid
      }
      const price = await req.post()
      assert.strictEqual(price.stripeObject.recurring.interval, 'month')
    })

    it('optionally-required posted recurring_interval_count', async () => {
      const administrator = await TestHelper.createOwner()
      await TestHelper.createProduct(administrator, {
        active: 'true'
      })
      const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
      req.account = administrator.account
      req.session = administrator.session
      req.body = {
        currency: 'usd',
        tax_behavior: 'inclusive',
        unit_amount: '1000',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'metered',
        recurring_aggregate_usage: 'sum',
        productid: administrator.product.productid
      }
      const price = await req.post()
      assert.strictEqual(price.stripeObject.recurring.interval_count, 1)
    })

    it('optionally-required posted recurring_aggregate_usage (sum|max|last_ever|last_during_period)', async () => {
      const administrator = await TestHelper.createOwner()
      await TestHelper.createProduct(administrator, {
        active: 'true'
      })
      const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
      req.account = administrator.account
      req.session = administrator.session
      req.body = {
        currency: 'usd',
        tax_behavior: 'inclusive',
        unit_amount: '1000',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'metered',
        recurring_aggregate_usage: 'sum',
        productid: administrator.product.productid
      }
      const price = await req.post()
      assert.strictEqual(price.stripeObject.recurring.aggregate_usage, 'sum')
    })

    it('optional posted transform_quantity_divide_by', async () => {
      const administrator = await TestHelper.createOwner()
      await TestHelper.createProduct(administrator, {
        active: 'true'
      })
      const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
      req.account = administrator.account
      req.session = administrator.session
      req.body = {
        currency: 'usd',
        tax_behavior: 'inclusive',
        unit_amount: '1000',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'metered',
        recurring_aggregate_usage: 'sum',
        transform_quantity_divide_by: '7',
        transform_quantity_round: 'down',
        productid: administrator.product.productid
      }
      const price = await req.post()
      assert.strictEqual(price.stripeObject.transform_quantity.divide_by, 7)
    })

    it('optionally-required posted transform_quantity_round (up|down)', async () => {
      const administrator = await TestHelper.createOwner()
      await TestHelper.createProduct(administrator, {
        active: 'true'
      })
      const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
      req.account = administrator.account
      req.session = administrator.session
      req.body = {
        currency: 'usd',
        tax_behavior: 'inclusive',
        unit_amount: '1000',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'metered',
        recurring_aggregate_usage: 'sum',
        transform_quantity_divide_by: '7',
        transform_quantity_round: 'down',
        productid: administrator.product.productid
      }
      const price = await req.post()
      assert.strictEqual(price.stripeObject.transform_quantity.round, 'down')
    })

    it('optionally-required posted tiers_mode (graduated|volume)', async () => {
      const administrator = await TestHelper.createOwner()
      await TestHelper.createProduct(administrator, {
        active: 'true'
      })
      const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
      req.account = administrator.account
      req.session = administrator.session
      req.body = {
        currency: 'usd',
        tax_behavior: 'inclusive',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'metered',
        recurring_aggregate_usage: 'sum',
        billing_scheme: 'tiered',
        tiers_mode: 'volume',
        tier1_up_to: '1000',
        tier1_unit_amount: '9999',
        tier2_up_to: 'inf',
        tier2_unit_amount: '8999',
        productid: administrator.product.productid
      }
      const price = await req.post()
      assert.strictEqual(price.stripeObject.tiers_mode, 'volume')
    })

    it('optional posted tier(1...)_up_to', async () => {
      const administrator = await TestHelper.createOwner()
      await TestHelper.createProduct(administrator, {
        active: 'true'
      })
      const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
      req.account = administrator.account
      req.session = administrator.session
      req.body = {
        currency: 'usd',
        tax_behavior: 'inclusive',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'metered',
        recurring_aggregate_usage: 'sum',
        billing_scheme: 'tiered',
        tiers_mode: 'volume',
        tier1_up_to: '1000',
        tier1_unit_amount: '9999',
        tier2_up_to: 'inf',
        tier2_unit_amount: '8999',
        productid: administrator.product.productid
      }
      const price = await req.post()
      assert.strictEqual(price.stripeObject.tiers[0].up_to, 1000)
    })

    it('optional posted tier(1...)_unit_amount', async () => {
      const administrator = await TestHelper.createOwner()
      await TestHelper.createProduct(administrator, {
        active: 'true'
      })
      const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
      req.account = administrator.account
      req.session = administrator.session
      req.body = {
        currency: 'usd',
        tax_behavior: 'inclusive',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'metered',
        recurring_aggregate_usage: 'sum',
        billing_scheme: 'tiered',
        tiers_mode: 'volume',
        tier1_up_to: '1000',
        tier1_unit_amount: '9999',
        tier2_up_to: 'inf',
        tier2_unit_amount: '8999',
        productid: administrator.product.productid
      }
      const price = await req.post()
      assert.strictEqual(price.stripeObject.tiers[1].unit_amount, 8999)
    })

    it('optional posted tier(1...)_flat_amount', async () => {
      const administrator = await TestHelper.createOwner()
      await TestHelper.createProduct(administrator, {
        active: 'true'
      })
      const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
      req.account = administrator.account
      req.session = administrator.session
      req.body = {
        currency: 'usd',
        tax_behavior: 'inclusive',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'metered',
        recurring_aggregate_usage: 'sum',
        billing_scheme: 'tiered',
        tiers_mode: 'volume',
        tier1_up_to: '1000',
        tier1_flat_amount: '9999',
        tier2_up_to: 'inf',
        tier2_flat_amount: '8999',
        productid: administrator.product.productid
      }
      const price = await req.post()
      assert.strictEqual(price.stripeObject.tiers[1].flat_amount, 8999)
    })
  })

  describe('returns', () => {
    it('object', async () => {
      const administrator = await TestHelper.createOwner()
      await TestHelper.createProduct(administrator, {
        active: 'true'
      })
      const req = TestHelper.createRequest('/api/administrator/subscriptions/create-price')
      req.account = administrator.account
      req.session = administrator.session
      req.body = {
        currency: 'usd',
        tax_behavior: 'inclusive',
        unit_amount: '1000',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'metered',
        recurring_aggregate_usage: 'sum',
        productid: administrator.product.productid
      }
      req.filename = __filename
      req.saveResponse = true
      const price = await req.post()
      assert.strictEqual(price.object, 'price')
    })
  })
})