Stripe Connect module API explorer

/api/administrator/connect/payouts (GET)

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

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

Returns array

[
  {
    "payoutid": "po_1LEBohRZ0kEyRwr1WSI3LS0z",
    "object": "payout",
    "stripeObject": {
      "id": "po_1LEBohRZ0kEyRwr1WSI3LS0z",
      "object": "payout",
      "amount": 2000,
      "arrival_date": 1656288000,
      "automatic": false,
      "balance_transaction": "txn_1LEBoiRZ0kEyRwr1Os3QwGQ6",
      "created": 1656074455,
      "currency": "nzd",
      "description": null,
      "destination": "ba_1LEBoKRZ0kEyRwr1nyqMuFU5",
      "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_8bef10c3c46c04ea",
    "stripeid": "acct_1LEBoDRZ0kEyRwr1",
    "appid": "tests_1656074355",
    "createdAt": "2022-06-24T12:40:56.921Z",
    "updatedAt": "2022-06-24T12:40:56.922Z"
  },
  {
    "payoutid": "po_1LEBoCDEbuv1y1WOR7VPmxJK",
    "object": "payout",
    "stripeObject": {
      "id": "po_1LEBoCDEbuv1y1WOR7VPmxJK",
      "object": "payout",
      "amount": 2000,
      "arrival_date": 1656288000,
      "automatic": false,
      "balance_transaction": "txn_1LEBoCDEbuv1y1WOxZTbfAsr",
      "created": 1656074424,
      "currency": "nzd",
      "description": null,
      "destination": "ba_1LEBnoDEbuv1y1WO7faiMowO",
      "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": "paid",
      "type": "bank_account"
    },
    "accountid": "acct_8bef10c3c46c04ea",
    "stripeid": "acct_1LEBnhDEbuv1y1WO",
    "appid": "tests_1656074355",
    "createdAt": "2022-06-24T12:40:25.476Z",
    "updatedAt": "2022-06-24T12:40:25.828Z"
  },
  {
    "payoutid": "po_1LEBnfDGG7NHC4RlqB1u8hsB",
    "object": "payout",
    "stripeObject": {
      "id": "po_1LEBnfDGG7NHC4RlqB1u8hsB",
      "object": "payout",
      "amount": 2000,
      "arrival_date": 1656288000,
      "automatic": false,
      "balance_transaction": "txn_1LEBnfDGG7NHC4RlPHqrVdaf",
      "created": 1656074391,
      "currency": "nzd",
      "description": null,
      "destination": "ba_1LEBnBDGG7NHC4RldWq02SJ1",
      "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": "paid",
      "type": "bank_account"
    },
    "accountid": "acct_84c0bbf386c8d891",
    "stripeid": "acct_1LEBn5DGG7NHC4Rl",
    "appid": "tests_1656074355",
    "createdAt": "2022-06-24T12:39:52.677Z",
    "updatedAt": "2022-06-24T12:39:52.985Z"
  }
]

Receives

API routes may receive parameters from the URL and POST supporting simple and multipart:

Field Value Required Type
accountid string optional URL
all boolean optional URL
limit integer optional URL
offset integer optional URL
stripeid string optional URL

NodeJS source (view on github)

const connect = require('../../../../../index.js')

module.exports = {
  get: async (req) => {
    req.query = req.query || {}
    const where = {
      appid: req.appid || global.appid
    }
    if (req.query.stripeid) {
      const StripeAccount = await global.api.administrator.connect.StripeAccount.get(req)
      if (!StripeAccount) {
        throw new Error('invalid-stripeid')
      }
      where.stripeid = req.query.stripeid
    } else if (req.query.accountid) {
      const account = await global.api.administrator.Account.get(req)
      if (!account) {
        throw new Error('invalid-account')
      }
      where.accountid = req.query.accountid
    }
    let payoutids
    if (req.query.all) {
      payoutids = await connect.Storage.Payout.findAll({
        where,
        attributes: ['payoutid'],
        order: [
          ['createdAt', 'DESC']
        ]
      })
    } else {
      const offset = req.query.offset ? parseInt(req.query.offset, 10) : 0
      const limit = req.query.limit ? parseInt(req.query.limit, 10) : global.pageSize
      payoutids = await connect.Storage.Payout.findAll({
        where,
        attributes: ['payoutid'],
        offset,
        limit,
        order: [
          ['createdAt', 'DESC']
        ]
      })
    }
    if (!payoutids || !payoutids.length) {
      return null
    }
    const items = []
    for (const payoutInfo of payoutids) {
      req.query.payoutid = payoutInfo.dataValues.payoutid
      const payout = await global.api.administrator.connect.Payout.get(req)
      items.push(payout)
    }
    return items
  }
}

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')
const DashboardTestHelper = require('@layeredapps/dashboard/test-helper.js')

describe('/api/administrator/connect/payouts', function () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  let cachedResponses, cachedPayouts, accountPayouts, stripeAccountPayouts
  async function bundledData (retryNumber) {
    if (retryNumber > 0) {
      cachedResponses = {}
    }
    if (cachedResponses && cachedResponses.finished) {
      return
    }
    cachedResponses = {}
    cachedPayouts = []
    accountPayouts = []
    stripeAccountPayouts = []
    await DashboardTestHelper.setupBeforeEach()
    await TestHelper.setupBeforeEach()
    const administrator = await TestHelper.createOwner()
    let user = await TestStripeAccounts.createSubmittedIndividual('NZ')
    for (let i = 0, len = global.pageSize; i < len; i++) {
      await TestHelper.createPayout(user)
      cachedPayouts.unshift(user.payout.payoutid)
    }
    user = await TestStripeAccounts.createSubmittedIndividual('NZ')
    const stripeid = user.stripeAccount.stripeid
    await TestHelper.createPayout(user)
    cachedPayouts.unshift(user.payout.payoutid)
    accountPayouts.unshift(user.payout.payoutid)
    stripeAccountPayouts.unshift(user.payout.payoutid)
    user = await TestStripeAccounts.createSubmittedIndividual('NZ', user)
    await TestHelper.createPayout(user)
    cachedPayouts.unshift(user.payout.payoutid)
    accountPayouts.unshift(user.payout.payoutid)
    const req1 = TestHelper.createRequest('/api/administrator/connect/payouts')
    req1.account = administrator.account
    req1.session = administrator.session
    req1.filename = __filename
    req1.saveResponse = true
    cachedResponses.returns = await req1.get()
    global.pageSize = 3
    cachedResponses.pageSize = await req1.get()
    global.pageSize = 2
    const req2 = TestHelper.createRequest('/api/administrator/connect/payouts?offset=1')
    req2.account = administrator.account
    req2.session = administrator.session
    cachedResponses.offset = await req2.get()
    const req3 = TestHelper.createRequest('/api/administrator/connect/payouts?limit=1')
    req3.account = administrator.account
    req3.session = administrator.session
    cachedResponses.limit = await req3.get()
    const req4 = TestHelper.createRequest('/api/administrator/connect/payouts?all=true')
    req4.account = administrator.account
    req4.session = administrator.session
    cachedResponses.all = await req4.get()
    const req5 = TestHelper.createRequest(`/api/administrator/connect/payouts?accountid=${user.account.accountid}&all=true`)
    req5.account = administrator.account
    req5.session = administrator.session
    cachedResponses.accountid = await req5.get()
    const req6 = TestHelper.createRequest(`/api/administrator/connect/payouts?stripeid=${stripeid}&all=true`)
    req6.account = administrator.account
    req6.session = administrator.session
    cachedResponses.stripeid = await req6.get()
    cachedResponses.finished = true
  }
  describe('receives', function () {
    it('optional querystring offset (integer)', async function () {
      await bundledData(this.test.currentRetry())
      const offset = 1
      const payoutsNow = cachedResponses.offset
      for (let i = 0, len = global.pageSize; i < len; i++) {
        assert.strictEqual(payoutsNow[i].payoutid, cachedPayouts[offset + i])
      }
    })

    it('optional querystring limit (integer)', async function () {
      await bundledData(this.test.currentRetry())
      const limit = 1
      const payoutsNow = cachedResponses.limit
      assert.strictEqual(payoutsNow.length, limit)
    })

    it('optional querystring all (boolean)', async function () {
      await bundledData(this.test.currentRetry())
      const payoutsNow = cachedResponses.all
      assert.strictEqual(payoutsNow.length, cachedPayouts.length)
    })

    it('optional querystring accountid (string)', async function () {
      await bundledData(this.test.currentRetry())
      const payoutsNow = cachedResponses.accountid
      assert.strictEqual(payoutsNow.length, accountPayouts.length)
    })

    it('optional querystring stripeid (string)', async function () {
      await bundledData(this.test.currentRetry())
      const payoutsNow = cachedResponses.stripeid
      assert.strictEqual(payoutsNow.length, stripeAccountPayouts.length)
    })
  })

  describe('returns', function () {
    it('array', async function () {
      await bundledData(this.test.currentRetry())
      const payouts = cachedResponses.returns
      assert.strictEqual(payouts.length, global.pageSize)
    })
  })

  describe('configuration', function () {
    it('environment PAGE_SIZE', async function () {
      await bundledData(this.test.currentRetry())
      const payouts = cachedResponses.pageSize
      assert.strictEqual(payouts.length, global.pageSize + 1)
    })
  })
})