diff --git a/packages/api/package.json b/packages/api/package.json index 73ed7f7..c0b3c2e 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -50,9 +50,9 @@ "@fastify/cors": "^9.0.1", "@fastify/middie": "8.3.1", "@fastify/static": "7.0.4", - "@modular-api/api": "^0.4.17", + "@modular-api/api": "^0.4.19", "@modular-api/fastify-cart": "^0.2.4", - "@modular-api/fastify-checkout": "^0.3.7", + "@modular-api/fastify-checkout": "^0.3.9", "@modular-api/fastify-oidc": "^0.5.4", "@mollie/api-client": "^3.7.0", "@slimfact/app": "^0.1.0", diff --git a/packages/api/src/pgboss.ts b/packages/api/src/pgboss.ts index 292783f..11791fe 100644 --- a/packages/api/src/pgboss.ts +++ b/packages/api/src/pgboss.ts @@ -2,6 +2,7 @@ import PgBoss, { Job } from 'pg-boss' import { db, postgresConnectionString } from '../src/kysely/index.js' import { InvoiceStatus, RawNewInvoice } from '@modular-api/fastify-checkout' import { FastifyInstance } from 'fastify' +import { RefundStatus } from '@modular-api/fastify-checkout/types' let boss: PgBoss const createSubscriptionWorker = ({ fastify }: { fastify: FastifyInstance }) => @@ -16,6 +17,27 @@ const createSubscriptionWorker = ({ fastify }: { fastify: FastifyInstance }) => return true } +const createRefundWorker = ({ fastify }: { fastify: FastifyInstance }) => + async function refundWorker() { + const refunds = await db + .selectFrom('checkout.refunds') + .where((web) => + web.or([ + web('status', '=', RefundStatus.PENDING), + web('status', '=', RefundStatus.PROCESSING), + web('status', '=', RefundStatus.QUEUED) + ]) + ) + .select('id') + .execute() + + for (const refund of refunds) { + await fastify.checkout?.paymentHandlers?.mollie?.getRefund({ + id: refund.id + }) + } + } + export const initialize = async ({ fastify }: { fastify: FastifyInstance }) => { boss = new PgBoss(postgresConnectionString) @@ -34,6 +56,21 @@ export const initialize = async ({ fastify }: { fastify: FastifyInstance }) => { subscriptionWorker ) }) + + const refundWorker = createRefundWorker({ fastify }) + await boss.work( + 'checkRefunds', + { batchSize: 1, includeMetadata: true }, + refundWorker + ) + if (!schedules.some((schedule) => schedule.name === 'checkRefunds')) { + const queueName = `checkRefunds` + + if (!(await boss.getQueue(queueName))) { + await boss.createQueue(queueName) + } + await boss.schedule(queueName, '0 0 * * *', {}, {}) + } // await boss.work( // 'subscription:*', // { batchSize: 1, includeMetadata: true }, diff --git a/packages/app/package.json b/packages/app/package.json index 8cc2241..6c5111a 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -44,7 +44,7 @@ "devDependencies": { "@modular-api/fastify-cart": "^0.2.4", "@modular-api/fastify-checkout": "^0.3.3", - "@modular-api/quasar-components": "^0.2.10", + "@modular-api/quasar-components": "^0.2.11", "@quasar/extras": "1.16.11", "@quasar/quasar-ui-qcalendar": "4.0.0-beta.16", "@simsustech/quasar-components": "^0.10.3", diff --git a/packages/app/src/components/invoice/InvoiceExpansionItem.vue b/packages/app/src/components/invoice/InvoiceExpansionItem.vue index a063435..1ede869 100644 --- a/packages/app/src/components/invoice/InvoiceExpansionItem.vue +++ b/packages/app/src/components/invoice/InvoiceExpansionItem.vue @@ -344,6 +344,11 @@ name="payments" :label="lang.payment.payments" /> + @@ -396,6 +401,15 @@ /> + + + + +