Stripe Subscriptions module API explorer

/api/user/subscriptions/charges-count (GET)

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

await global.api.user.subscriptions.ChargesCount.get(req)

NodeJS source (view on github)

const subscriptions = require('../../../../../index.js')

module.exports = {
  get: async (req) => {
    if (!req.query || !req.query.accountid) {
      throw new Error('invalid-accountid')
    }
    const account = await global.api.user.Account.get(req)
    if (!account) {
      throw new Error('invalid-account')
    }
    return subscriptions.Storage.Charge.count({
      where: {
        accountid: req.query.accountid,
        appid: req.appid || global.appid
      }
    })
  }
}

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/user/subscriptions/charges-count', function () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  describe('returns', () => {
    it('integer', async () => {
      const administrator = await TestHelper.createOwner()
      await TestHelper.createProduct(administrator, {
        active: 'true'
      })
      const user = await TestStripeAccounts.createUserWithPaymentMethod()
      for (let i = 0, len = global.pageSize + 1; i < len; i++) {
        await TestHelper.createPrice(administrator, {
          productid: administrator.product.productid,
          active: 'true',
          unit_amount: 3000,
          currency: 'usd',
          tax_behavior: 'inclusive',
          recurring_interval: 'month',
          recurring_usage_type: 'licensed',
          recurring_interval_count: '1'
        })
        await TestStripeAccounts.createUserWithPaidSubscription(administrator.price, user)
      }
      const req = TestHelper.createRequest(`/api/user/subscriptions/charges-count?accountid=${user.account.accountid}`)
      req.account = user.account
      req.session = user.session
      req.filename = __filename
      req.saveResponse = true
      const result = await req.get()
      assert.strictEqual(result, global.pageSize + 1)
    })
  })
})