/api/administrator/subscriptions/payment-intents (GET)
Account information like email addresses is generated with faker-js it is not real user information.
await global.api.administrator.subscriptions.PaymentIntents.get(req)Returns array
[
{
"paymentintentid": "pi_3LEOLZHHqepMFuCX0bjhGF12",
"object": "paymentintent",
"stripeObject": {
"id": "pi_3LEOLZHHqepMFuCX0bjhGF12",
"object": "payment_intent",
"amount": 10000,
"amount_capturable": 0,
"amount_details": {
"tip": {}
},
"amount_received": 0,
"application": null,
"application_fee_amount": null,
"automatic_payment_methods": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic",
"charges": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "/v1/charges?payment_intent=pi_3LEOLZHHqepMFuCX0bjhGF12"
},
"client_secret": "pi_3LEOLZHHqepMFuCX0bjhGF12_secret_KzLmMBsd5OVf8UfeL4fyi3pMI",
"confirmation_method": "automatic",
"created": 1656122621,
"currency": "usd",
"customer": "cus_LwGtrRE7ZX91te",
"description": null,
"invoice": null,
"last_payment_error": null,
"livemode": false,
"metadata": {},
"next_action": null,
"on_behalf_of": null,
"payment_method": null,
"payment_method_options": {
"card": {
"installments": null,
"mandate_options": null,
"network": null,
"request_three_d_secure": "automatic"
}
},
"payment_method_types": [
"card"
],
"processing": null,
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "requires_payment_method",
"transfer_data": null,
"transfer_group": null
},
"accountid": "acct_dd1f553553edae02",
"customerid": "cus_LwGtrRE7ZX91te",
"paymentmethodid": "pm_1LEOLXHHqepMFuCXmCtklolb",
"subscriptionid": null,
"invoiceid": null,
"status": "requires_payment_method",
"appid": "tests_1656122598",
"createdAt": "2022-06-25T02:03:42.153Z",
"updatedAt": "2022-06-25T02:03:42.606Z"
},
{
"paymentintentid": "pi_3LEOLVHHqepMFuCX0tKyAqO1",
"object": "paymentintent",
"stripeObject": {
"id": "pi_3LEOLVHHqepMFuCX0tKyAqO1",
"object": "payment_intent",
"amount": 10000,
"amount_capturable": 0,
"amount_details": {
"tip": {}
},
"amount_received": 0,
"application": null,
"application_fee_amount": null,
"automatic_payment_methods": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic",
"charges": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "/v1/charges?payment_intent=pi_3LEOLVHHqepMFuCX0tKyAqO1"
},
"client_secret": "pi_3LEOLVHHqepMFuCX0tKyAqO1_secret_ClwCh0seKdFAKaRtN8saBWisf",
"confirmation_method": "automatic",
"created": 1656122617,
"currency": "usd",
"customer": "cus_LwGtPb4q8PeMyi",
"description": null,
"invoice": null,
"last_payment_error": null,
"livemode": false,
"metadata": {},
"next_action": null,
"on_behalf_of": null,
"payment_method": null,
"payment_method_options": {
"card": {
"installments": null,
"mandate_options": null,
"network": null,
"request_three_d_secure": "automatic"
}
},
"payment_method_types": [
"card"
],
"processing": null,
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "requires_payment_method",
"transfer_data": null,
"transfer_group": null
},
"accountid": "acct_a4b75f08df7d38ba",
"customerid": "cus_LwGtPb4q8PeMyi",
"paymentmethodid": "pm_1LEOLTHHqepMFuCXldRHTWE0",
"subscriptionid": null,
"invoiceid": null,
"status": "requires_payment_method",
"appid": "tests_1656122598",
"createdAt": "2022-06-25T02:03:38.216Z",
"updatedAt": "2022-06-25T02:03:38.812Z"
},
{
"paymentintentid": "pi_3LEOLRHHqepMFuCX12DaeaON",
"object": "paymentintent",
"stripeObject": {
"id": "pi_3LEOLRHHqepMFuCX12DaeaON",
"object": "payment_intent",
"amount": 10000,
"amount_capturable": 0,
"amount_details": {
"tip": {}
},
"amount_received": 0,
"application": null,
"application_fee_amount": null,
"automatic_payment_methods": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic",
"charges": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "/v1/charges?payment_intent=pi_3LEOLRHHqepMFuCX12DaeaON"
},
"client_secret": "pi_3LEOLRHHqepMFuCX12DaeaON_secret_i56lRPpmvWXmjyK2fhKnVvydv",
"confirmation_method": "automatic",
"created": 1656122613,
"currency": "usd",
"customer": "cus_LwGtOrDxEY7STQ",
"description": null,
"invoice": null,
"last_payment_error": null,
"livemode": false,
"metadata": {},
"next_action": null,
"on_behalf_of": null,
"payment_method": null,
"payment_method_options": {
"card": {
"installments": null,
"mandate_options": null,
"network": null,
"request_three_d_secure": "automatic"
}
},
"payment_method_types": [
"card"
],
"processing": null,
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "requires_payment_method",
"transfer_data": null,
"transfer_group": null
},
"accountid": "acct_e409f5cad479f0f2",
"customerid": "cus_LwGtOrDxEY7STQ",
"paymentmethodid": "pm_1LEOLOHHqepMFuCXY2gfT7v7",
"subscriptionid": null,
"invoiceid": null,
"status": "requires_payment_method",
"appid": "tests_1656122598",
"createdAt": "2022-06-25T02:03:34.115Z",
"updatedAt": "2022-06-25T02:03:34.832Z"
}
]
Receives
API routes may receive parameters from the URL and POST supporting simple and multipart:
Field | Value | Required | Type |
---|---|---|---|
all | boolean | 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 paymentintentids
if (req.query.all) {
paymentintentids = await subscriptions.Storage.PaymentIntent.findAll({
where,
attributes: ['paymentintentid'],
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
paymentintentids = await subscriptions.Storage.PaymentIntent.findAll({
where,
attributes: ['paymentintentid'],
offset,
limit,
order: [
['createdAt', 'DESC']
]
})
}
if (!paymentintentids || !paymentintentids.length) {
return null
}
const items = []
for (const paymentintentInfo of paymentintentids) {
req.query.paymentintentid = paymentintentInfo.dataValues.paymentintentid
const paymentintent = await global.api.administrator.subscriptions.PaymentIntent.get(req)
items.push(paymentintent)
}
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-intents', function () {
before(TestHelper.disableMetrics)
after(TestHelper.enableMetrics)
let cachedResponses, cachedPaymentIntents
async function bundledData (retryNumber) {
if (retryNumber > 0) {
cachedResponses = {}
}
if (cachedResponses && cachedResponses.finished) {
return
}
cachedResponses = {}
cachedPaymentIntents = []
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()
await TestHelper.createPaymentIntent(user, {
paymentmethodid: user.paymentMethod.paymentmethodid,
amount: '10000',
currency: 'usd'
})
cachedPaymentIntents.unshift(user.paymentIntent.paymentintentid)
}
const offset = 1
const limit = 1
const req1 = TestHelper.createRequest(`/api/administrator/subscriptions/payment-intents?offset=${offset}`)
req1.account = administrator.account
req1.session = administrator.session
cachedResponses.offset = await req1.get()
const req2 = TestHelper.createRequest(`/api/administrator/subscriptions/payment-intents?limit=${limit}`)
req2.account = administrator.account
req2.session = administrator.session
cachedResponses.limit = await req2.get()
const req3 = TestHelper.createRequest('/api/administrator/subscriptions/payment-intents?all=true')
req3.account = administrator.account
req3.session = administrator.session
cachedResponses.all = await req3.get()
const req4 = TestHelper.createRequest('/api/administrator/subscriptions/payment-intents')
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 paymentIntentsNow = cachedResponses.offset
for (let i = 0, len = global.pageSize; i < len; i++) {
assert.strictEqual(paymentIntentsNow[i].paymentintentid, cachedPaymentIntents[offset + i])
}
})
it('optional querystring all (boolean)', async () => {
const paymentIntentsNow = cachedResponses.all
assert.strictEqual(paymentIntentsNow.length, cachedPaymentIntents.length)
})
})
describe('returns', () => {
it('array', async () => {
const paymentIntentsNow = cachedResponses.returns
assert.strictEqual(paymentIntentsNow.length, global.pageSize)
})
})
describe('configuration', () => {
it('environment PAGE_SIZE', async () => {
const paymentIntentsNow = cachedResponses.pageSize
assert.strictEqual(paymentIntentsNow.length, global.pageSize + 1)
})
})
})