Stripe Subscriptions module API explorer

/api/user/subscriptions/invoices (GET)

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

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

Returns array

[
  {
    "invoiceid": "in_1LEOgTHHqepMFuCXv6DQB7Uw",
    "object": "invoice",
    "stripeObject": {
      "id": "in_1LEOgTHHqepMFuCXv6DQB7Uw",
      "object": "invoice",
      "account_country": "AU",
      "account_name": "test-subscriptions",
      "account_tax_ids": null,
      "amount_due": 3000,
      "amount_paid": 3000,
      "amount_remaining": 0,
      "application": null,
      "application_fee_amount": null,
      "attempt_count": 1,
      "attempted": true,
      "auto_advance": false,
      "automatic_tax": {
        "enabled": false,
        "status": null
      },
      "billing_reason": "subscription_create",
      "charge": "ch_3LEOgTHHqepMFuCX1jhwBFRL",
      "collection_method": "charge_automatically",
      "created": 1656123917,
      "currency": "usd",
      "custom_fields": null,
      "customer": "cus_LwHEwBSVCgAeCh",
      "customer_address": null,
      "customer_email": "Sandy_Rodriguez@hotmail.com",
      "customer_name": null,
      "customer_phone": null,
      "customer_shipping": null,
      "customer_tax_exempt": "none",
      "customer_tax_ids": [],
      "default_payment_method": null,
      "default_source": null,
      "default_tax_rates": [],
      "description": null,
      "discount": null,
      "discounts": [],
      "due_date": null,
      "ending_balance": 0,
      "footer": null,
      "hosted_invoice_url": "https://invoice.stripe.com/i/acct_1KhiP8HHqepMFuCX/test_YWNjdF8xS2hpUDhISHFlcE1GdUNYLF9Md0hFSlpTeHBsOXV5WUZwbkI1SEgzbER2WFp5bVB1LDQ2NjY0NzIx0200UwH0IOJs?s=ap",
      "invoice_pdf": "https://pay.stripe.com/invoice/acct_1KhiP8HHqepMFuCX/test_YWNjdF8xS2hpUDhISHFlcE1GdUNYLF9Md0hFSlpTeHBsOXV5WUZwbkI1SEgzbER2WFp5bVB1LDQ2NjY0NzIx0200UwH0IOJs/pdf?s=ap",
      "last_finalization_error": null,
      "lines": {
        "object": "list",
        "data": [
          {
            "id": "il_1LEOgTHHqepMFuCX9qIXvfVc",
            "object": "line_item",
            "amount": 3000,
            "amount_excluding_tax": 3000,
            "currency": "usd",
            "description": "1 thing × product267 (at $30.00 / month)",
            "discount_amounts": [],
            "discountable": true,
            "discounts": [],
            "livemode": false,
            "metadata": {},
            "period": {
              "end": 1658715917,
              "start": 1656123917
            },
            "plan": {
              "id": "price_1LEOgSHHqepMFuCXnfBVcQ7M",
              "object": "plan",
              "active": true,
              "aggregate_usage": null,
              "amount": 3000,
              "amount_decimal": "3000",
              "billing_scheme": "per_unit",
              "created": 1656123916,
              "currency": "usd",
              "interval": "month",
              "interval_count": 1,
              "livemode": false,
              "metadata": {},
              "nickname": null,
              "product": "prod_LwHEiYnhkEMc6o",
              "tiers_mode": null,
              "transform_usage": null,
              "trial_period_days": null,
              "usage_type": "licensed"
            },
            "price": {
              "id": "price_1LEOgSHHqepMFuCXnfBVcQ7M",
              "object": "price",
              "active": true,
              "billing_scheme": "per_unit",
              "created": 1656123916,
              "currency": "usd",
              "custom_unit_amount": null,
              "livemode": false,
              "lookup_key": null,
              "metadata": {},
              "nickname": null,
              "product": "prod_LwHEiYnhkEMc6o",
              "recurring": {
                "aggregate_usage": null,
                "interval": "month",
                "interval_count": 1,
                "trial_period_days": null,
                "usage_type": "licensed"
              },
              "tax_behavior": "inclusive",
              "tiers_mode": null,
              "transform_quantity": null,
              "type": "recurring",
              "unit_amount": 3000,
              "unit_amount_decimal": "3000"
            },
            "proration": false,
            "proration_details": {
              "credited_items": null
            },
            "quantity": 1,
            "subscription": "sub_1LEOgTHHqepMFuCXNvHzTwB4",
            "subscription_item": "si_LwHEI7kEPJlueO",
            "tax_amounts": [],
            "tax_rates": [],
            "type": "subscription",
            "unit_amount_excluding_tax": "3000"
          }
        ],
        "has_more": false,
        "total_count": 1,
        "url": "/v1/invoices/in_1LEOgTHHqepMFuCXv6DQB7Uw/lines"
      },
      "livemode": false,
      "metadata": {},
      "next_payment_attempt": null,
      "number": "0D881096-0004",
      "on_behalf_of": null,
      "paid": true,
      "paid_out_of_band": false,
      "payment_intent": "pi_3LEOgTHHqepMFuCX1bt0V8j9",
      "payment_settings": {
        "payment_method_options": null,
        "payment_method_types": null
      },
      "period_end": 1656123917,
      "period_start": 1656123917,
      "post_payment_credit_notes_amount": 0,
      "pre_payment_credit_notes_amount": 0,
      "quote": null,
      "receipt_number": null,
      "rendering_options": null,
      "starting_balance": 0,
      "statement_descriptor": null,
      "status": "paid",
      "status_transitions": {
        "finalized_at": 1656123917,
        "marked_uncollectible_at": null,
        "paid_at": 1656123917,
        "voided_at": null
      },
      "subscription": "sub_1LEOgTHHqepMFuCXNvHzTwB4",
      "subtotal": 3000,
      "subtotal_excluding_tax": 3000,
      "tax": null,
      "test_clock": null,
      "total": 3000,
      "total_discount_amounts": [],
      "total_excluding_tax": 3000,
      "total_tax_amounts": [],
      "transfer_data": null,
      "webhooks_delivered_at": null
    },
    "customerid": "cus_LwHEwBSVCgAeCh",
    "subscriptionid": "sub_1LEOgTHHqepMFuCXNvHzTwB4",
    "accountid": "acct_4eec9af9465562c7",
    "appid": "tests_1656123897",
    "createdAt": "2022-06-25T02:25:20.524Z",
    "updatedAt": "2022-06-25T02:25:21.184Z"
  },
  {
    "invoiceid": "in_1LEOgOHHqepMFuCXnkaKrjRN",
    "object": "invoice",
    "stripeObject": {
      "id": "in_1LEOgOHHqepMFuCXnkaKrjRN",
      "object": "invoice",
      "account_country": "AU",
      "account_name": "test-subscriptions",
      "account_tax_ids": null,
      "amount_due": 3000,
      "amount_paid": 3000,
      "amount_remaining": 0,
      "application": null,
      "application_fee_amount": null,
      "attempt_count": 1,
      "attempted": true,
      "auto_advance": false,
      "automatic_tax": {
        "enabled": false,
        "status": null
      },
      "billing_reason": "subscription_create",
      "charge": "ch_3LEOgOHHqepMFuCX1ZPdpFq3",
      "collection_method": "charge_automatically",
      "created": 1656123912,
      "currency": "usd",
      "custom_fields": null,
      "customer": "cus_LwHEwBSVCgAeCh",
      "customer_address": null,
      "customer_email": "Sandy_Rodriguez@hotmail.com",
      "customer_name": null,
      "customer_phone": null,
      "customer_shipping": null,
      "customer_tax_exempt": "none",
      "customer_tax_ids": [],
      "default_payment_method": null,
      "default_source": null,
      "default_tax_rates": [],
      "description": null,
      "discount": null,
      "discounts": [],
      "due_date": null,
      "ending_balance": 0,
      "footer": null,
      "hosted_invoice_url": "https://invoice.stripe.com/i/acct_1KhiP8HHqepMFuCX/test_YWNjdF8xS2hpUDhISHFlcE1GdUNYLF9Md0hFNTQ1cGJFZnJJTEN3dWVxd1FOSVg5Qmc4ZUZ4LDQ2NjY0NzE30200xyzawLmH?s=ap",
      "invoice_pdf": "https://pay.stripe.com/invoice/acct_1KhiP8HHqepMFuCX/test_YWNjdF8xS2hpUDhISHFlcE1GdUNYLF9Md0hFNTQ1cGJFZnJJTEN3dWVxd1FOSVg5Qmc4ZUZ4LDQ2NjY0NzE30200xyzawLmH/pdf?s=ap",
      "last_finalization_error": null,
      "lines": {
        "object": "list",
        "data": [
          {
            "id": "il_1LEOgOHHqepMFuCXbDa3RbnA",
            "object": "line_item",
            "amount": 3000,
            "amount_excluding_tax": 3000,
            "currency": "usd",
            "description": "1 thing × product267 (at $30.00 / month)",
            "discount_amounts": [],
            "discountable": true,
            "discounts": [],
            "livemode": false,
            "metadata": {},
            "period": {
              "end": 1658715912,
              "start": 1656123912
            },
            "plan": {
              "id": "price_1LEOgNHHqepMFuCXztk7u200",
              "object": "plan",
              "active": true,
              "aggregate_usage": null,
              "amount": 3000,
              "amount_decimal": "3000",
              "billing_scheme": "per_unit",
              "created": 1656123911,
              "currency": "usd",
              "interval": "month",
              "interval_count": 1,
              "livemode": false,
              "metadata": {},
              "nickname": null,
              "product": "prod_LwHEiYnhkEMc6o",
              "tiers_mode": null,
              "transform_usage": null,
              "trial_period_days": null,
              "usage_type": "licensed"
            },
            "price": {
              "id": "price_1LEOgNHHqepMFuCXztk7u200",
              "object": "price",
              "active": true,
              "billing_scheme": "per_unit",
              "created": 1656123911,
              "currency": "usd",
              "custom_unit_amount": null,
              "livemode": false,
              "lookup_key": null,
              "metadata": {},
              "nickname": null,
              "product": "prod_LwHEiYnhkEMc6o",
              "recurring": {
                "aggregate_usage": null,
                "interval": "month",
                "interval_count": 1,
                "trial_period_days": null,
                "usage_type": "licensed"
              },
              "tax_behavior": "inclusive",
              "tiers_mode": null,
              "transform_quantity": null,
              "type": "recurring",
              "unit_amount": 3000,
              "unit_amount_decimal": "3000"
            },
            "proration": false,
            "proration_details": {
              "credited_items": null
            },
            "quantity": 1,
            "subscription": "sub_1LEOgOHHqepMFuCXOglI8Pb0",
            "subscription_item": "si_LwHERpH4Mfz4sT",
            "tax_amounts": [],
            "tax_rates": [],
            "type": "subscription",
            "unit_amount_excluding_tax": "3000"
          }
        ],
        "has_more": false,
        "total_count": 1,
        "url": "/v1/invoices/in_1LEOgOHHqepMFuCXnkaKrjRN/lines"
      },
      "livemode": false,
      "metadata": {},
      "next_payment_attempt": null,
      "number": "0D881096-0003",
      "on_behalf_of": null,
      "paid": true,
      "paid_out_of_band": false,
      "payment_intent": "pi_3LEOgOHHqepMFuCX1oUmpQt8",
      "payment_settings": {
        "payment_method_options": null,
        "payment_method_types": null
      },
      "period_end": 1656123912,
      "period_start": 1656123912,
      "post_payment_credit_notes_amount": 0,
      "pre_payment_credit_notes_amount": 0,
      "quote": null,
      "receipt_number": null,
      "rendering_options": null,
      "starting_balance": 0,
      "statement_descriptor": null,
      "status": "paid",
      "status_transitions": {
        "finalized_at": 1656123912,
        "marked_uncollectible_at": null,
        "paid_at": 1656123912,
        "voided_at": null
      },
      "subscription": "sub_1LEOgOHHqepMFuCXOglI8Pb0",
      "subtotal": 3000,
      "subtotal_excluding_tax": 3000,
      "tax": null,
      "test_clock": null,
      "total": 3000,
      "total_discount_amounts": [],
      "total_excluding_tax": 3000,
      "total_tax_amounts": [],
      "transfer_data": null,
      "webhooks_delivered_at": null
    },
    "customerid": "cus_LwHEwBSVCgAeCh",
    "subscriptionid": "sub_1LEOgOHHqepMFuCXOglI8Pb0",
    "accountid": "acct_4eec9af9465562c7",
    "appid": "tests_1656123897",
    "createdAt": "2022-06-25T02:25:15.630Z",
    "updatedAt": "2022-06-25T02:25:17.287Z"
  },
  {
    "invoiceid": "in_1LEOgJHHqepMFuCXkHJaRXLG",
    "object": "invoice",
    "stripeObject": {
      "id": "in_1LEOgJHHqepMFuCXkHJaRXLG",
      "object": "invoice",
      "account_country": "AU",
      "account_name": "test-subscriptions",
      "account_tax_ids": null,
      "amount_due": 3000,
      "amount_paid": 3000,
      "amount_remaining": 0,
      "application": null,
      "application_fee_amount": null,
      "attempt_count": 1,
      "attempted": true,
      "auto_advance": false,
      "automatic_tax": {
        "enabled": false,
        "status": null
      },
      "billing_reason": "subscription_create",
      "charge": "ch_3LEOgJHHqepMFuCX1ztkt9xb",
      "collection_method": "charge_automatically",
      "created": 1656123907,
      "currency": "usd",
      "custom_fields": null,
      "customer": "cus_LwHEwBSVCgAeCh",
      "customer_address": null,
      "customer_email": "Sandy_Rodriguez@hotmail.com",
      "customer_name": null,
      "customer_phone": null,
      "customer_shipping": null,
      "customer_tax_exempt": "none",
      "customer_tax_ids": [],
      "default_payment_method": null,
      "default_source": null,
      "default_tax_rates": [],
      "description": null,
      "discount": null,
      "discounts": [],
      "due_date": null,
      "ending_balance": 0,
      "footer": null,
      "hosted_invoice_url": "https://invoice.stripe.com/i/acct_1KhiP8HHqepMFuCX/test_YWNjdF8xS2hpUDhISHFlcE1GdUNYLF9Md0hFOVdaQVMyYnJhVXViTUtLdG5YbXJtSXIxelRkLDQ2NjY0NzEy0200qDtZM4La?s=ap",
      "invoice_pdf": "https://pay.stripe.com/invoice/acct_1KhiP8HHqepMFuCX/test_YWNjdF8xS2hpUDhISHFlcE1GdUNYLF9Md0hFOVdaQVMyYnJhVXViTUtLdG5YbXJtSXIxelRkLDQ2NjY0NzEy0200qDtZM4La/pdf?s=ap",
      "last_finalization_error": null,
      "lines": {
        "object": "list",
        "data": [
          {
            "id": "il_1LEOgJHHqepMFuCXm2Udsx1S",
            "object": "line_item",
            "amount": 3000,
            "amount_excluding_tax": 3000,
            "currency": "usd",
            "description": "1 thing × product267 (at $30.00 / month)",
            "discount_amounts": [],
            "discountable": true,
            "discounts": [],
            "livemode": false,
            "metadata": {},
            "period": {
              "end": 1658715906,
              "start": 1656123906
            },
            "plan": {
              "id": "price_1LEOgIHHqepMFuCXlYCgKkmH",
              "object": "plan",
              "active": true,
              "aggregate_usage": null,
              "amount": 3000,
              "amount_decimal": "3000",
              "billing_scheme": "per_unit",
              "created": 1656123906,
              "currency": "usd",
              "interval": "month",
              "interval_count": 1,
              "livemode": false,
              "metadata": {},
              "nickname": null,
              "product": "prod_LwHEiYnhkEMc6o",
              "tiers_mode": null,
              "transform_usage": null,
              "trial_period_days": null,
              "usage_type": "licensed"
            },
            "price": {
              "id": "price_1LEOgIHHqepMFuCXlYCgKkmH",
              "object": "price",
              "active": true,
              "billing_scheme": "per_unit",
              "created": 1656123906,
              "currency": "usd",
              "custom_unit_amount": null,
              "livemode": false,
              "lookup_key": null,
              "metadata": {},
              "nickname": null,
              "product": "prod_LwHEiYnhkEMc6o",
              "recurring": {
                "aggregate_usage": null,
                "interval": "month",
                "interval_count": 1,
                "trial_period_days": null,
                "usage_type": "licensed"
              },
              "tax_behavior": "inclusive",
              "tiers_mode": null,
              "transform_quantity": null,
              "type": "recurring",
              "unit_amount": 3000,
              "unit_amount_decimal": "3000"
            },
            "proration": false,
            "proration_details": {
              "credited_items": null
            },
            "quantity": 1,
            "subscription": "sub_1LEOgIHHqepMFuCXY9qfCepd",
            "subscription_item": "si_LwHEakTCOTQvuF",
            "tax_amounts": [],
            "tax_rates": [],
            "type": "subscription",
            "unit_amount_excluding_tax": "3000"
          }
        ],
        "has_more": false,
        "total_count": 1,
        "url": "/v1/invoices/in_1LEOgJHHqepMFuCXkHJaRXLG/lines"
      },
      "livemode": false,
      "metadata": {},
      "next_payment_attempt": null,
      "number": "0D881096-0002",
      "on_behalf_of": null,
      "paid": true,
      "paid_out_of_band": false,
      "payment_intent": "pi_3LEOgJHHqepMFuCX1vGdaTn8",
      "payment_settings": {
        "payment_method_options": null,
        "payment_method_types": null
      },
      "period_end": 1656123906,
      "period_start": 1656123906,
      "post_payment_credit_notes_amount": 0,
      "pre_payment_credit_notes_amount": 0,
      "quote": null,
      "receipt_number": null,
      "rendering_options": null,
      "starting_balance": 0,
      "statement_descriptor": null,
      "status": "paid",
      "status_transitions": {
        "finalized_at": 1656123907,
        "marked_uncollectible_at": null,
        "paid_at": 1656123906,
        "voided_at": null
      },
      "subscription": "sub_1LEOgIHHqepMFuCXY9qfCepd",
      "subtotal": 3000,
      "subtotal_excluding_tax": 3000,
      "tax": null,
      "test_clock": null,
      "total": 3000,
      "total_discount_amounts": [],
      "total_excluding_tax": 3000,
      "total_tax_amounts": [],
      "transfer_data": null,
      "webhooks_delivered_at": null
    },
    "customerid": "cus_LwHEwBSVCgAeCh",
    "subscriptionid": "sub_1LEOgIHHqepMFuCXY9qfCepd",
    "accountid": "acct_4eec9af9465562c7",
    "appid": "tests_1656123897",
    "createdAt": "2022-06-25T02:25:10.775Z",
    "updatedAt": "2022-06-25T02:25:12.284Z"
  }
]

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 = {
      appid: req.appid || global.appid
    }
    if (req.query.customerid) {
      const customer = await global.api.user.subscriptions.Customer.get(req)
      if (!customer) {
        throw new Error('invalid-customerid')
      }
      where.customerid = req.query.customerid
    } else if (req.query.subscriptionid) {
      const subscription = await global.api.user.subscriptions.Subscription.get(req)
      if (!subscription) {
        throw new Error('invalid-subscriptionid')
      }
      where.subscriptionid = req.query.subscriptionid
    } else {
      where.accountid = req.query.accountid
    }
    let invoiceids
    if (req.query.all) {
      invoiceids = await subscriptions.Storage.Invoice.findAll({
        where,
        attributes: ['invoiceid'],
        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
      invoiceids = await subscriptions.Storage.Invoice.findAll({
        where,
        attributes: ['invoiceid'],
        offset,
        limit,
        order: [
          ['createdAt', 'DESC']
        ]
      })
    }
    if (!invoiceids || !invoiceids.length) {
      return null
    }
    const items = []
    for (const invoiceInfo of invoiceids) {
      req.query.invoiceid = invoiceInfo.dataValues.invoiceid
      const invoice = await global.api.user.subscriptions.Invoice.get(req)
      items.push(invoice)
    }
    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/invoices', function () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  let cachedResponses, cachedInvoices
  async function bundledData (retryNumber) {
    if (retryNumber > 0) {
      cachedResponses = {}
    }
    if (cachedResponses && cachedResponses.finished) {
      return
    }
    cachedResponses = {}
    cachedInvoices = []
    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.createPrice(administrator, {
        productid: administrator.product.productid,
        currency: 'usd',
        tax_behavior: 'inclusive',
        unit_amount: 3000,
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'licensed',
        active: 'true'
      })
      await TestStripeAccounts.createUserWithPaidSubscription(administrator.price, user)
      cachedInvoices.unshift(user.invoice.invoiceid)
    }
    const req1 = TestHelper.createRequest(`/api/user/subscriptions/invoices?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/invoices?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/invoices?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/invoices?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/invoices')
        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/invoices?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/customers?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 invoicesNow = cachedResponses.offset
      for (let i = 0, len = global.pageSize; i < len; i++) {
        assert.strictEqual(invoicesNow[i].invoiceid, cachedInvoices[offset + i])
      }
    })

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

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

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

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