Stripe Connect module API explorer

/api/administrator/connect/persons-count (GET)

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

await global.api.administrator.connect.PersonsCount.get(req)

Receives

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

Field Value Required Type
stripeid string optional URL

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-stripe-account invalid Stripe account is individual

NodeJS source (view on github)

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

module.exports = {
  get: async (req) => {
    const where = {
      appid: req.appid || global.appid
    }
    if (req.query && req.query.stripeid) {
      const stripeAccount = await global.api.administrator.connect.StripeAccount.get(req)
      if (!stripeAccount) {
        throw new Error('invalid-stripeid')
      }
      if (stripeAccount.stripeObject.business_type !== 'company') {
        throw new Error('invalid-stripe-account')
      }
      where.stripeid = req.query.stripeid
    }
    return connect.Storage.Person.count({
      where
    })
  }
}

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/connect/persons-count', () => {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  describe('exceptions', function () {
    describe('invalid-stripe-account', () => {
      it('invalid Stripe account is individual', async () => {
        const administrator = await TestHelper.createOwner()
        const user = await TestStripeAccounts.createIndividualMissingIndividualDetails()
        const req = TestHelper.createRequest(`/api/administrator/connect/persons-count?stripeid=${user.stripeAccount.stripeid}`)
        req.account = administrator.account
        req.session = administrator.session
        let errorMessage
        try {
          await req.get()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-stripe-account')
      })
    })
  })

  describe('receives', function () {
    it('optional querystring stripeid', async function () {
      const administrator = await TestHelper.createOwner()
      const user1 = await TestStripeAccounts.createCompanyWithDirectors('DE', 2)
      await TestStripeAccounts.createCompanyWithDirectors('DE', 1)
      const req = TestHelper.createRequest(`/api/administrator/connect/persons-count?stripeid=${user1.stripeAccount.stripeid}`)
      req.account = administrator.account
      req.session = administrator.session
      const result = await req.get()
      assert.strictEqual(result, 2)
    })
  })

  describe('returns', () => {
    it('integer', async () => {
      const administrator = await TestHelper.createOwner()
      for (let i = 0, len = global.pageSize + 1; i < len; i++) {
        await TestStripeAccounts.createCompanyWithDirectors('DE', 1)
      }
      const req = TestHelper.createRequest('/api/administrator/connect/persons-count')
      req.account = administrator.account
      req.session = administrator.session
      req.filename = __filename
      req.saveResponse = true
      const result = await req.get()
      assert.strictEqual(result, global.pageSize + 1)
    })
  })
})