/api/user/connect/delete-stripe-account (DELETE)
await global.api.user.connect.DeleteStripeAccount.delete(req) Located in Stripe Connect module API
Returns boolean
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 |
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 = {
delete: 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.accountid !== req.account.accountid) {
throw new Error('invalid-stripe-account')
}
await stripeCache.execute('accounts', 'del', req.query.stripeid, req.stripeKey)
await stripeCache.delete(req.query.stripeid)
return true
}
}
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/delete-stripe-account', () => {
describe('exceptions', () => {
describe('invalid-stripeid', () => {
it('missing querystring stripeid', async () => {
const user = await TestHelper.createUser()
const req = TestHelper.createRequest('/api/user/connect/delete-stripe-account')
req.account = user.account
req.session = user.session
let errorMessage
try {
await req.delete()
} 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/delete-stripe-account?stripeid=invalid')
req.account = user.account
req.session = user.session
let errorMessage
try {
await req.delete()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-stripeid')
})
})
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/delete-stripe-account?stripeid=${user.stripeAccount.id}`)
req.account = user2.account
req.session = user2.session
let errorMessage
try {
await req.delete()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-account')
})
})
})
describe('returns', () => {
it('boolean', async () => {
const user = await TestHelper.createUser()
await TestHelper.createStripeAccount(user, {
country: 'DE',
type: 'company'
})
const req = TestHelper.createRequest(`/api/user/connect/delete-stripe-account?stripeid=${user.stripeAccount.id}`)
req.account = user.account
req.session = user.session
req.filename = __filename
req.saveResponse = true
const deleted = await req.delete()
assert.strictEqual(deleted, true)
})
})
})