Stripe Subscriptions module API explorer

/api/administrator/subscriptions/payment-intent (GET)

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

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

Returns object

{
  "paymentintentid": "pi_3LEOKmHHqepMFuCX0VdjCw9X",
  "object": "paymentintent",
  "stripeObject": {
    "id": "pi_3LEOKmHHqepMFuCX0VdjCw9X",
    "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_3LEOKmHHqepMFuCX0VdjCw9X"
    },
    "client_secret": "pi_3LEOKmHHqepMFuCX0VdjCw9X_secret_vOuBRuZRIwyQLHNaqn8gOLCZX",
    "confirmation_method": "automatic",
    "created": 1656122572,
    "currency": "usd",
    "customer": "cus_LwGs3b2WsJ6FBs",
    "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_611d29ac706d36dd",
  "customerid": "cus_LwGs3b2WsJ6FBs",
  "paymentmethodid": "pm_1LEOKkHHqepMFuCXAjiakUPN",
  "subscriptionid": null,
  "invoiceid": null,
  "status": "requires_payment_method",
  "appid": "tests_1656122569",
  "createdAt": "2022-06-25T02:02:53.033Z",
  "updatedAt": "2022-06-25T02:02:53.501Z"
}

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

NodeJS source (view on github)

const dashboard = require('@layeredapps/dashboard')
const subscriptions = require('../../../../../index.js')

module.exports = {
  get: async (req) => {
    if (!req.query || !req.query.paymentintentid) {
      throw new Error('invalid-paymentintentid')
    }
    let paymentIntent = await dashboard.StorageCache.get(req.query.paymentintentid)
    if (!paymentIntent) {
      const paymentIntentInfo = await subscriptions.Storage.PaymentIntent.findOne({
        where: {
          paymentintentid: req.query.paymentintentid,
          appid: req.appid || global.appid
        }
      })
      if (!paymentIntentInfo) {
        throw new Error('invalid-paymentintentid')
      }
      paymentIntent = {}
      for (const field of paymentIntentInfo._options.attributes) {
        paymentIntent[field] = paymentIntentInfo.get(field)
      }
      await dashboard.StorageCache.set(req.query.paymentintentid, paymentIntent)
    }
    return paymentIntent
  }
}

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/administrator/subscriptions/payment-intent', function () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  describe('exceptions', () => {
    describe('invalid-paymentintentid', () => {
      it('missing querystring paymentintentid', async () => {
        const administrator = await TestHelper.createOwner()
        const req = TestHelper.createRequest('/api/administrator/subscriptions/payment-intent')
        req.account = administrator.account
        req.session = administrator.session
        let errorMessage
        try {
          await req.get()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-paymentintentid')
      })

      it('invalid querystring paymentintentid', async () => {
        const administrator = await TestHelper.createOwner()
        const req = TestHelper.createRequest('/api/administrator/subscriptions/payment-intent?paymentintentid=invalid')
        req.account = administrator.account
        req.session = administrator.session
        let errorMessage
        try {
          await req.get()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-paymentintentid')
      })
    })
  })

  describe('returns', () => {
    it('object', async () => {
      const administrator = await TestHelper.createOwner()
      const user = await TestStripeAccounts.createUserWithPaymentMethod()
      await TestHelper.createPaymentIntent(user, {
        amount: '10000',
        currency: 'usd',
        paymentmethodid: user.paymentMethod.paymentmethodid
      })
      const req = TestHelper.createRequest(`/api/administrator/subscriptions/payment-intent?paymentintentid=${user.paymentIntent.paymentintentid}`)
      req.account = administrator.account
      req.session = administrator.session
      req.filename = __filename
      req.saveResponse = true
      const paymentIntent = await req.get()
      assert.strictEqual(paymentIntent.paymentintentid, user.paymentIntent.paymentintentid)
    })
  })
})