mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
stripe
This commit is contained in:
@@ -29,6 +29,7 @@ export default defineEventHandler(async event => {
|
||||
const checkout = await StripeService.cretePayment(
|
||||
price,
|
||||
'https://dashboard.litlyx.com/payment_ok',
|
||||
project_id,
|
||||
project.customer_id
|
||||
);
|
||||
|
||||
@@ -37,9 +38,6 @@ export default defineEventHandler(async event => {
|
||||
return setResponseStatus(event, 400, 'Cannot create payment');
|
||||
}
|
||||
|
||||
const customer = checkout.customer;
|
||||
await ProjectModel.updateOne({ _id: project_id }, { customer_id: customer });
|
||||
|
||||
return checkout.url;
|
||||
|
||||
});
|
||||
37
dashboard/server/api/pay/[project_id]/invoices.ts
Normal file
37
dashboard/server/api/pay/[project_id]/invoices.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { getUserProjectFromId } from "~/server/LIVE_DEMO_DATA";
|
||||
import StripeService from '~/server/services/StripeService';
|
||||
|
||||
|
||||
export type InvoiceData = {
|
||||
date: number,
|
||||
cost: number,
|
||||
id: string,
|
||||
status: string,
|
||||
link: string
|
||||
}
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
const project_id = getRequestProjectId(event);
|
||||
if (!project_id) return;
|
||||
|
||||
const user = getRequestUser(event);
|
||||
const project = await getUserProjectFromId(project_id, user);
|
||||
if (!project) return;
|
||||
|
||||
if (!project.customer_id) return [];
|
||||
|
||||
const invoices = await StripeService.getInvoices(project.customer_id);
|
||||
|
||||
return invoices?.data.map(e => {
|
||||
const result: InvoiceData = {
|
||||
link: e.invoice_pdf || '',
|
||||
id: e.number || '',
|
||||
date: e.created * 1000,
|
||||
status: e.status || 'NO_STATUS',
|
||||
cost: e.amount_due
|
||||
}
|
||||
return result;
|
||||
})
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user