/api/administrator/subscriptions/invoices (GET)
Account information like email addresses is generated with faker-js it is not real user information.
await global.api.administrator.subscriptions.Invoices.get(req)Returns array
[
{
"invoiceid": "in_1LEOKZHHqepMFuCXe41ufqix",
"object": "invoice",
"stripeObject": {
"id": "in_1LEOKZHHqepMFuCXe41ufqix",
"object": "invoice",
"account_country": "AU",
"account_name": "test-subscriptions",
"account_tax_ids": null,
"amount_due": 1000,
"amount_paid": 1000,
"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_3LEOKZHHqepMFuCX1IHjP5IO",
"collection_method": "charge_automatically",
"created": 1656122559,
"currency": "usd",
"custom_fields": null,
"customer": "cus_LwGsJ25B0fzvCL",
"customer_address": null,
"customer_email": "Sherman32@gmail.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_YWNjdF8xS2hpUDhISHFlcE1GdUNYLF9Md0dzZTZjSmJSc3psTURFbGVZcXQxYUZmNndDV05qLDQ2NjYzMzYy0200wz2uLrBK?s=ap",
"invoice_pdf": "https://pay.stripe.com/invoice/acct_1KhiP8HHqepMFuCX/test_YWNjdF8xS2hpUDhISHFlcE1GdUNYLF9Md0dzZTZjSmJSc3psTURFbGVZcXQxYUZmNndDV05qLDQ2NjYzMzYy0200wz2uLrBK/pdf?s=ap",
"last_finalization_error": null,
"lines": {
"object": "list",
"data": [
{
"id": "il_1LEOKZHHqepMFuCXnz4RKCrh",
"object": "line_item",
"amount": 1000,
"amount_excluding_tax": 1000,
"currency": "usd",
"description": "1 thing × product181 (at $10.00 / month)",
"discount_amounts": [],
"discountable": true,
"discounts": [],
"livemode": false,
"metadata": {},
"period": {
"end": 1658714558,
"start": 1656122558
},
"plan": {
"id": "price_1LEOK7HHqepMFuCXktG4Zqlx",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 1000,
"amount_decimal": "1000",
"billing_scheme": "per_unit",
"created": 1656122531,
"currency": "usd",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {},
"nickname": null,
"product": "prod_LwGrKYOmwRvm5l",
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed"
},
"price": {
"id": "price_1LEOK7HHqepMFuCXktG4Zqlx",
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1656122531,
"currency": "usd",
"custom_unit_amount": null,
"livemode": false,
"lookup_key": null,
"metadata": {},
"nickname": null,
"product": "prod_LwGrKYOmwRvm5l",
"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": 1000,
"unit_amount_decimal": "1000"
},
"proration": false,
"proration_details": {
"credited_items": null
},
"quantity": 1,
"subscription": "sub_1LEOKZHHqepMFuCXpb0Osagj",
"subscription_item": "si_LwGs7ti8ifJOh9",
"tax_amounts": [],
"tax_rates": [],
"type": "subscription",
"unit_amount_excluding_tax": "1000"
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/invoices/in_1LEOKZHHqepMFuCXe41ufqix/lines"
},
"livemode": false,
"metadata": {},
"next_payment_attempt": null,
"number": "AD75F713-0001",
"on_behalf_of": null,
"paid": true,
"paid_out_of_band": false,
"payment_intent": "pi_3LEOKZHHqepMFuCX1ce1gbsS",
"payment_settings": {
"payment_method_options": null,
"payment_method_types": null
},
"period_end": 1656122558,
"period_start": 1656122558,
"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": 1656122559,
"marked_uncollectible_at": null,
"paid_at": 1656122558,
"voided_at": null
},
"subscription": "sub_1LEOKZHHqepMFuCXpb0Osagj",
"subtotal": 1000,
"subtotal_excluding_tax": 1000,
"tax": null,
"test_clock": null,
"total": 1000,
"total_discount_amounts": [],
"total_excluding_tax": 1000,
"total_tax_amounts": [],
"transfer_data": null,
"webhooks_delivered_at": null
},
"customerid": "cus_LwGsJ25B0fzvCL",
"subscriptionid": "sub_1LEOKZHHqepMFuCXpb0Osagj",
"accountid": "acct_fd56b66387e905a1",
"appid": "tests_1656122530",
"createdAt": "2022-06-25T02:02:41.922Z",
"updatedAt": "2022-06-25T02:02:42.659Z"
},
{
"invoiceid": "in_1LEOKRHHqepMFuCXrE6xJzK5",
"object": "invoice",
"stripeObject": {
"id": "in_1LEOKRHHqepMFuCXrE6xJzK5",
"object": "invoice",
"account_country": "AU",
"account_name": "test-subscriptions",
"account_tax_ids": null,
"amount_due": 1000,
"amount_paid": 1000,
"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_3LEOKRHHqepMFuCX0JVfbdXZ",
"collection_method": "charge_automatically",
"created": 1656122551,
"currency": "usd",
"custom_fields": null,
"customer": "cus_LwGsrZbWvXucF7",
"customer_address": null,
"customer_email": "Minnie.Vandervort@yahoo.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_YWNjdF8xS2hpUDhISHFlcE1GdUNYLF9Md0dzZjVwbEVOWnhTUnZSUW03ODNOYnUwQ2xOZ0lZLDQ2NjYzMzU20200mHiJncGs?s=ap",
"invoice_pdf": "https://pay.stripe.com/invoice/acct_1KhiP8HHqepMFuCX/test_YWNjdF8xS2hpUDhISHFlcE1GdUNYLF9Md0dzZjVwbEVOWnhTUnZSUW03ODNOYnUwQ2xOZ0lZLDQ2NjYzMzU20200mHiJncGs/pdf?s=ap",
"last_finalization_error": null,
"lines": {
"object": "list",
"data": [
{
"id": "il_1LEOKRHHqepMFuCXxMzxwmUN",
"object": "line_item",
"amount": 1000,
"amount_excluding_tax": 1000,
"currency": "usd",
"description": "1 thing × product181 (at $10.00 / month)",
"discount_amounts": [],
"discountable": true,
"discounts": [],
"livemode": false,
"metadata": {},
"period": {
"end": 1658714551,
"start": 1656122551
},
"plan": {
"id": "price_1LEOK7HHqepMFuCXktG4Zqlx",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 1000,
"amount_decimal": "1000",
"billing_scheme": "per_unit",
"created": 1656122531,
"currency": "usd",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {},
"nickname": null,
"product": "prod_LwGrKYOmwRvm5l",
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed"
},
"price": {
"id": "price_1LEOK7HHqepMFuCXktG4Zqlx",
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1656122531,
"currency": "usd",
"custom_unit_amount": null,
"livemode": false,
"lookup_key": null,
"metadata": {},
"nickname": null,
"product": "prod_LwGrKYOmwRvm5l",
"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": 1000,
"unit_amount_decimal": "1000"
},
"proration": false,
"proration_details": {
"credited_items": null
},
"quantity": 1,
"subscription": "sub_1LEOKRHHqepMFuCXh4uyrSzm",
"subscription_item": "si_LwGsYhnOZkUaC2",
"tax_amounts": [],
"tax_rates": [],
"type": "subscription",
"unit_amount_excluding_tax": "1000"
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/invoices/in_1LEOKRHHqepMFuCXrE6xJzK5/lines"
},
"livemode": false,
"metadata": {},
"next_payment_attempt": null,
"number": "0EA88130-0001",
"on_behalf_of": null,
"paid": true,
"paid_out_of_band": false,
"payment_intent": "pi_3LEOKRHHqepMFuCX0xEFa3SF",
"payment_settings": {
"payment_method_options": null,
"payment_method_types": null
},
"period_end": 1656122551,
"period_start": 1656122551,
"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": 1656122551,
"marked_uncollectible_at": null,
"paid_at": 1656122551,
"voided_at": null
},
"subscription": "sub_1LEOKRHHqepMFuCXh4uyrSzm",
"subtotal": 1000,
"subtotal_excluding_tax": 1000,
"tax": null,
"test_clock": null,
"total": 1000,
"total_discount_amounts": [],
"total_excluding_tax": 1000,
"total_tax_amounts": [],
"transfer_data": null,
"webhooks_delivered_at": null
},
"customerid": "cus_LwGsrZbWvXucF7",
"subscriptionid": "sub_1LEOKRHHqepMFuCXh4uyrSzm",
"accountid": "acct_906be242e6324efc",
"appid": "tests_1656122530",
"createdAt": "2022-06-25T02:02:34.626Z",
"updatedAt": "2022-06-25T02:02:36.761Z"
},
{
"invoiceid": "in_1LEOKJHHqepMFuCXJ0nfLfku",
"object": "invoice",
"stripeObject": {
"id": "in_1LEOKJHHqepMFuCXJ0nfLfku",
"object": "invoice",
"account_country": "AU",
"account_name": "test-subscriptions",
"account_tax_ids": null,
"amount_due": 1000,
"amount_paid": 1000,
"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_3LEOKKHHqepMFuCX1HYS9YOK",
"collection_method": "charge_automatically",
"created": 1656122543,
"currency": "usd",
"custom_fields": null,
"customer": "cus_LwGs0cH6vA0Z1E",
"customer_address": null,
"customer_email": "Lindsay.Rippin55@yahoo.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_YWNjdF8xS2hpUDhISHFlcE1GdUNYLF9Md0dzSnJNUFJDZEF6TkFNa0NrMkREdVRha0VvclhoLDQ2NjYzMzQ50200JoAbmPlf?s=ap",
"invoice_pdf": "https://pay.stripe.com/invoice/acct_1KhiP8HHqepMFuCX/test_YWNjdF8xS2hpUDhISHFlcE1GdUNYLF9Md0dzSnJNUFJDZEF6TkFNa0NrMkREdVRha0VvclhoLDQ2NjYzMzQ50200JoAbmPlf/pdf?s=ap",
"last_finalization_error": null,
"lines": {
"object": "list",
"data": [
{
"id": "il_1LEOKJHHqepMFuCXrKFRiagk",
"object": "line_item",
"amount": 1000,
"amount_excluding_tax": 1000,
"currency": "usd",
"description": "1 thing × product181 (at $10.00 / month)",
"discount_amounts": [],
"discountable": true,
"discounts": [],
"livemode": false,
"metadata": {},
"period": {
"end": 1658714543,
"start": 1656122543
},
"plan": {
"id": "price_1LEOK7HHqepMFuCXktG4Zqlx",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 1000,
"amount_decimal": "1000",
"billing_scheme": "per_unit",
"created": 1656122531,
"currency": "usd",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {},
"nickname": null,
"product": "prod_LwGrKYOmwRvm5l",
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed"
},
"price": {
"id": "price_1LEOK7HHqepMFuCXktG4Zqlx",
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1656122531,
"currency": "usd",
"custom_unit_amount": null,
"livemode": false,
"lookup_key": null,
"metadata": {},
"nickname": null,
"product": "prod_LwGrKYOmwRvm5l",
"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": 1000,
"unit_amount_decimal": "1000"
},
"proration": false,
"proration_details": {
"credited_items": null
},
"quantity": 1,
"subscription": "sub_1LEOKJHHqepMFuCXV9oFmsMJ",
"subscription_item": "si_LwGspkazaQ99D8",
"tax_amounts": [],
"tax_rates": [],
"type": "subscription",
"unit_amount_excluding_tax": "1000"
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/invoices/in_1LEOKJHHqepMFuCXJ0nfLfku/lines"
},
"livemode": false,
"metadata": {},
"next_payment_attempt": null,
"number": "E44231EB-0001",
"on_behalf_of": null,
"paid": true,
"paid_out_of_band": false,
"payment_intent": "pi_3LEOKKHHqepMFuCX1VQFGpqc",
"payment_settings": {
"payment_method_options": null,
"payment_method_types": null
},
"period_end": 1656122543,
"period_start": 1656122543,
"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": 1656122543,
"marked_uncollectible_at": null,
"paid_at": 1656122543,
"voided_at": null
},
"subscription": "sub_1LEOKJHHqepMFuCXV9oFmsMJ",
"subtotal": 1000,
"subtotal_excluding_tax": 1000,
"tax": null,
"test_clock": null,
"total": 1000,
"total_discount_amounts": [],
"total_excluding_tax": 1000,
"total_tax_amounts": [],
"transfer_data": null,
"webhooks_delivered_at": null
},
"customerid": "cus_LwGs0cH6vA0Z1E",
"subscriptionid": "sub_1LEOKJHHqepMFuCXV9oFmsMJ",
"accountid": "acct_639cb984e3bd206e",
"appid": "tests_1656122530",
"createdAt": "2022-06-25T02:02:27.239Z",
"updatedAt": "2022-06-25T02:02:29.246Z"
}
]
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
}
if (req.query.customerid) {
where.customerid = req.query.customerid
} else if (req.query.accountid) {
where.accountid = req.query.accountid
} else if (req.query.subscriptionid) {
where.subscriptionid = req.query.subscriptionid
}
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.administrator.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/administrator/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 TestStripeAccounts.createOwnerWithPrice()
for (let i = 0, len = global.pageSize + 2; i < len; i++) {
const user = await TestStripeAccounts.createUserWithPaidSubscription(administrator.price)
cachedInvoices.unshift(user.invoice.invoiceid)
}
const req = TestHelper.createRequest('/api/administrator/subscriptions/invoices?offset=1')
req.account = administrator.account
req.session = administrator.session
cachedResponses.offset = await req.get()
const req2 = TestHelper.createRequest('/api/administrator/subscriptions/invoices?limit=1')
req2.account = administrator.account
req2.session = administrator.session
cachedResponses.limit = await req2.get()
const req3 = TestHelper.createRequest('/api/administrator/subscriptions/invoices?all=true')
req3.account = administrator.account
req3.session = administrator.session
cachedResponses.all = await req3.get()
const req4 = TestHelper.createRequest('/api/administrator/subscriptions/invoices')
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 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 stripeAccounts = cachedResponses.returns
assert.strictEqual(stripeAccounts.length, global.pageSize)
})
})
describe('configuration', () => {
it('environment PAGE_SIZE', async () => {
const stripeAccounts = cachedResponses.pageSize
assert.strictEqual(stripeAccounts.length, global.pageSize + 1)
})
})
})