/api/administrator/subscriptions/payout (GET)
await global.api.administrator.subscriptions.Payout.get(req) Located in Stripe Subscriptions 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 payoutid | |
invalid-payoutid | missing querystring payoutid |
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 = {
get: async (req) => {
if (!req.query || !req.query.payoutid) {
throw new Error('invalid-payoutid')
}
let payout
try {
payout = await stripeCache.retrieve(req.query.payoutid, 'payouts', req.stripeKey)
} catch (error) {
}
if (!payout) {
throw new Error('invalid-payoutid')
}
return payout
}
}
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/subscriptions/payout', function () {
if (!process.env.DISABLE_PAYOUT_TESTS) {
this.timeout(60 * 60 * 1000)
after(TestHelper.deleteOldWebhooks)
before(TestHelper.setupWebhook)
describe('exceptions', () => {
describe('invalid-payoutid', () => {
it('missing querystring payoutid', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/subscriptions/payout')
req.account = administrator.account
req.session = administrator.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-payoutid')
})
it('invalid querystring payoutid', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/subscriptions/payout?payoutid=invalid')
req.account = administrator.account
req.session = administrator.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-payoutid')
})
})
})
if (!process.env.DISABLE_PAYOUT_TESTS) {
describe('returns', () => {
it('object', async () => {
const administrator = await TestHelper.createOwner()
const payout = await TestHelper.createPayout(administrator)
const req = TestHelper.createRequest(`/api/administrator/subscriptions/payout?payoutid=${payout.id}`)
req.account = administrator.account
req.session = administrator.session
req.filename = __filename
req.saveResponse = true
const payoutNow = await req.get()
assert.strictEqual(payoutNow.id, payout.id)
})
})
}
}
})