Stripe Subscriptions module API explorer

/api/user/subscriptions/payment-intents (GET)

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

await global.api.user.subscriptions.PaymentIntents.get(req)

Returns array

[
  {
    "paymentintentid": "pi_3LEOhDHHqepMFuCX12PM6DEk",
    "object": "paymentintent",
    "stripeObject": {
      "id": "pi_3LEOhDHHqepMFuCX12PM6DEk",
      "object": "payment_intent",
      "amount": 10000,
      "amount_capturable": 0,
      "amount_details": {
        "tip": {}
      },
      "amount_received": 0,
      "application": null,
      "application_fee_amount": null,
      "automatic_payment_methods": null,
      "canceled_at": null,
      "cancellation_reason": null,
      "capture_method": "automatic",
      "charges": {
        "object": "list",
        "data": [],
        "has_more": false,
        "total_count": 0,
        "url": "/v1/charges?payment_intent=pi_3LEOhDHHqepMFuCX12PM6DEk"
      },
      "client_secret": "pi_3LEOhDHHqepMFuCX12PM6DEk_secret_n15ySmDgRhEg6wMogFW30gsE5",
      "confirmation_method": "automatic",
      "created": 1656123963,
      "currency": "usd",
      "customer": "cus_LwHF9dnYz080PN",
      "description": null,
      "invoice": null,
      "last_payment_error": null,
      "livemode": false,
      "metadata": {},
      "next_action": null,
      "on_behalf_of": null,
      "payment_method": null,
      "payment_method_options": {
        "card": {
          "installments": null,
          "mandate_options": null,
          "network": null,
          "request_three_d_secure": "automatic"
        }
      },
      "payment_method_types": [
        "card"
      ],
      "processing": null,
      "receipt_email": null,
      "review": null,
      "setup_future_usage": null,
      "shipping": null,
      "source": null,
      "statement_descriptor": null,
      "statement_descriptor_suffix": null,
      "status": "requires_payment_method",
      "transfer_data": null,
      "transfer_group": null
    },
    "accountid": "acct_a3b223a6fb08c867",
    "customerid": "cus_LwHF9dnYz080PN",
    "paymentmethodid": "pm_1LEOh8HHqepMFuCXPv1RaMaZ",
    "subscriptionid": null,
    "invoiceid": null,
    "status": "requires_payment_method",
    "appid": "tests_1656123957",
    "createdAt": "2022-06-25T02:26:04.022Z",
    "updatedAt": "2022-06-25T02:26:04.486Z"
  },
  {
    "paymentintentid": "pi_3LEOhCHHqepMFuCX1XvxavJM",
    "object": "paymentintent",
    "stripeObject": {
      "id": "pi_3LEOhCHHqepMFuCX1XvxavJM",
      "object": "payment_intent",
      "amount": 10000,
      "amount_capturable": 0,
      "amount_details": {
        "tip": {}
      },
      "amount_received": 0,
      "application": null,
      "application_fee_amount": null,
      "automatic_payment_methods": null,
      "canceled_at": null,
      "cancellation_reason": null,
      "capture_method": "automatic",
      "charges": {
        "object": "list",
        "data": [],
        "has_more": false,
        "total_count": 0,
        "url": "/v1/charges?payment_intent=pi_3LEOhCHHqepMFuCX1XvxavJM"
      },
      "client_secret": "pi_3LEOhCHHqepMFuCX1XvxavJM_secret_kRM5sCn4EL9V78HHUJ01CDLQT",
      "confirmation_method": "automatic",
      "created": 1656123962,
      "currency": "usd",
      "customer": "cus_LwHF9dnYz080PN",
      "description": null,
      "invoice": null,
      "last_payment_error": null,
      "livemode": false,
      "metadata": {},
      "next_action": null,
      "on_behalf_of": null,
      "payment_method": null,
      "payment_method_options": {
        "card": {
          "installments": null,
          "mandate_options": null,
          "network": null,
          "request_three_d_secure": "automatic"
        }
      },
      "payment_method_types": [
        "card"
      ],
      "processing": null,
      "receipt_email": null,
      "review": null,
      "setup_future_usage": null,
      "shipping": null,
      "source": null,
      "statement_descriptor": null,
      "statement_descriptor_suffix": null,
      "status": "requires_payment_method",
      "transfer_data": null,
      "transfer_group": null
    },
    "accountid": "acct_a3b223a6fb08c867",
    "customerid": "cus_LwHF9dnYz080PN",
    "paymentmethodid": "pm_1LEOh8HHqepMFuCXPv1RaMaZ",
    "subscriptionid": null,
    "invoiceid": null,
    "status": "requires_payment_method",
    "appid": "tests_1656123957",
    "createdAt": "2022-06-25T02:26:03.210Z",
    "updatedAt": "2022-06-25T02:26:03.827Z"
  },
  {
    "paymentintentid": "pi_3LEOhCHHqepMFuCX0GqvtJf1",
    "object": "paymentintent",
    "stripeObject": {
      "id": "pi_3LEOhCHHqepMFuCX0GqvtJf1",
      "object": "payment_intent",
      "amount": 10000,
      "amount_capturable": 0,
      "amount_details": {
        "tip": {}
      },
      "amount_received": 0,
      "application": null,
      "application_fee_amount": null,
      "automatic_payment_methods": null,
      "canceled_at": null,
      "cancellation_reason": null,
      "capture_method": "automatic",
      "charges": {
        "object": "list",
        "data": [],
        "has_more": false,
        "total_count": 0,
        "url": "/v1/charges?payment_intent=pi_3LEOhCHHqepMFuCX0GqvtJf1"
      },
      "client_secret": "pi_3LEOhCHHqepMFuCX0GqvtJf1_secret_XbhlD0ogL69MNfxiPk44LU786",
      "confirmation_method": "automatic",
      "created": 1656123962,
      "currency": "usd",
      "customer": "cus_LwHF9dnYz080PN",
      "description": null,
      "invoice": null,
      "last_payment_error": null,
      "livemode": false,
      "metadata": {},
      "next_action": null,
      "on_behalf_of": null,
      "payment_method": null,
      "payment_method_options": {
        "card": {
          "installments": null,
          "mandate_options": null,
          "network": null,
          "request_three_d_secure": "automatic"
        }
      },
      "payment_method_types": [
        "card"
      ],
      "processing": null,
      "receipt_email": null,
      "review": null,
      "setup_future_usage": null,
      "shipping": null,
      "source": null,
      "statement_descriptor": null,
      "statement_descriptor_suffix": null,
      "status": "requires_payment_method",
      "transfer_data": null,
      "transfer_group": null
    },
    "accountid": "acct_a3b223a6fb08c867",
    "customerid": "cus_LwHF9dnYz080PN",
    "paymentmethodid": "pm_1LEOh8HHqepMFuCXPv1RaMaZ",
    "subscriptionid": null,
    "invoiceid": null,
    "status": "requires_payment_method",
    "appid": "tests_1656123957",
    "createdAt": "2022-06-25T02:26:02.209Z",
    "updatedAt": "2022-06-25T02:26:03.035Z"
  }
]

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

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

NodeJS source (view on github)

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

module.exports = {
  get: 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')
    }
    const where = {
      accountid: req.query.accountid,
      appid: req.appid || global.appid
    }
    let paymentintentids
    if (req.query.all) {
      paymentintentids = await subscriptions.Storage.PaymentIntent.findAll({
        where,
        attributes: ['paymentintentid'],
        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
      paymentintentids = await subscriptions.Storage.PaymentIntent.findAll({
        where,
        attributes: ['paymentintentid'],
        offset,
        limit,
        order: [
          ['createdAt', 'DESC']
        ]
      })
    }
    if (!paymentintentids || !paymentintentids.length) {
      return null
    }
    const items = []
    for (const paymentintentInfo of paymentintentids) {
      req.query.paymentintentid = paymentintentInfo.dataValues.paymentintentid
      const paymentintent = await global.api.user.subscriptions.PaymentIntent.get(req)
      items.push(paymentintent)
    }
    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/user/subscriptions/payment-intents', function () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  let cachedResponses, cachedPaymentIntents
  async function bundledData (retryNumber) {
    if (retryNumber > 0) {
      cachedResponses = {}
    }
    if (cachedResponses && cachedResponses.finished) {
      return
    }
    cachedResponses = {}
    cachedPaymentIntents = []
    await TestHelper.setupBefore()
    await DashboardTestHelper.setupBeforeEach()
    await TestHelper.setupBeforeEach()
    const administrator = await TestHelper.createOwner()
    await TestHelper.createProduct(administrator, {
      active: 'true'
    })
    const user = await TestStripeAccounts.createUserWithPaymentMethod()
    for (let i = 0, len = global.pageSize + 2; i < len; i++) {
      await TestHelper.createPaymentIntent(user, {
        amount: '10000',
        currency: 'usd',
        paymentmethodid: user.paymentMethod.paymentmethodid
      })
      cachedPaymentIntents.unshift(user.paymentIntent.paymentintentid)
    }
    const req1 = TestHelper.createRequest(`/api/user/subscriptions/payment-intents?accountid=${user.account.accountid}&offset=1`)
    req1.account = user.account
    req1.session = user.session
    cachedResponses.offset = await req1.get()
    const req2 = TestHelper.createRequest(`/api/user/subscriptions/payment-intents?accountid=${user.account.accountid}&limit=1`)
    req2.account = user.account
    req2.session = user.session
    cachedResponses.limit = await req2.get()
    const req3 = TestHelper.createRequest(`/api/user/subscriptions/payment-intents?accountid=${user.account.accountid}&all=true`)
    req3.account = user.account
    req3.session = user.session
    cachedResponses.all = await req3.get()
    const req4 = TestHelper.createRequest(`/api/user/subscriptions/payment-intents?accountid=${user.account.accountid}`)
    req4.account = user.account
    req4.session = user.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('exceptions', () => {
    describe('invalid-accountid', () => {
      it('missing querystring accountid', async () => {
        const user = await TestHelper.createUser()
        const req = TestHelper.createRequest('/api/user/subscriptions/payment-intents')
        req.account = user.account
        req.session = user.session
        let errorMessage
        try {
          await req.get()
        } 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/subscriptions/payment-intents?accountid=invalid')
        req.account = user.account
        req.session = user.session
        let errorMessage
        try {
          await req.get()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-accountid')
      })
    })

    describe('invalid-account', () => {
      it('ineligible accessing account', async function () {
        await bundledData(this.test.currentRetry())
        const user = await TestHelper.createUser()
        const user2 = await TestHelper.createUser()
        const req = TestHelper.createRequest(`/api/user/subscriptions/payment-intents?accountid=${user.account.accountid}`)
        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('receives', () => {
    it('optional querystring offset (integer)', async function () {
      await bundledData(this.test.currentRetry())
      const offset = 1
      const paymentIntentsNow = cachedResponses.offset
      for (let i = 0, len = global.pageSize; i < len; i++) {
        assert.strictEqual(paymentIntentsNow[i].paymentintentid, cachedPaymentIntents[offset + i])
      }
    })

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

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

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

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