diff --git a/packages/server/src/api/endpoints/invoice.ts b/packages/server/src/api/endpoints/invoice.ts index 75d818b..ad1c235 100644 --- a/packages/server/src/api/endpoints/invoice.ts +++ b/packages/server/src/api/endpoints/invoice.ts @@ -203,7 +203,7 @@ export async function invoiceEndpoints(server: FastifyInstance): Promise { return reply.code(400).send({ error: 'Missing invoiceId' }); } - const invoice = await database.invoices.findOne({ _id: invoiceId, project }, { populate: ['items'] }); + const invoice = await database.invoices.findOne({ _id: invoiceId, project }, { populate: ['items', 'project'] }); if (!invoice) { return reply.code(404).send({ error: 'Invoice not found' }); } diff --git a/packages/server/src/api/endpoints/payment_method.test.ts b/packages/server/src/api/endpoints/payment_method.test.ts index 4cd6d59..c37162d 100644 --- a/packages/server/src/api/endpoints/payment_method.test.ts +++ b/packages/server/src/api/endpoints/payment_method.test.ts @@ -171,14 +171,13 @@ describe('Payment-method endpoints', () => { const testData = getFixtures(); const paymentMethodData = { - _id: '123', + _id: '1234', type: 'credit-card', name: 'VISA', customer: testData.customer, paymentProviderId: '123', }; - const persistAndFlush = vi.fn(); const removeAndFlush = vi.fn(); vi.spyOn(database, 'database', 'get').mockReturnValue({ @@ -193,7 +192,6 @@ describe('Payment-method endpoints', () => { }, }, em: { - persistAndFlush, removeAndFlush, }, } as unknown as database.Database); @@ -217,7 +215,5 @@ describe('Payment-method endpoints', () => { expect(paymentMethodResponse).toStrictEqual({ ok: true }); expect(removeAndFlush).toBeCalledTimes(1); expect(removeAndFlush).toHaveBeenCalledWith(paymentMethodData); - - expect(persistAndFlush).toBeCalledTimes(1); }); }); diff --git a/packages/server/src/api/endpoints/payment_method.ts b/packages/server/src/api/endpoints/payment_method.ts index f8ed2c6..e167d03 100644 --- a/packages/server/src/api/endpoints/payment_method.ts +++ b/packages/server/src/api/endpoints/payment_method.ts @@ -215,8 +215,7 @@ export async function paymentMethodEndpoints(server: FastifyInstance): Promise { } catch (e) { log.error('Error while invoice charging:', e); invoice.status = 'failed'; + + if (invoice.subscription) { + const { subscription } = invoice; + subscription.status = 'error'; + subscription.error = (e as Error)?.message || (e as string); + await database.em.persistAndFlush([subscription]); + } + await database.em.persistAndFlush([invoice]); } }