Stripe Connect module API explorer

/api/user/connect/create-stripe-account (POST)

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

await global.api.user.connect.CreateStripeAccount.post(req)

Returns object

{
  "stripeid": "acct_1LEBsNRajHsy1MwE",
  "object": "stripeAccount",
  "accountid": "acct_fe2f4dd3431a5d6c",
  "tokenUpdate": null,
  "stripeObject": {
    "id": "acct_1LEBsNRajHsy1MwE",
    "object": "account",
    "business_profile": {
      "mcc": null,
      "name": null,
      "product_description": null,
      "support_address": null,
      "support_email": null,
      "support_phone": null,
      "support_url": null,
      "url": null
    },
    "business_type": "individual",
    "capabilities": {
      "card_payments": "inactive",
      "transfers": "inactive"
    },
    "charges_enabled": false,
    "company": {
      "address": {
        "city": null,
        "country": "US",
        "line1": null,
        "line2": null,
        "postal_code": null,
        "state": null
      },
      "directors_provided": true,
      "executives_provided": true,
      "name": null,
      "owners_provided": true,
      "tax_id_provided": false,
      "verification": {
        "document": {
          "back": null,
          "details": null,
          "details_code": null,
          "front": null
        }
      }
    },
    "country": "US",
    "created": 1656074684,
    "default_currency": "usd",
    "details_submitted": false,
    "email": null,
    "external_accounts": {
      "object": "list",
      "data": [],
      "has_more": false,
      "total_count": 0,
      "url": "/v1/accounts/acct_1LEBsNRajHsy1MwE/external_accounts"
    },
    "future_requirements": {
      "alternatives": [],
      "current_deadline": null,
      "currently_due": [],
      "disabled_reason": null,
      "errors": [],
      "eventually_due": [],
      "past_due": [],
      "pending_verification": []
    },
    "metadata": {},
    "payouts_enabled": false,
    "requirements": {
      "alternatives": [],
      "current_deadline": null,
      "currently_due": [
        "business_profile.mcc",
        "business_profile.url",
        "external_account",
        "individual.address.city",
        "individual.address.line1",
        "individual.address.postal_code",
        "individual.address.state",
        "individual.dob.day",
        "individual.dob.month",
        "individual.dob.year",
        "individual.email",
        "individual.first_name",
        "individual.last_name",
        "individual.phone",
        "individual.ssn_last_4",
        "tos_acceptance.date",
        "tos_acceptance.ip"
      ],
      "disabled_reason": "requirements.past_due",
      "errors": [],
      "eventually_due": [
        "business_profile.mcc",
        "business_profile.url",
        "external_account",
        "individual.address.city",
        "individual.address.line1",
        "individual.address.postal_code",
        "individual.address.state",
        "individual.dob.day",
        "individual.dob.month",
        "individual.dob.year",
        "individual.email",
        "individual.first_name",
        "individual.last_name",
        "individual.phone",
        "individual.ssn_last_4",
        "tos_acceptance.date",
        "tos_acceptance.ip"
      ],
      "past_due": [
        "business_profile.mcc",
        "business_profile.url",
        "external_account",
        "individual.address.city",
        "individual.address.line1",
        "individual.address.postal_code",
        "individual.address.state",
        "individual.dob.day",
        "individual.dob.month",
        "individual.dob.year",
        "individual.email",
        "individual.first_name",
        "individual.last_name",
        "individual.phone",
        "individual.ssn_last_4",
        "tos_acceptance.date",
        "tos_acceptance.ip"
      ],
      "pending_verification": []
    },
    "settings": {
      "bacs_debit_payments": {},
      "branding": {
        "icon": null,
        "logo": null,
        "primary_color": null,
        "secondary_color": null
      },
      "card_issuing": {
        "tos_acceptance": {
          "date": null,
          "ip": null
        }
      },
      "card_payments": {
        "decline_on": {
          "avs_failure": false,
          "cvc_failure": false
        },
        "statement_descriptor_prefix": null,
        "statement_descriptor_prefix_kana": null,
        "statement_descriptor_prefix_kanji": null
      },
      "dashboard": {
        "display_name": null,
        "timezone": "Etc/UTC"
      },
      "payments": {
        "statement_descriptor": null,
        "statement_descriptor_kana": null,
        "statement_descriptor_kanji": null
      },
      "payouts": {
        "debit_negative_balances": false,
        "schedule": {
          "delay_days": 2,
          "interval": "daily"
        },
        "statement_descriptor": null
      },
      "sepa_debit_payments": {}
    },
    "tos_acceptance": {
      "date": null,
      "ip": null,
      "user_agent": null
    },
    "type": "custom"
  },
  "requiresOwners": false,
  "requiresDirectors": false,
  "requiresExecutives": false,
  "appid": "tests_1656074683",
  "createdAt": "2022-06-24T12:44:46.182Z",
  "updatedAt": "2022-06-24T12:44:46.182Z"
}

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-accountid missing querystring accountid
invalid querystring accountid
invalid-business_type missing posted business_type
invalid posted business_type
invalid-country invalid posted country
invalid posted country

NodeJS source (view on github)

const connect = require('../../../../../index.js')
const stripeCache = require('../../../../stripe-cache.js')

module.exports = {
  post: async (req) => {
    if (!req.query || !req.query.accountid) {
      throw new Error('invalid-accountid')
    }
    const account = await global.api.user.Account.get(req)
    if (!account) {
      throw new Error('invalid-account')
    }
    if (!req.body || (req.body.business_type !== 'individual' && req.body.business_type !== 'company')) {
      throw new Error('invalid-business_type')
    }
    if (!req.body.country || !connect.countrySpecIndex[req.body.country]) {
      throw new Error('invalid-country')
    }
    const accountInfo = {
      type: 'custom',
      business_type: req.body.business_type,
      country: req.body.country,
      requested_capabilities: ['card_payments', 'transfers']
    }
    try {
      const stripeAccount = await stripeCache.execute('accounts', 'create', accountInfo, req.stripeKey)
      const allRequirements = stripeAccount.requirements.currently_due.concat(stripeAccount.requirements.eventually_due)
      const requiresOwners = allRequirements.indexOf('owners.last_name') > -1
      const requiresDirectors = allRequirements.indexOf('directors.last_name') > -1
      const requiresExecutives = allRequirements.indexOf('executives.last_name') > -1
      await connect.Storage.StripeAccount.create({
        appid: req.appid || global.appid,
        stripeid: stripeAccount.id,
        accountid: req.query.accountid,
        stripeObject: stripeAccount,
        requiresOwners,
        requiresDirectors,
        requiresExecutives
      })
      req.query.stripeid = stripeAccount.id
      return global.api.user.connect.StripeAccount.get(req)
    } catch (error) {
      if (error.message.startsWith('invalid-')) {
        throw new Error(error.message.split('.').join('_'))
      }
      throw error
    }
  }
}

Test source (view on github)

/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../../test-helper.js')

describe('/api/user/connect/create-stripe-account', function () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  describe('exceptions', () => {
    describe('invalid-accountid', () => {
      it('missing querystring accountid', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest('/api/user/connect/create-stripe-account')
        req.account = user.account
        req.session = user.session
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-accountid')
      })

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

    describe('invalid-account', () => {
      it('ineligible accessing account', async () => {
        const user = await TestHelper.createUser()
        const user2 = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/connect/create-stripe-account?accountid=${user.account.accountid}`)
        req.account = user2.account
        req.session = user2.session
        req.body = {
          business_type: '',
          country: 'US'
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-account')
      })
    })

    describe('invalid-business_type', () => {
      it('missing posted business_type', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/connect/create-stripe-account?accountid=${user.account.accountid}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          business_type: '',
          country: 'US'
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-business_type')
      })

      it('invalid posted business_type', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/connect/create-stripe-account?accountid=${user.account.accountid}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          business_type: 'invalid',
          country: 'US'
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-business_type')
      })
    })

    describe('invalid-country', () => {
      it('invalid posted country', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/connect/create-stripe-account?accountid=${user.account.accountid}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          business_type: 'individual',
          country: ''
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-country')
      })

      it('invalid posted country', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/connect/create-stripe-account?accountid=${user.account.accountid}`)
        req.account = user.account
        req.session = user.session
        req.body = {
          business_type: 'individual',
          country: 'invalid'
        }
        let errorMessage
        try {
          await req.post()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-country')
      })
    })
  })

  describe('returns', () => {
    it('object', async () => {
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/user/connect/create-stripe-account?accountid=${user.account.accountid}`)
      req.account = user.account
      req.session = user.session
      req.body = {
        business_type: 'individual',
        country: 'US'
      }
      req.filename = __filename
      req.saveResponse = true
      const stripeAccount = await req.post()
      assert.strictEqual(stripeAccount.stripeObject.business_type, 'individual')
    })
  })
})