Stripe Connect module API explorer

/api/user/connect/person (GET)

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

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

Returns object

{
  "personid": "person_1LEBwgRmMLYvfXYXTYFFxOU6",
  "object": "person",
  "accountid": "acct_7e206dfda36bbed6",
  "stripeid": "acct_1LEBwdRmMLYvfXYX",
  "tokenUpdate": null,
  "stripeObject": {
    "id": "person_1LEBwgRmMLYvfXYXTYFFxOU6",
    "object": "person",
    "account": "acct_1LEBwdRmMLYvfXYX",
    "address": {
      "city": "Berlin",
      "country": "DE",
      "line1": "123 Park Lane",
      "line2": null,
      "postal_code": "01067",
      "state": null
    },
    "created": 1656074951,
    "dob": {
      "day": 1,
      "month": 1,
      "year": 1970
    },
    "email": "Harold49@yahoo.com",
    "first_name": "Harold",
    "future_requirements": {
      "alternatives": [],
      "currently_due": [],
      "errors": [],
      "eventually_due": [],
      "past_due": [],
      "pending_verification": []
    },
    "last_name": "Gaylord",
    "metadata": {},
    "phone": "+14567890123",
    "relationship": {
      "director": false,
      "executive": true,
      "owner": false,
      "percent_ownership": null,
      "representative": true,
      "title": "SVP Testing"
    },
    "requirements": {
      "alternatives": [],
      "currently_due": [],
      "errors": [],
      "eventually_due": [],
      "past_due": [],
      "pending_verification": [
        "verification.additional_document",
        "verification.document"
      ]
    },
    "verification": {
      "additional_document": {
        "back": "file_1LEBwwDsofxDmDiW9kHVYgUv",
        "details": null,
        "details_code": null,
        "front": "file_1LEBwvDsofxDmDiWGV789G50"
      },
      "details": null,
      "details_code": null,
      "document": {
        "back": "file_1LEBwzDsofxDmDiW9MvEtF3d",
        "details": null,
        "details_code": null,
        "front": "file_1LEBwxDsofxDmDiWWcA5vmR0"
      },
      "status": "pending"
    }
  },
  "appid": "tests_1656074947",
  "createdAt": "2022-06-24T12:49:12.745Z",
  "updatedAt": "2022-06-24T12:49:39.777Z"
}

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

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.personid) {
      throw new Error('invalid-personid')
    }
    let person = await dashboard.StorageCache.get(req.query.personid)
    if (!person) {
      const personInfo = await connect.Storage.Person.findOne({
        where: {
          personid: req.query.personid,
          appid: req.appid || global.appid
        }
      })
      if (!personInfo) {
        throw new Error('invalid-personid')
      }
      if (personInfo.dataValues.accountid !== req.account.accountid) {
        throw new Error('invalid-account')
      }
      person = {}
      for (const field of personInfo._options.attributes) {
        person[field] = personInfo.get(field)
      }
      await dashboard.StorageCache.set(req.query.personid, person)
    }
    if (person.accountid !== req.account.accountid) {
      throw new Error('invalid-account')
    }
    return person
  }
}

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/person', () => {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  describe('exceptions', () => {
    describe('invalid-personid', () => {
      it('missing querystring personid', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest('/api/user/connect/person')
        req.account = user.account
        req.session = user.session
        let errorMessage
        try {
          await req.get()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-personid')
      })

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

    describe('invalid-account', () => {
      it('ineligible accessing account', async () => {
        const user = await TestStripeAccounts.createCompanyWithRepresentative('DE')
        const user2 = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/connect/person?personid=${user.representative.personid}`)
        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', () => {
    it('object', async () => {
      const user = await TestStripeAccounts.createCompanyWithRepresentative('DE')
      const req = TestHelper.createRequest(`/api/user/connect/person?personid=${user.representative.personid}`)
      req.account = user.account
      req.session = user.session
      req.filename = __filename
      req.saveResponse = true
      const representative = await req.get()
      assert.strictEqual(representative.personid, user.representative.personid)
    })
  })
})