Stripe Subscriptions module API explorer

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

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

Returns object

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

NodeJS source (edit on github)

If you see a problem with the source submit a pull request on Github.

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

module.exports = {
  get: async (req) => {
    if (!req.query || !req.query.paymentmethodid) {
      throw new Error('invalid-paymentmethodid')
    }
    const exists = await subscriptions.StorageList.exists(`${req.appid}/paymentMethods`, req.query.paymentmethodid)
    if (!exists) {
      throw new Error('invalid-paymentmethodid')
    }
    let paymentMethod
    try {
      paymentMethod = await stripeCache.retrieve(req.query.paymentmethodid, 'paymentMethods', req.stripeKey)
    } catch (error) {
    }
    if (!paymentMethod) {
      throw new Error('invalid-paymentmethodid')
    }
    return paymentMethod
  }
}

Test source (edit on github)

Tests perform real HTTP requests against a running Dashboard server.

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

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

  describe('returns', () => {
    it('object', async () => {
      const administrator = await TestHelper.createOwner()
      const user = await TestStripeAccounts.createUserWithPaymentMethod()
      const req = TestHelper.createRequest(`/api/administrator/subscriptions/payment-method?paymentmethodid=${user.paymentMethod.id}`)
      req.account = administrator.account
      req.session = administrator.session
      req.filename = __filename
      req.saveResponse = true
      const paymentMethod = await req.get()
      assert.strictEqual(paymentMethod.id, user.paymentMethod.id)
    })
  })
})