Stripe Connect module API explorer

/api/user/connect/create-stripe-account (POST)

await global.api.user.connect.CreateStripeAccount.post(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
invalid querystring accountid
invalid-accountid missing querystring accountid
invalid-account ineligible accessing account
invalid posted type
invalid-type missing posted type
invalid-country invalid posted country
invalid posted country

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

module.exports = {
  post: 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')
    }
    if (!req.body || (req.body.type !== 'individual' && req.body.type !== 'company')) {
      throw new Error('invalid-type')
    }
    if (!req.body.country || !connect.countrySpecIndex[req.body.country]) {
      throw new Error('invalid-country')
    }
    // TODO: this should be determined through the stripe requirements
    // however the country specs have out-of-date requirement and the
    // account requirements don't exist before creating the account
    const requiresOwners = req.body.country !== 'CA' && req.body.country !== 'HK' && req.body.country !== 'JP'
    const requiresDirectors = req.body.country !== 'CA' && req.body.country !== 'HK' && req.body.country !== 'JP' &&
                              req.body.country !== 'MY' && req.body.country !== 'SG' && req.body.country !== 'US'
    const accountInfo = {
      type: 'custom',
      business_type: req.body.type,
      country: req.body.country,
      requested_capabilities: ['card_payments', 'transfers'],
      metadata: {
        appid: req.appid,
        accountid: req.query.accountid,
        ip: req.ip,
        requiresOwners,
        requiresDirectors
      }
    }
    const stripeAccount = await stripeCache.execute('accounts', 'create', accountInfo, req.stripeKey)
    await connect.StorageList.addMany({
      [`${req.appid}/stripeAccounts`]: stripeAccount.id,
      [`${req.appid}/account/stripeAccounts/${req.query.accountid}`]: stripeAccount.id
    })
    await connect.Storage.write(`${req.appid}/map/stripeid/accountid/${stripeAccount.id}`, req.query.accountid)
    return stripeAccount
  }
}

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

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

    describe('invalid-account', () => {
      it('ineligible accessing account', async () => {
        const user = await TestHelper.createUser()
        const user2 = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/connect/create-stripe-account?accountid=${user.account.accountid}`)
        req.account = user2.account
        req.session = user2.session
        req.body = {
          type: '',
          country: 'US'
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-account')
      })
    })

    describe('invalid-type', () => {
      it('missing posted type', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/connect/create-stripe-account?accountid=${user.account.accountid}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          type: '',
          country: 'US'
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-type')
      })

      it('invalid posted type', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/connect/create-stripe-account?accountid=${user.account.accountid}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          type: 'invalid',
          country: 'US'
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-type')
      })
    })

    describe('invalid-country', () => {
      it('invalid posted country', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/connect/create-stripe-account?accountid=${user.account.accountid}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          type: 'individual',
          country: ''
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-country')
      })

      it('invalid posted country', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/connect/create-stripe-account?accountid=${user.account.accountid}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          type: 'individual',
          country: 'invalid'
        }
        let errorMessage
        try {
          await req.post()
        } 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/create-stripe-account?accountid=${user.account.accountid}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        type: 'individual',
        country: 'US'
      }
      req.filename = __filename
      req.saveResponse = true
      const stripeAccount = await req.post()
      assert.strictEqual(stripeAccount.business_type, 'individual')
    })
  })
})