Stripe Connect module API explorer

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

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

Returns object

Exceptions

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

Exception Circumstances

NodeJS source (edit on github)

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


const connect = require('../../../../../index.js')
const stripeCache = require('../../../../stripe-cache.js')
const cache = {}

module.exports = {
  get: async (req) => {
    if (!req.query || !req.query.country) {
      throw new Error('invalid-country')
    }
    if (!connect.countrySpecIndex[req.query.country]) {
      throw new Error('invalid-country')
    }
    if (cache[req.query.country]) {
      return cache[req.query.country]
    }
    const countrySpec = cache[req.query.country] = await stripeCache.execute('countrySpecs', 'retrieve', req.query.country, req.stripeKey)
    if (!countrySpec) {
      throw new Error('invalid-country')
    }
    return countrySpec
  }
}

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-spec', () => {
  describe('exceptions', () => {
    it('missing querystring country', async () => {
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest('/api/user/connect/country-spec')
      req.account = user.account
      req.session = user.session
      let errorMessage
      try {
        await req.get()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-country')
    })

    it('invalid querystring country', async () => {
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest('/api/user/connect/country-spec?country=invalid')
      req.account = user.account
      req.session = user.session
      let errorMessage
      try {
        await req.get()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-country')
    })
  })

  describe('returns', () => {
    it('object', async () => {
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest('/api/user/connect/country-spec?country=US')
      req.account = user.account
      req.session = user.session
      req.filename = __filename
      req.saveResponse = true
      const countrySpec = await req.get()
      assert.strictEqual(countrySpec.id, 'US')
    })
  })
})