Stripe Connect module API explorer

/api/user/connect/create-person (POST)

await global.api.user.connect.CreatePerson.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 stripeid
invalid-stripeid missing querystring stripeid
ineligible stripe account does not require directors
ineligible stripe account does not require owners
invalid-stripe-account ineligible stripe account for individuals
invalid-account ineligible accessing account
invalid posted relationship_percent_ownership
invalid-relationship_percent_ownership missing posted relationship_percent_ownership
invalid posted relationship_title
invalid-relationship_title missing posted relationship_title
invalid-relationship_executive invalid representative must be an executive

Receives

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

Field Value Required Type
relationship_director string optional POST
relationship_executive string configurable as required POST
relationship_owner string optional POST
relationship_percent_ownership string required POST
relationship_representative string optional POST
relationship_title string required POST

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.stripeid) {
      throw new Error('invalid-stripeid')
    }
    const stripeAccount = await global.api.user.connect.StripeAccount.get(req)
    if (!stripeAccount) {
      throw new Error('invalid-stripeid')
    }
    if (stripeAccount.business_type !== 'company') {
      throw new Error('invalid-stripe-account')
    }
    if (!req.body.relationship_representative && !req.body.relationship_director && !req.body.relationship_owner) {
      throw new Error('invalid-selection')
    }
    if (req.body.relationship_representative && !req.body.relationship_executive) {
      throw new Error('invalid-relationship_executive')
    }
    // TODO: the 5000 character limit is from Stripe
    // they'll probably change it so monitor this
    if (!req.body.relationship_title ||
        !req.body.relationship_title.length ||
        req.body.relationship_title.length > 5000) {
      throw new Error('invalid-relationship_title')
    }
    if (!req.body.relationship_percent_ownership) {
      throw new Error('invalid-relationship_percent_ownership')
    }
    let percent
    try {
      percent = parseFloat(req.body.relationship_percent_ownership, 10)
    } catch (s) {
      throw new Error('invalid-relationship_percent_ownership')
    }
    // TODO: 0% ownership throws an error on Stripe if the person is not 'owner=true'
    if ((!percent && percent !== 0) || percent > 100 || percent < 0) {
      throw new Error('invalid-relationship_percent_ownership')
    }
    if (percent === 0) {
      if (req.body.relationship_owner) {
        throw new Error('invalid-relationship_percent_ownership')
      }
      delete (req.body.relationship_percent_ownership)
    }
    const personInfo = {
      relationship: {
        title: req.body.relationship_title
      }
    }
    if (req.body.relationship_percent_ownership) {
      personInfo.relationship.percent_ownership = req.body.relationship_percent_ownership
    }
    if (req.body.relationship_representative) {
      personInfo.relationship.representative = true
    }
    if (req.body.relationship_executive) {
      personInfo.relationship.executive = true
    }
    if (req.body.relationship_director) {
      if (stripeAccount.metadata.requiresDirectors === 'false') {
        throw new Error('invalid-stripe-account')
      }
      personInfo.relationship.director = true
    }
    if (req.body.relationship_owner) {
      if (stripeAccount.metadata.requiresOwners === 'false') {
        throw new Error('invalid-stripe-account')
      }
      personInfo.relationship.owner = true
    }
    const person = await stripeCache.execute('accounts', 'createPerson', req.query.stripeid, personInfo, req.stripeKey)
    await connect.Storage.write(`${req.appid}/map/personid/stripeid/${person.id}`, req.query.stripeid)
    await connect.StorageList.addMany({
      [`${req.appid}/persons`]: person.id,
      [`${req.appid}/stripeAccount/persons/${req.query.stripeid}`]: person.id
    })
    return person
  }
}

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

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

    describe('invalid-stripe-account', () => {
      it('ineligible stripe account for individuals', async () => {
        const user = await TestHelper.createUser()
        await TestHelper.createStripeAccount(user, {
          country: 'US',
          type: 'individual'
        })
        const req = TestHelper.createRequest(`/api/user/connect/create-person?stripeid=${user.stripeAccount.id}`)
        req.account = user.account
        req.session = user.session
        let errorMessage
        try {
          await req.post(req)
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-stripe-account')
      })

      it('ineligible stripe account does not require directors', async () => {
        const user = await TestHelper.createUser()
        await TestHelper.createStripeAccount(user, {
          country: 'US',
          type: 'company'
        })
        const req = TestHelper.createRequest(`/api/user/connect/create-person?stripeid=${user.stripeAccount.id}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          relationship_director: 'true',
          relationship_title: 'Chairperson',
          relationship_percent_ownership: '0.1'
        }
        let errorMessage
        try {
          await req.post(req)
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-stripe-account')
      })

      it('ineligible stripe account does not require owners', async () => {
        const user = await TestHelper.createUser()
        await TestHelper.createStripeAccount(user, {
          country: 'HK',
          type: 'company'
        })
        const req = TestHelper.createRequest(`/api/user/connect/create-person?stripeid=${user.stripeAccount.id}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          relationship_owner: 'true',
          relationship_title: 'Chairperson',
          relationship_percent_ownership: '0.1'
        }
        let errorMessage
        try {
          await req.post(req)
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-stripe-account')
      })
    })

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

    describe('invalid-relationship_percent_ownership', () => {
      it('missing posted relationship_percent_ownership', async () => {
        const user = await TestHelper.createUser()
        await TestHelper.createStripeAccount(user, {
          country: 'US',
          type: 'company'
        })
        const req = TestHelper.createRequest(`/api/user/connect/create-person?stripeid=${user.stripeAccount.id}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          relationship_representative: 'true',
          relationship_executive: 'true',
          relationship_title: 'Chairperson',
          relationship_percent_ownership: ''
        }
        let errorMessage
        try {
          await req.post(req)
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-relationship_percent_ownership')
      })

      it('invalid posted relationship_percent_ownership', async () => {
        const user = await TestHelper.createUser()
        await TestHelper.createStripeAccount(user, {
          country: 'US',
          type: 'company'
        })
        const req = TestHelper.createRequest(`/api/user/connect/create-person?stripeid=${user.stripeAccount.id}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          relationship_representative: 'true',
          relationship_executive: 'true',
          relationship_title: 'Chairperson',
          relationship_percent_ownership: 'invalid'
        }
        let errorMessage
        try {
          await req.post(req)
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-relationship_percent_ownership')
      })
    })

    describe('invalid-relationship_title', () => {
      it('missing posted relationship_title', async () => {
        const user = await TestHelper.createUser()
        await TestHelper.createStripeAccount(user, {
          country: 'US',
          type: 'company'
        })
        const req = TestHelper.createRequest(`/api/user/connect/create-person?stripeid=${user.stripeAccount.id}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          relationship_representative: 'true',
          relationship_executive: 'true',
          relationship_title: '',
          relationship_percent_ownership: '0.1'
        }
        let errorMessage
        try {
          await req.post(req)
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-relationship_title')
      })

      it('invalid posted relationship_title', async () => {
        const user = await TestHelper.createUser()
        await TestHelper.createStripeAccount(user, {
          country: 'US',
          type: 'company'
        })
        const req = TestHelper.createRequest(`/api/user/connect/create-person?stripeid=${user.stripeAccount.id}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          relationship_representative: 'true',
          relationship_executive: 'true',
          relationship_title: '',
          relationship_percent_ownership: '0.1'
        }
        // TODO: the 5000 character limit is from Stripe
        // they'll probably change it so monitor this
        while (req.body.relationship_title.length < 5001) {
          req.body.relationship_title += '-'
        }
        let errorMessage
        try {
          await req.post(req)
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-relationship_title')
      })
    })

    describe('invalid-relationship_executive', async () => {
      it('invalid representative must be an executive', async () => {
        const user = await TestHelper.createUser()
        await TestHelper.createStripeAccount(user, {
          country: 'US',
          type: 'company'
        })
        const req = TestHelper.createRequest(`/api/user/connect/create-person?stripeid=${user.stripeAccount.id}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          relationship_representative: 'true',
          relationship_title: 'Chairperson',
          relationship_percent_ownership: '0.1'
        }
        let errorMessage
        try {
          await req.post(req)
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-relationship_executive')
      })
    })
  })

  describe('receives', () => {
    it('optional posted relationship_representative', async () => {
      const user = await TestHelper.createUser()
      await TestHelper.createStripeAccount(user, {
        country: 'US',
        type: 'company'
      })
      const req = TestHelper.createRequest(`/api/user/connect/create-person?stripeid=${user.stripeAccount.id}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        relationship_representative: 'true',
        relationship_executive: 'true',
        relationship_title: 'Chairperson',
        relationship_percent_ownership: '0.1'
      }
      const person = await req.post()
      assert.strictEqual(person.relationship.representative, true)
    })

    it('optionally-required posted relationship_executive', async () => {
      const user = await TestHelper.createUser()
      await TestHelper.createStripeAccount(user, {
        country: 'US',
        type: 'company'
      })
      const req = TestHelper.createRequest(`/api/user/connect/create-person?stripeid=${user.stripeAccount.id}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        relationship_representative: 'true',
        relationship_executive: 'true',
        relationship_title: 'Chairperson',
        relationship_percent_ownership: '0.1'
      }
      const person = await req.post()
      assert.strictEqual(person.relationship.executive, true)
    })

    it('optional posted relationship_director', async () => {
      const user = await TestHelper.createUser()
      await TestHelper.createStripeAccount(user, {
        country: 'GB',
        type: 'company'
      })
      const req = TestHelper.createRequest(`/api/user/connect/create-person?stripeid=${user.stripeAccount.id}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        relationship_director: 'true',
        relationship_title: 'Chairperson',
        relationship_percent_ownership: '0.1'
      }
      const person = await req.post()
      assert.strictEqual(person.relationship.director, true)
    })

    it('optional posted relationship_owner', async () => {
      const user = await TestHelper.createUser()
      await TestHelper.createStripeAccount(user, {
        country: 'GB',
        type: 'company'
      })
      const req = TestHelper.createRequest(`/api/user/connect/create-person?stripeid=${user.stripeAccount.id}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        relationship_owner: 'true',
        relationship_title: 'Chairperson',
        relationship_percent_ownership: '0.1'
      }
      const person = await req.post()
      assert.strictEqual(person.relationship.owner, true)
    })

    it('required posted relationship_percent_ownership', async () => {
      const user = await TestHelper.createUser()
      await TestHelper.createStripeAccount(user, {
        country: 'GB',
        type: 'company'
      })
      const req = TestHelper.createRequest(`/api/user/connect/create-person?stripeid=${user.stripeAccount.id}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        relationship_director: 'true',
        relationship_title: 'Chairperson',
        relationship_percent_ownership: '0.1'
      }
      const person = await req.post()
      assert.strictEqual(person.relationship.percent_ownership, 0.1)
    })

    it('required posted relationship_title', async () => {
      const user = await TestHelper.createUser()
      await TestHelper.createStripeAccount(user, {
        country: 'GB',
        type: 'company'
      })
      const req = TestHelper.createRequest(`/api/user/connect/create-person?stripeid=${user.stripeAccount.id}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        relationship_director: 'true',
        relationship_title: 'Chairperson',
        relationship_percent_ownership: '0.1'
      }
      const person = await req.post()
      assert.strictEqual(person.relationship.title, 'Chairperson')
    })
  })

  describe('returns', () => {
    it('object', async () => {
      const user = await TestHelper.createUser()
      await TestHelper.createStripeAccount(user, {
        country: 'US',
        type: 'company'
      })
      const req = TestHelper.createRequest(`/api/user/connect/create-person?stripeid=${user.stripeAccount.id}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        relationship_representative: 'true',
        relationship_executive: 'true',
        relationship_title: 'Chairperson',
        relationship_percent_ownership: '0.1'
      }
      req.filename = __filename
      req.saveResponse = true
      const person = await req.post()
      assert.strictEqual(person.object, 'person')
    })
  })
})