Stripe Connect module API explorer

/api/user/connect/country-specs (GET)

await global.api.user.connect.CountrySpecs.get(req)

Returns array

Exceptions

These exceptions are thrown (NodeJS) or returned as JSON (HTTP) if you provide incorrect data or do not meet the requirements:

Exception Circumstances

Receives

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

Field Value Required Type
all boolean optional URL
limit integer optional URL
offset integer optional URL

NodeJS source (edit on github)

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

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

module.exports = {
  auth: false,
  get: async (req) => {
    if (!cache) {
      cache = await stripeCache.execute('countrySpecs', 'list', { limit: 100 }, req.stripeKey)
    }
    req.query = req.query || {}
    if (req.query.all) {
      return cache.data
    }
    const offset = req.query.offset ? parseInt(req.query.offset, 10) : 0
    const limit = req.query.limit ? parseInt(req.query.limit, 10) : global.pageSize
    const result = []
    let skipped = 0
    for (const countrySpec of cache.data) {
      if (skipped < offset) {
        skipped++
        continue
      }
      result.push(countrySpec)
      if (result.length === limit) {
        return result
      }
    }
    return result
  }
}

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')

describe('/api/user/connect/country-specs', () => {
  describe('receives', () => {
    it('optional querystring offset (integer)', async () => {
      const offset = 1
      global.delayDiskWrites = true
      const req = TestHelper.createRequest('/api/user/connect/country-specs?all=true')
      const countries = await req.get()
      const req2 = TestHelper.createRequest(`/api/user/connect/country-specs?offset=${offset}`)
      const countriesNow = await req2.get()
      for (let i = 0, len = global.pageSize; i < len; i++) {
        assert.strictEqual(countriesNow[i].id, countries[offset + i].id)
      }
    })

    it('optional querystring limit (integer)', async () => {
      const limit = 1
      const req = TestHelper.createRequest(`/api/user/connect/country-specs?limit=${limit}`)
      const countriesNow = await req.get()
      assert.strictEqual(countriesNow.length, limit)
    })

    it('optional querystring all (boolean)', async () => {
      global.pageSize = 1
      const req = TestHelper.createRequest('/api/user/connect/country-specs?all=true')
      const countriesNow = await req.get()
      assert.notStrictEqual(countriesNow.length, 0)
      assert.notStrictEqual(countriesNow.length, global.pageSize)
    })
  })

  describe('returns', () => {
    it('array', async () => {
      const req = TestHelper.createRequest('/api/user/connect/country-specs')
      req.filename = __filename
      req.saveResponse = true
      const countrySpecs = await req.get()
      assert.strictEqual(countrySpecs.length, global.pageSize)
    })
  })

  describe('configuration', () => {
    it('environment PAGE_SIZE', async () => {
      global.pageSize = 3
      const req = TestHelper.createRequest('/api/user/connect/country-specs')
      const countrySpecs = await req.get()
      assert.strictEqual(countrySpecs.length, global.pageSize)
    })
  })
})