/api/administrator/connect/set-stripe-account-rejected (PATCH)
await global.api.administrator.connect.SetStripeAccountRejected.patch(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 posted reason | |
invalid-reason | missing posted reason |
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')
}
if (!req.body || !req.body.reason) {
throw new Error('invalid-reason')
}
if (req.body.reason !== 'fraud' && req.body.reason !== 'other' && req.body.reason !== 'terms_of_service') {
throw new Error('invalid-reason')
}
const stripeAccount = await global.api.administrator.connect.StripeAccount.get(req)
if (!stripeAccount) {
throw new Error('invalid-stripeid')
}
const updateInfo = {
reason: req.body.reason
}
const accountNow = await stripeCache.execute('accounts', 'reject', req.query.stripeid, updateInfo, req.stripeKey)
await stripeCache.delete(req.query.stripeid)
return accountNow
}
}
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/administrator/connect/set-stripe-account-rejected', () => {
describe('exceptions', () => {
describe('invalid-stripeid', () => {
it('missing querystring stripeid', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/connect/set-stripe-account-rejected')
req.account = administrator.account
req.session = administrator.session
req.body = {
reason: 'fraud'
}
let errorMessage
try {
await req.patch(req)
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-stripeid')
})
it('invalid querystring stripeid', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/connect/set-stripe-account-rejected?stripeid=invalid')
req.account = administrator.account
req.session = administrator.session
req.body = {
reason: 'fraud'
}
let errorMessage
try {
await req.patch(req)
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-stripeid')
})
})
describe('invalid-reason', () => {
it('missing posted reason', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/connect/set-stripe-account-rejected?stripeid=invalid')
req.account = administrator.account
req.session = administrator.session
req.body = {
reason: ''
}
let errorMessage
try {
await req.patch(req)
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-reason')
})
it('invalid posted reason', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/connect/set-stripe-account-rejected?stripeid=invalid')
req.account = administrator.account
req.session = administrator.session
req.body = {
reason: 'invalid'
}
let errorMessage
try {
await req.patch(req)
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-reason')
})
})
})
describe('returns', () => {
it('boolean', async () => {
const administrator = await TestHelper.createOwner()
const user = await TestHelper.createUser()
await TestHelper.createStripeAccount(user, {
country: 'DE',
type: 'company'
})
const req = TestHelper.createRequest(`/api/administrator/connect/set-stripe-account-rejected?stripeid=${user.stripeAccount.id}`)
req.account = administrator.account
req.session = administrator.session
req.filename = __filename
req.saveResponse = true
req.body = {
reason: 'fraud'
}
const accountNow = await req.patch()
assert.strictEqual(accountNow.requirements.disabled_reason, 'rejected.fraud')
})
})
})