/api/administrator/subscriptions/customer (GET)
await global.api.administrator.subscriptions.Customer.get(req) Located in Stripe Subscriptions module API
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 customerid | |
invalid-customerid | missing querystring customerid |
NodeJS source (edit on github)
If you see a problem with the source submit a pull request on Github.
const stripeCache = require('../../../../stripe-cache.js')
module.exports = {
get: async (req) => {
if (!req.query || !req.query.customerid) {
throw new Error('invalid-customerid')
}
let customer
try {
customer = await stripeCache.retrieve(req.query.customerid, 'customers', req.stripeKey)
} catch (error) {
}
if (!customer) {
throw new Error('invalid-customerid')
}
return customer
}
}
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/customer', function () {
before(TestHelper.setupWebhook)
after(TestHelper.deleteOldWebhooks)
describe('exceptions', () => {
describe('invalid-customerid', () => {
it('missing querystring customerid', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/subscriptions/customer')
req.account = administrator.account
req.session = administrator.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-customerid')
})
it('invalid querystring customerid', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/subscriptions/customer?customerid=invalid')
req.account = administrator.account
req.session = administrator.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-customerid')
})
})
})
describe('returns', () => {
it('object', async () => {
const administrator = await TestHelper.createOwner()
const user = await TestStripeAccounts.createUserWithPaymentMethod()
const req = TestHelper.createRequest(`/api/administrator/subscriptions/customer?customerid=${user.customer.id}`)
req.account = administrator.account
req.session = administrator.session
req.filename = __filename
req.saveResponse = true
const customer = await req.get()
assert.strictEqual(customer.id, user.customer.id)
})
})
})