Stripe Subscriptions module API explorer

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

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

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

Returns array

[
  {
    "paymentmethodid": "pm_1LEOMBHHqepMFuCX1NRH32hT",
    "object": "paymentmethod",
    "accountid": "acct_bbe328c88941332a",
    "customerid": "cus_LwGt2xXQn9rdPy",
    "stripeObject": {
      "id": "pm_1LEOMBHHqepMFuCX1NRH32hT",
      "object": "payment_method",
      "billing_details": {
        "address": {
          "city": "New York",
          "country": "US",
          "line1": "285 Fulton St",
          "line2": "Apt 893",
          "postal_code": "10007",
          "state": "NY"
        },
        "email": null,
        "name": "Helen Lakin",
        "phone": null
      },
      "card": {
        "brand": "visa",
        "checks": {
          "address_line1_check": "pass",
          "address_postal_code_check": "pass",
          "cvc_check": "pass"
        },
        "country": "US",
        "exp_month": 1,
        "exp_year": 2023,
        "fingerprint": "IRcdqfBUCskmPkNV",
        "funding": "credit",
        "generated_from": null,
        "last4": "1111",
        "networks": {
          "available": [
            "visa"
          ],
          "preferred": null
        },
        "three_d_secure_usage": {
          "supported": true
        },
        "wallet": null
      },
      "created": 1656122660,
      "customer": "cus_LwGt2xXQn9rdPy",
      "livemode": false,
      "metadata": {},
      "type": "card"
    },
    "appid": "tests_1656122649",
    "createdAt": "2022-06-25T02:04:20.965Z",
    "updatedAt": "2022-06-25T02:04:21.774Z"
  },
  {
    "paymentmethodid": "pm_1LEOM8HHqepMFuCXlmheWfz2",
    "object": "paymentmethod",
    "accountid": "acct_37736c14f3759140",
    "customerid": "cus_LwGtUtv4vhOKqz",
    "stripeObject": {
      "id": "pm_1LEOM8HHqepMFuCXlmheWfz2",
      "object": "payment_method",
      "billing_details": {
        "address": {
          "city": "New York",
          "country": "US",
          "line1": "285 Fulton St",
          "line2": "Apt 893",
          "postal_code": "10007",
          "state": "NY"
        },
        "email": null,
        "name": "Terrence Olson",
        "phone": null
      },
      "card": {
        "brand": "visa",
        "checks": {
          "address_line1_check": "pass",
          "address_postal_code_check": "pass",
          "cvc_check": "pass"
        },
        "country": "US",
        "exp_month": 1,
        "exp_year": 2023,
        "fingerprint": "IRcdqfBUCskmPkNV",
        "funding": "credit",
        "generated_from": null,
        "last4": "1111",
        "networks": {
          "available": [
            "visa"
          ],
          "preferred": null
        },
        "three_d_secure_usage": {
          "supported": true
        },
        "wallet": null
      },
      "created": 1656122656,
      "customer": "cus_LwGtUtv4vhOKqz",
      "livemode": false,
      "metadata": {},
      "type": "card"
    },
    "appid": "tests_1656122649",
    "createdAt": "2022-06-25T02:04:17.857Z",
    "updatedAt": "2022-06-25T02:04:18.678Z"
  },
  {
    "paymentmethodid": "pm_1LEOM5HHqepMFuCXbSL1tfsl",
    "object": "paymentmethod",
    "accountid": "acct_e7ed786ebc266894",
    "customerid": "cus_LwGtqyTQKU1dv0",
    "stripeObject": {
      "id": "pm_1LEOM5HHqepMFuCXbSL1tfsl",
      "object": "payment_method",
      "billing_details": {
        "address": {
          "city": "New York",
          "country": "US",
          "line1": "285 Fulton St",
          "line2": "Apt 893",
          "postal_code": "10007",
          "state": "NY"
        },
        "email": null,
        "name": "Felipe Harber",
        "phone": null
      },
      "card": {
        "brand": "visa",
        "checks": {
          "address_line1_check": "pass",
          "address_postal_code_check": "pass",
          "cvc_check": "pass"
        },
        "country": "US",
        "exp_month": 1,
        "exp_year": 2023,
        "fingerprint": "IRcdqfBUCskmPkNV",
        "funding": "credit",
        "generated_from": null,
        "last4": "1111",
        "networks": {
          "available": [
            "visa"
          ],
          "preferred": null
        },
        "three_d_secure_usage": {
          "supported": true
        },
        "wallet": null
      },
      "created": 1656122653,
      "customer": "cus_LwGtqyTQKU1dv0",
      "livemode": false,
      "metadata": {},
      "type": "card"
    },
    "appid": "tests_1656122649",
    "createdAt": "2022-06-25T02:04:14.453Z",
    "updatedAt": "2022-06-25T02:04:15.461Z"
  }
]

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 paymentmethodids
    if (req.query.all) {
      paymentmethodids = await subscriptions.Storage.PaymentMethod.findAll({
        where,
        attributes: ['paymentmethodid'],
        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
      paymentmethodids = await subscriptions.Storage.PaymentMethod.findAll({
        where,
        attributes: ['paymentmethodid'],
        offset,
        limit,
        order: [
          ['createdAt', 'DESC']
        ]
      })
    }
    if (!paymentmethodids || !paymentmethodids.length) {
      return null
    }
    const items = []
    for (const paymentmethodInfo of paymentmethodids) {
      req.query.paymentmethodid = paymentmethodInfo.dataValues.paymentmethodid
      const paymentmethod = await global.api.administrator.subscriptions.PaymentMethod.get(req)
      items.push(paymentmethod)
    }
    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/payment-methods', function () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  let cachedResponses, cachedPaymentMethods
  async function bundledData (retryNumber) {
    if (retryNumber > 0) {
      cachedResponses = {}
    }
    if (cachedResponses && cachedResponses.finished) {
      return
    }
    cachedResponses = {}
    cachedPaymentMethods = []
    await TestHelper.setupBefore()
    await DashboardTestHelper.setupBeforeEach()
    await TestHelper.setupBeforeEach()
    const administrator = await TestHelper.createOwner()
    for (let i = 0, len = global.pageSize + 2; i < len; i++) {
      const user = await TestStripeAccounts.createUserWithPaymentMethod()
      cachedPaymentMethods.unshift(user.paymentMethod.paymentmethodid)
    }
    const req1 = TestHelper.createRequest('/api/administrator/subscriptions/payment-methods?offset=1')
    req1.account = administrator.account
    req1.session = administrator.session
    cachedResponses.offset = await req1.get()
    const req2 = TestHelper.createRequest('/api/administrator/subscriptions/payment-methods?limit=1')
    req2.account = administrator.account
    req2.session = administrator.session
    cachedResponses.limit = await req2.get()
    const req3 = TestHelper.createRequest('/api/administrator/subscriptions/payment-methods?all=true')
    req3.account = administrator.account
    req3.session = administrator.session
    cachedResponses.all = await req3.get()
    const req4 = TestHelper.createRequest('/api/administrator/subscriptions/payment-methods')
    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 paymentMethodsNow = cachedResponses.offset
      for (let i = 0, len = global.pageSize; i < len; i++) {
        assert.strictEqual(paymentMethodsNow[i].paymentmethodid, cachedPaymentMethods[offset + i])
      }
    })

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

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

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

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