Stripe Connect module API explorer

/api/user/connect/payout (GET)

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

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

Returns object

{
  "payoutid": "po_1LEBuARd1XimRqWc0yfo8TnS",
  "object": "payout",
  "stripeObject": {
    "id": "po_1LEBuARd1XimRqWc0yfo8TnS",
    "object": "payout",
    "amount": 2000,
    "arrival_date": 1656288000,
    "automatic": false,
    "balance_transaction": "txn_1LEBuBRd1XimRqWcQOKGPFoK",
    "created": 1656074794,
    "currency": "nzd",
    "description": null,
    "destination": "ba_1LEBthRd1XimRqWcs3YzJlYD",
    "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_b1abff77ed45f9c3",
  "stripeid": "acct_1LEBtaRd1XimRqWc",
  "appid": "tests_1656074758",
  "createdAt": "2022-06-24T12:46:36.004Z",
  "updatedAt": "2022-06-24T12:46:36.004Z"
}

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-account ineligible accessing account
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')
      }
      if (payoutInfo.dataValues.accountid !== req.account.accountid) {
        throw new Error('invalid-account')
      }
      payout = {}
      for (const field of payoutInfo._options.attributes) {
        payout[field] = payoutInfo.get(field)
      }
      await dashboard.StorageCache.set(req.query.payoutid, payout)
    }
    if (payout.accountid !== req.account.accountid) {
      throw new Error('invalid-account')
    }
    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/user/connect/payout', function () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  describe('exceptions', () => {
    describe('invalid-payoutid', () => {
      it('missing querystring payoutid', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest('/api/user/connect/payout')
        req.account = user.account
        req.session = user.session
        let errorMessage
        try {
          await req.get()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-payoutid')
      })

      it('invalid querystring payoutid', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest('/api/user/connect/payout?payoutid=invalid')
        req.account = user.account
        req.session = user.session
        let errorMessage
        try {
          await req.get()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-payoutid')
      })
    })

    describe('invalid-account', function () {
      it('ineligible accessing account', async () => {
        const user = await TestStripeAccounts.createSubmittedIndividual('NZ')
        await TestHelper.createPayout(user)
        const user2 = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/connect/payout?payoutid=${user.payout.payoutid}`)
        req.account = user2.account
        req.session = user2.session
        let errorMessage
        try {
          await req.get()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-account')
      })
    })
  })

  describe('returns', function () {
    it('object', async () => {
      const user = await TestStripeAccounts.createSubmittedIndividual('NZ')
      await TestHelper.createPayout(user)
      const req = TestHelper.createRequest(`/api/user/connect/payout?payoutid=${user.payout.payoutid}`)
      req.account = user.account
      req.session = user.session
      req.filename = __filename
      req.saveResponse = true
      const payout = await req.get()
      assert.strictEqual(payout.payoutid, user.payout.payoutid)
    })
  })
})