/api/user/connect/set-company-directors-submitted (PATCH)
await global.api.user.connect.SetCompanyDirectorsSubmitted.patch(req) Located in Stripe Connect module API
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 company directors are submitted | |
invalid-stripe-account | ineligible stripe account for individual |
invalid-account | ineligible accessing account |
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')
module.exports = {
patch: 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.metadata.submitted ||
stripeAccount.business_type !== 'company' ||
stripeAccount.metadata.accountid !== req.account.accountid ||
(stripeAccount.company && stripeAccount.company.directors_provided)) {
throw new Error('invalid-stripe-account')
}
if (!stripeAccount.metadata.requiresDirectors) {
throw new Error('invalid-stripe-account')
}
const accountInfo = {
company: {
directors_provided: true
}
}
const stripeAccountNow = await stripeCache.execute('accounts', 'update', req.query.stripeid, accountInfo, req.stripeKey)
await stripeCache.delete(req.query.stripeid)
return stripeAccountNow
}
}
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')
const TestStripeAccounts = require('../../../../../test-stripe-accounts.js')
describe('/api/user/connect/set-company-directors-submitted', function () {
after(TestHelper.deleteOldWebhooks)
before(TestHelper.setupWebhook)
describe('exceptions', () => {
describe('invalid-stripeid', () => {
it('missing querystring stripeid', async () => {
const user = await TestHelper.createUser()
const req = TestHelper.createRequest('/api/user/connect/set-company-directors-submitted')
req.account = user.account
req.session = user.session
let errorMessage
try {
await req.patch(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/set-company-directors-submitted?stripeid=invalid')
req.account = user.account
req.session = user.session
let errorMessage
try {
await req.patch(req)
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-stripeid')
})
})
describe('invalid-stripe-account', () => {
it('ineligible stripe account for individual', async () => {
const user = await TestHelper.createUser()
await TestHelper.createStripeAccount(user, {
country: 'US',
type: 'individual'
})
const req = TestHelper.createRequest(`/api/user/connect/set-company-directors-submitted?stripeid=${user.stripeAccount.id}`)
req.account = user.account
req.session = user.session
let errorMessage
try {
await req.patch(req)
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-stripe-account')
})
it('ineligible company directors are submitted', async () => {
const user = await TestHelper.createUser()
await TestHelper.createStripeAccount(user, {
country: 'AT',
type: 'company'
})
await TestHelper.submitCompanyDirectors(user)
const req = TestHelper.createRequest(`/api/user/connect/set-company-directors-submitted?stripeid=${user.stripeAccount.id}`)
req.account = user.account
req.session = user.session
let errorMessage
try {
await req.patch(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: 'DE',
type: 'company'
})
const user2 = await TestHelper.createUser()
const req = TestHelper.createRequest(`/api/user/connect/set-company-directors-submitted?stripeid=${user.stripeAccount.id}`)
req.account = user2.account
req.session = user2.session
let errorMessage
try {
await req.patch(req)
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-account')
})
})
})
describe('returns', () => {
it('object', async () => {
const user = await TestStripeAccounts.createCompanyWithDirectors('US', 1)
const req = TestHelper.createRequest(`/api/user/connect/set-company-directors-submitted?stripeid=${user.stripeAccount.id}`)
req.account = user.account
req.session = user.session
req.filename = __filename
req.saveResponse = true
const accountNow = await req.patch()
assert.strictEqual(accountNow.company.directors_provided, true)
})
})
})