This commit is contained in:
Emily
2024-06-04 15:36:57 +02:00
parent 0427827858
commit c151d558f4
6 changed files with 101 additions and 25 deletions

View File

@@ -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;
});

View 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;
})
});