Stripe Subscriptions module API explorer

/api/administrator/subscriptions/setup-intents (GET)

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

await global.api.administrator.subscriptions.SetupIntents.get(req)

Returns array

[
  {
    "setupintentid": "seti_1LEOUtHHqepMFuCXZ6UNk5zN",
    "accountid": "acct_964bf35e76d90b39",
    "customerid": "cus_LwH2j6sQ9guEO8",
    "paymentmethodid": null,
    "object": "setupintent",
    "stripeObject": {
      "id": "seti_1LEOUtHHqepMFuCXZ6UNk5zN",
      "object": "setup_intent",
      "application": null,
      "cancellation_reason": null,
      "client_secret": "seti_1LEOUtHHqepMFuCXZ6UNk5zN_secret_LwH2eOhGsTDwVjv0gE6rwOtfDRFBEWJ",
      "created": 1656123199,
      "customer": "cus_LwH2j6sQ9guEO8",
      "description": null,
      "flow_directions": null,
      "last_setup_error": null,
      "latest_attempt": null,
      "livemode": false,
      "mandate": null,
      "metadata": {},
      "next_action": null,
      "on_behalf_of": null,
      "payment_method": "pm_1LEOUsHHqepMFuCX61tLCKuK",
      "payment_method_options": {
        "card": {
          "mandate_options": null,
          "network": null,
          "request_three_d_secure": "automatic"
        }
      },
      "payment_method_types": [
        "card"
      ],
      "single_use_mandate": null,
      "status": "requires_confirmation",
      "usage": "off_session"
    },
    "appid": "tests_1656123186",
    "createdAt": "2022-06-25T02:13:20.338Z",
    "updatedAt": "2022-06-25T02:13:20.474Z"
  },
  {
    "setupintentid": "seti_1LEOUqHHqepMFuCXqKxspIgL",
    "accountid": "acct_104617f499f6e905",
    "customerid": "cus_LwH2D7OJTz25Kb",
    "paymentmethodid": null,
    "object": "setupintent",
    "stripeObject": {
      "id": "seti_1LEOUqHHqepMFuCXqKxspIgL",
      "object": "setup_intent",
      "application": null,
      "cancellation_reason": null,
      "client_secret": "seti_1LEOUqHHqepMFuCXqKxspIgL_secret_LwH2XO0Yje8xR9EaUSi51a4gg4KGJjY",
      "created": 1656123196,
      "customer": "cus_LwH2D7OJTz25Kb",
      "description": null,
      "flow_directions": null,
      "last_setup_error": null,
      "latest_attempt": null,
      "livemode": false,
      "mandate": null,
      "metadata": {},
      "next_action": null,
      "on_behalf_of": null,
      "payment_method": "pm_1LEOUpHHqepMFuCXO4YNHyD4",
      "payment_method_options": {
        "card": {
          "mandate_options": null,
          "network": null,
          "request_three_d_secure": "automatic"
        }
      },
      "payment_method_types": [
        "card"
      ],
      "single_use_mandate": null,
      "status": "requires_confirmation",
      "usage": "off_session"
    },
    "appid": "tests_1656123186",
    "createdAt": "2022-06-25T02:13:17.195Z",
    "updatedAt": "2022-06-25T02:13:18.670Z"
  },
  {
    "setupintentid": "seti_1LEOUmHHqepMFuCXDPURW9bA",
    "accountid": "acct_ecfa243ed188e330",
    "customerid": "cus_LwH2B5PfKIT15v",
    "paymentmethodid": null,
    "object": "setupintent",
    "stripeObject": {
      "id": "seti_1LEOUmHHqepMFuCXDPURW9bA",
      "object": "setup_intent",
      "application": null,
      "cancellation_reason": null,
      "client_secret": "seti_1LEOUmHHqepMFuCXDPURW9bA_secret_LwH2vsusMY9MlOVp16n2eW6CFdSJRkQ",
      "created": 1656123192,
      "customer": "cus_LwH2B5PfKIT15v",
      "description": null,
      "flow_directions": null,
      "last_setup_error": null,
      "latest_attempt": null,
      "livemode": false,
      "mandate": null,
      "metadata": {},
      "next_action": null,
      "on_behalf_of": null,
      "payment_method": "pm_1LEOUlHHqepMFuCXluX0OmjB",
      "payment_method_options": {
        "card": {
          "mandate_options": null,
          "network": null,
          "request_three_d_secure": "automatic"
        }
      },
      "payment_method_types": [
        "card"
      ],
      "single_use_mandate": null,
      "status": "requires_confirmation",
      "usage": "off_session"
    },
    "appid": "tests_1656123186",
    "createdAt": "2022-06-25T02:13:13.558Z",
    "updatedAt": "2022-06-25T02:13:13.809Z"
  }
]

Receives

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

Field Value Required Type
all boolean optional URL
limit integer optional URL
offset integer optional URL

NodeJS source (view on github)

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

module.exports = {
  get: async (req) => {
    req.query = req.query || {}
    const where = {
      appid: req.appid || global.appid
    }
    let setupintentids
    if (req.query.all) {
      setupintentids = await subscriptions.Storage.SetupIntent.findAll({
        where,
        attributes: ['setupintentid'],
        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
      setupintentids = await subscriptions.Storage.SetupIntent.findAll({
        where,
        attributes: ['setupintentid'],
        offset,
        limit,
        order: [
          ['createdAt', 'DESC']
        ]
      })
    }
    if (!setupintentids || !setupintentids.length) {
      return null
    }
    const items = []
    for (const setupintentInfo of setupintentids) {
      req.query.setupintentid = setupintentInfo.dataValues.setupintentid
      const setupIntent = await global.api.administrator.subscriptions.SetupIntent.get(req)
      items.push(setupIntent)
    }
    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/subscriptions/setup-intents', function () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  let cachedResponses, cachedSetupIntents
  async function bundledData (retryNumber) {
    if (retryNumber > 0) {
      cachedResponses = {}
    }
    if (cachedResponses && cachedResponses.finished) {
      return
    }
    cachedResponses = {}
    cachedSetupIntents = []
    await TestHelper.setupBefore()
    await DashboardTestHelper.setupBeforeEach()
    await TestHelper.setupBeforeEach()
    const administrator = await TestStripeAccounts.createOwnerWithPrice()
    for (let i = 0, len = global.pageSize + 2; i < len; i++) {
      const user = await TestStripeAccounts.createUserWithPaymentMethod()
      cachedSetupIntents.unshift(user.setupIntent.setupintentid)
    }
    const req1 = TestHelper.createRequest('/api/administrator/subscriptions/setup-intents?offset=1')
    req1.account = administrator.account
    req1.session = administrator.session
    cachedResponses.offset = await req1.get()
    const req2 = TestHelper.createRequest('/api/administrator/subscriptions/setup-intents?limit=1')
    req2.account = administrator.account
    req2.session = administrator.session
    cachedResponses.limit = await req2.get()
    const req3 = TestHelper.createRequest('/api/administrator/subscriptions/setup-intents?all=true')
    req3.account = administrator.account
    req3.session = administrator.session
    cachedResponses.all = await req3.get()
    const req4 = TestHelper.createRequest('/api/administrator/subscriptions/setup-intents')
    req4.account = administrator.account
    req4.session = administrator.session
    req4.filename = __filename
    req4.saveResponse = true
    cachedResponses.returns = await req4.get()
    global.pageSize = 3
    cachedResponses.pageSize = await req4.get()
    global.pageSize = 2
    cachedResponses.finished = true
  }
  describe('receives', () => {
    it('optional querystring offset (integer)', async function () {
      await bundledData(this.test.currentRetry())
      const offset = 1
      const setupIntentsNow = cachedResponses.offset
      for (let i = 0, len = global.pageSize; i < len; i++) {
        assert.strictEqual(setupIntentsNow[i].setupintentid, cachedSetupIntents[offset + i])
      }
    })

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

    it('optional querystring all (boolean)', async () => {
      const setupIntentsNow = cachedResponses.all
      assert.strictEqual(setupIntentsNow.length, cachedSetupIntents.length)
    })
  })

  describe('returns', () => {
    it('array', async () => {
      const setupIntentsNow = cachedResponses.returns
      assert.strictEqual(setupIntentsNow.length, global.pageSize)
    })
  })

  describe('configuration', () => {
    it('environment PAGE_SIZE', async () => {
      const setupIntentsNow = cachedResponses.pageSize
      assert.strictEqual(setupIntentsNow.length, global.pageSize + 1)
    })
  })
})