mirror of
https://github.com/jcreek/SvelteKitSaasBoilerplate.git
synced 2026-07-13 11:03:49 +00:00
feat(#76): Add pagination for stripe orders on account page
This commit is contained in:
@@ -590,7 +590,12 @@ const getUserSubscriptions = async (userId: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
const getUserTransactions = async (userId: string) => {
|
||||
const getUserTransactions = async (
|
||||
userId: string,
|
||||
perPage: number,
|
||||
startingAfter: string | undefined = undefined,
|
||||
endingBefore: string | undefined = undefined
|
||||
) => {
|
||||
try {
|
||||
// Step 1: Retrieve the customer ID associated with the user
|
||||
const { data, error } = await supabaseAdmin
|
||||
@@ -610,10 +615,19 @@ const getUserTransactions = async (userId: string) => {
|
||||
}
|
||||
|
||||
// Step 2: Fetch charge transactions from Stripe
|
||||
const charges = await stripeClient.charges.list({ customer: customerId });
|
||||
const params: stripe.ChargeListParams = {
|
||||
customer: customerId,
|
||||
limit: perPage
|
||||
};
|
||||
|
||||
if (startingAfter) params.starting_after = startingAfter;
|
||||
if (endingBefore) params.ending_before = endingBefore;
|
||||
|
||||
const charges = await stripeClient.charges.list(params);
|
||||
|
||||
// Step 3: Format transaction data
|
||||
const transactions = charges.data.map((charge) => ({
|
||||
id: charge.id,
|
||||
amount: (charge.amount / 100).toFixed(2),
|
||||
currency: charge.currency.toUpperCase(),
|
||||
description: charge.description ?? 'No description provided',
|
||||
|
||||
Reference in New Issue
Block a user