Stripe Connect module API explorer

/api/administrator/connect/payout (GET)

Account information like email addresses is generated with faker-js it is not real user information.

await global.api.administrator.connect.Payout.get(req)

Returns object

{
  "payoutid": "po_1LEBlERWgGgeiPyf6dwm7R2p",
  "object": "payout",
  "stripeObject": {
    "id": "po_1LEBlERWgGgeiPyf6dwm7R2p",
    "object": "payout",
    "amount": 2000,
    "arrival_date": 1656288000,
    "automatic": false,
    "balance_transaction": "txn_1LEBlERWgGgeiPyfYIOBlWRK",
    "created": 1656074240,
    "currency": "nzd",
    "description": null,
    "destination": "ba_1LEBkpRWgGgeiPyf7hgcbdnP",
    "failure_balance_transaction": null,
    "failure_code": null,
    "failure_message": null,
    "livemode": false,
    "metadata": {},
    "method": "standard",
    "original_payout": null,
    "reversed_by": null,
    "source_type": "card",
    "statement_descriptor": null,
    "status": "pending",
    "type": "bank_account"
  },
  "accountid": "acct_d6e1d2c842e5a248",
  "stripeid": "acct_1LEBkiRWgGgeiPyf",
  "appid": "tests_1656074207",
  "createdAt": "2022-06-24T12:37:21.823Z",
  "updatedAt": "2022-06-24T12:37:21.823Z"
}

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-payoutid missing querystring payoutid
invalid querystring payoutid

NodeJS source (view on github)

const connect = require('../../../../../index.js')
const dashboard = require('@layeredapps/dashboard')

module.exports = {
  get: async (req) => {
    if (!req.query || !req.query.payoutid) {
      throw new Error('invalid-payoutid')
    }
    let payout = await dashboard.StorageCache.get(req.query.payoutid)
    if (!payout) {
      const payoutInfo = await connect.Storage.Payout.findOne({
        where: {
          payoutid: req.query.payoutid,
          appid: req.appid || global.appid
        }
      })
      if (!payoutInfo) {
        throw new Error('invalid-payoutid')
      }
      payout = {}
      for (const field of payoutInfo._options.attributes) {
        payout[field] = payoutInfo.get(field)
      }
      await dashboard.StorageCache.set(req.query.payoutid, payout)
    }
    return payout
  }
}

Test source (view on github)

/* 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 () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  describe('exceptions', () => {
    describe('invalid-payoutid', () => {
      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')
      await TestHelper.createPayout(user)
      const req = TestHelper.createRequest(`/api/administrator/connect/payout?payoutid=${user.payout.payoutid}`)
      req.account = administrator.account
      req.session = administrator.session
      req.filename = __filename
      req.saveResponse = true
      const payout = await req.get()
      assert.strictEqual(payout.payoutid, user.payout.payoutid)
    })
  })
})