/api/administrator/connect/payout (GET)
await global.api.administrator.connect.Payout.get(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 payoutid | |
invalid-payoputid | missing querystring payoutid |
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 = {
get: async (req) => {
if (!req.query || !req.query.payoutid) {
throw new Error('invalid-payoutid')
}
const stripeid = await connect.Storage.read(`${req.appid}/map/payoutid/stripeid/${req.query.payoutid}`)
if (!stripeid) {
throw new Error('invalid-payoutid')
}
const accountKey = {
api_key: req.stripeKey.api_key,
stripe_account: stripeid
}
const payout = await stripeCache.retrieve(req.query.payoutid, 'payouts', accountKey)
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')
const TestStripeAccounts = require('../../../../../test-stripe-accounts.js')
describe('/api/administrator/connect/payout', function () {
this.timeout(30 * 60 * 1000)
after(TestHelper.deleteOldWebhooks)
before(TestHelper.setupWebhook)
describe('exceptions', () => {
describe('invalid-payoputid', () => {
it('missing querystring payoutid', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/connect/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/connect/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')
})
})
})
describe('returns', () => {
it('object', async () => {
const administrator = await TestHelper.createOwner()
// const user = await TestStripeAccounts.createSubmittedIndividual('NZ')
// TODO: swap with individual account
// the Stripe test api has an error creating fully-activated accounts
// so when that gets fixed this code can be changed to speed it up
const user = await TestStripeAccounts.createSubmittedCompany('NZ')
await TestHelper.createPayout(user)
await TestHelper.waitForPayout(administrator, user.stripeAccount.id, null)
const req = TestHelper.createRequest(`/api/administrator/connect/payout?payoutid=${user.payout.id}`)
req.account = administrator.account
req.session = administrator.session
req.filename = __filename
req.saveResponse = true
const payout = await req.get()
assert.strictEqual(payout.id, user.payout.id)
})
})
})