We proberen je e-mail binnen 48 uur te beantwoorden.
diff --git a/bun.lock b/bun.lock
index b001ed4..35b55dc 100644
--- a/bun.lock
+++ b/bun.lock
@@ -87,7 +87,6 @@
"@kk/auth": "workspace:*",
"@kk/db": "workspace:*",
"@kk/env": "workspace:*",
- "@lemonsqueezy/lemonsqueezy.js": "^4.00.0",
"@orpc/client": "catalog:",
"@orpc/openapi": "catalog:",
"@orpc/server": "catalog:",
@@ -530,8 +529,6 @@
"@kk/infra": ["@kk/infra@workspace:packages/infra"],
- "@lemonsqueezy/lemonsqueezy.js": ["@lemonsqueezy/lemonsqueezy.js@4.0.0", "", {}, "sha512-xcY1/lDrY7CpIF98WKiL1ElsfoVhddP7FT0fw7ssOzrFqQsr44HgolKrQZxd9SywsCPn12OTOUieqDIokI3mFg=="],
-
"@libsql/client": ["@libsql/client@0.15.15", "", { "dependencies": { "@libsql/core": "^0.15.14", "@libsql/hrana-client": "^0.7.0", "js-base64": "^3.7.5", "libsql": "^0.5.22", "promise-limit": "^2.7.0" } }, "sha512-twC0hQxPNHPKfeOv3sNT6u2pturQjLcI+CnpTM0SjRpocEGgfiZ7DWKXLNnsothjyJmDqEsBQJ5ztq9Wlu470w=="],
"@libsql/core": ["@libsql/core@0.15.15", "", { "dependencies": { "js-base64": "^3.7.5" } }, "sha512-C88Z6UKl+OyuKKPwz224riz02ih/zHYI3Ho/LAcVOgjsunIRZoBw7fjRfaH9oPMmSNeQfhGklSG2il1URoOIsA=="],
diff --git a/packages/api/package.json b/packages/api/package.json
index 262c1d6..348a15d 100644
--- a/packages/api/package.json
+++ b/packages/api/package.json
@@ -14,7 +14,6 @@
"@kk/auth": "workspace:*",
"@kk/db": "workspace:*",
"@kk/env": "workspace:*",
- "@lemonsqueezy/lemonsqueezy.js": "^4.00.0",
"@orpc/client": "catalog:",
"@orpc/openapi": "catalog:",
"@orpc/server": "catalog:",
diff --git a/packages/api/src/routers/drinkkaart.ts b/packages/api/src/routers/drinkkaart.ts
index 6fbf9eb..ed74e24 100644
--- a/packages/api/src/routers/drinkkaart.ts
+++ b/packages/api/src/routers/drinkkaart.ts
@@ -134,82 +134,49 @@ export const drinkkaartRouter = {
.handler(async ({ input, context }) => {
const { env: serverEnv, session } = context;
- if (
- !serverEnv.LEMON_SQUEEZY_API_KEY ||
- !serverEnv.LEMON_SQUEEZY_STORE_ID ||
- !serverEnv.LEMON_SQUEEZY_DRINKKAART_VARIANT_ID
- ) {
+ if (!serverEnv.MOLLIE_API_KEY) {
throw new ORPCError("INTERNAL_SERVER_ERROR", {
- message: "Lemon Squeezy Drinkkaart variant is niet geconfigureerd",
+ message: "Mollie is niet geconfigureerd",
});
}
const card = await getOrCreateDrinkkaart(session.user.id);
- const response = await fetch(
- "https://api.lemonsqueezy.com/v1/checkouts",
- {
- method: "POST",
- headers: {
- Accept: "application/vnd.api+json",
- "Content-Type": "application/vnd.api+json",
- Authorization: `Bearer ${serverEnv.LEMON_SQUEEZY_API_KEY}`,
- },
- body: JSON.stringify({
- data: {
- type: "checkouts",
- attributes: {
- custom_price: input.amountCents,
- product_options: {
- name: "Drinkkaart Opladen",
- description: `Drinkkaart top-up — ${formatCents(input.amountCents)}`,
- redirect_url: `${serverEnv.BETTER_AUTH_URL}/account?topup=success`,
- },
- checkout_data: {
- email: session.user.email,
- name: session.user.name,
- custom: {
- type: "drinkkaart_topup",
- drinkkaartId: card.id,
- userId: session.user.id,
- },
- },
- checkout_options: {
- embed: false,
- locale: "nl",
- },
- },
- relationships: {
- store: {
- data: {
- type: "stores",
- id: serverEnv.LEMON_SQUEEZY_STORE_ID,
- },
- },
- variant: {
- data: {
- type: "variants",
- id: serverEnv.LEMON_SQUEEZY_DRINKKAART_VARIANT_ID,
- },
- },
- },
- },
- }),
+ // Mollie amounts must be formatted as "10.00" (string, 2 decimal places)
+ const amountValue = (input.amountCents / 100).toFixed(2);
+
+ const response = await fetch("https://api.mollie.com/v2/payments", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${serverEnv.MOLLIE_API_KEY}`,
},
- );
+ body: JSON.stringify({
+ amount: { value: amountValue, currency: "EUR" },
+ description: `Drinkkaart Opladen — ${formatCents(input.amountCents)}`,
+ redirectUrl: `${serverEnv.BETTER_AUTH_URL}/account?topup=success`,
+ webhookUrl: `${serverEnv.BETTER_AUTH_URL}/api/webhook/mollie`,
+ locale: "nl_NL",
+ metadata: {
+ type: "drinkkaart_topup",
+ drinkkaartId: card.id,
+ userId: session.user.id,
+ },
+ }),
+ });
if (!response.ok) {
const errorData = await response.json();
- console.error("Lemon Squeezy Drinkkaart checkout error:", errorData);
+ console.error("Mollie Drinkkaart checkout error:", errorData);
throw new ORPCError("INTERNAL_SERVER_ERROR", {
message: "Kon checkout niet aanmaken",
});
}
const data = (await response.json()) as {
- data?: { attributes?: { url?: string } };
+ _links?: { checkout?: { href?: string } };
};
- const checkoutUrl = data.data?.attributes?.url;
+ const checkoutUrl = data._links?.checkout?.href;
if (!checkoutUrl) {
throw new ORPCError("INTERNAL_SERVER_ERROR", {
message: "Geen checkout URL ontvangen",
diff --git a/packages/api/src/routers/index.ts b/packages/api/src/routers/index.ts
index 7badb90..777f895 100644
--- a/packages/api/src/routers/index.ts
+++ b/packages/api/src/routers/index.ts
@@ -50,7 +50,7 @@ function parseGuestsJson(raw: string | null): Array<{
* Credits a watcher's drinkCardValue to their drinkkaart account.
*
* Safe to call multiple times — the `drinkkaartCreditedAt IS NULL` guard and the
- * `lemonsqueezy_order_id` UNIQUE constraint together prevent double-crediting even
+ * `mollie_payment_id` UNIQUE constraint together prevent double-crediting even
* if called concurrently (webhook + signup racing each other).
*
* Returns a status string describing the outcome.
@@ -160,11 +160,11 @@ export async function creditRegistrationToAccount(
return { credited: false, amountCents: 0, status: "already_credited" };
}
- // Record the topup. Re-use the registration's lemonsqueezyOrderId so the
+ // Record the topup. Re-use the registration's molliePaymentId so the
// topup row is clearly linked to the original payment. We prefix with
// "reg_" to distinguish from direct drinkkaart top-up orders if needed.
- const topupOrderId = reg.lemonsqueezyOrderId
- ? `reg_${reg.lemonsqueezyOrderId}`
+ const topupPaymentId = reg.molliePaymentId
+ ? `reg_${reg.molliePaymentId}`
: null;
await db.insert(drinkkaartTopup).values({
@@ -175,8 +175,7 @@ export async function creditRegistrationToAccount(
balanceBefore,
balanceAfter,
type: "payment",
- lemonsqueezyOrderId: topupOrderId,
- lemonsqueezyCustomerId: reg.lemonsqueezyCustomerId ?? null,
+ molliePaymentId: topupPaymentId,
adminId: null,
reason: "Drinkkaart bij registratie",
paidAt: reg.paidAt ?? new Date(),
@@ -742,12 +741,8 @@ export const appRouter = {
}),
)
.handler(async ({ input }) => {
- if (
- !env.LEMON_SQUEEZY_API_KEY ||
- !env.LEMON_SQUEEZY_STORE_ID ||
- !env.LEMON_SQUEEZY_VARIANT_ID
- ) {
- throw new Error("Lemon Squeezy is niet geconfigureerd");
+ if (!env.MOLLIE_API_KEY) {
+ throw new Error("Mollie is niet geconfigureerd");
}
const rows = await db
@@ -797,60 +792,40 @@ export const appRouter = {
? `Vrijwillige gift${drinkCardTotal > 0 ? " + drinkkaart" : ""}`
: `Toegangskaart${giftTotal > 0 ? " + gift" : ""}`;
- const response = await fetch(
- "https://api.lemonsqueezy.com/v1/checkouts",
- {
- method: "POST",
- headers: {
- Accept: "application/vnd.api+json",
- "Content-Type": "application/vnd.api+json",
- Authorization: `Bearer ${env.LEMON_SQUEEZY_API_KEY}`,
- },
- body: JSON.stringify({
- data: {
- type: "checkouts",
- attributes: {
- custom_price: amountInCents,
- product_options: {
- name: "Kunstenkamp Evenement",
- description: productDescription,
- redirect_url:
- input.redirectUrl ??
- `${env.CORS_ORIGIN}/manage/${input.token}`,
- },
- checkout_data: {
- email: row.email,
- name: `${row.firstName} ${row.lastName}`,
- custom: { registration_token: input.token },
- },
- checkout_options: {
- embed: false,
- locale: "nl",
- },
- },
- relationships: {
- store: {
- data: { type: "stores", id: env.LEMON_SQUEEZY_STORE_ID },
- },
- variant: {
- data: { type: "variants", id: env.LEMON_SQUEEZY_VARIANT_ID },
- },
- },
- },
- }),
+ const redirectUrl =
+ input.redirectUrl ?? `${env.CORS_ORIGIN}/manage/${input.token}`;
+
+ // Mollie amounts must be formatted as "10.00" (string, 2 decimal places)
+ const amountValue = (amountInCents / 100).toFixed(2);
+
+ const webhookUrl = `${env.CORS_ORIGIN}/api/webhook/mollie`;
+
+ const response = await fetch("https://api.mollie.com/v2/payments", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${env.MOLLIE_API_KEY}`,
},
- );
+ body: JSON.stringify({
+ amount: { value: amountValue, currency: "EUR" },
+ description: `Kunstenkamp Evenement — ${productDescription}`,
+ redirectUrl,
+ webhookUrl,
+ locale: "nl_NL",
+ metadata: { registration_token: input.token },
+ }),
+ });
if (!response.ok) {
const errorData = await response.json();
- console.error("Lemon Squeezy checkout error:", errorData);
+ console.error("Mollie checkout error:", errorData);
throw new Error("Kon checkout niet aanmaken");
}
const checkoutData = (await response.json()) as {
- data?: { attributes?: { url?: string } };
+ _links?: { checkout?: { href?: string } };
};
- const checkoutUrl = checkoutData.data?.attributes?.url;
+ const checkoutUrl = checkoutData._links?.checkout?.href;
if (!checkoutUrl) throw new Error("Geen checkout URL ontvangen");
diff --git a/packages/db/src/migrations/0006_mollie_migration.sql b/packages/db/src/migrations/0006_mollie_migration.sql
new file mode 100644
index 0000000..8e5123d
--- /dev/null
+++ b/packages/db/src/migrations/0006_mollie_migration.sql
@@ -0,0 +1,17 @@
+-- Migrate from Lemonsqueezy to Mollie
+-- Renames payment provider columns in registration and drinkkaart_topup tables.
+
+-- registration table:
+-- lemonsqueezy_order_id -> mollie_payment_id
+-- lemonsqueezy_customer_id -> dropped (Mollie does not return a persistent
+-- customer ID for one-off payments)
+
+ALTER TABLE registration RENAME COLUMN lemonsqueezy_order_id TO mollie_payment_id;
+ALTER TABLE registration DROP COLUMN lemonsqueezy_customer_id;
+
+-- drinkkaart_topup table:
+-- lemonsqueezy_order_id -> mollie_payment_id
+-- lemonsqueezy_customer_id -> dropped
+
+ALTER TABLE drinkkaart_topup RENAME COLUMN lemonsqueezy_order_id TO mollie_payment_id;
+ALTER TABLE drinkkaart_topup DROP COLUMN lemonsqueezy_customer_id;
diff --git a/packages/db/src/schema/drinkkaart.ts b/packages/db/src/schema/drinkkaart.ts
index 7a323ba..f8c2b04 100644
--- a/packages/db/src/schema/drinkkaart.ts
+++ b/packages/db/src/schema/drinkkaart.ts
@@ -46,8 +46,7 @@ export const drinkkaartTopup = sqliteTable("drinkkaart_topup", {
balanceBefore: integer("balance_before").notNull(),
balanceAfter: integer("balance_after").notNull(),
type: text("type", { enum: ["payment", "admin_credit"] }).notNull(),
- lemonsqueezyOrderId: text("lemonsqueezy_order_id").unique(), // nullable; only for type="payment"
- lemonsqueezyCustomerId: text("lemonsqueezy_customer_id"),
+ molliePaymentId: text("mollie_payment_id").unique(), // nullable; only for type="payment"
adminId: text("admin_id"), // nullable; only for type="admin_credit"
reason: text("reason"),
paidAt: integer("paid_at", { mode: "timestamp_ms" }).notNull(),
diff --git a/packages/db/src/schema/registrations.ts b/packages/db/src/schema/registrations.ts
index 45d5df7..b6d27bf 100644
--- a/packages/db/src/schema/registrations.ts
+++ b/packages/db/src/schema/registrations.ts
@@ -29,8 +29,7 @@ export const registration = sqliteTable(
paymentStatus: text("payment_status").notNull().default("pending"),
paymentAmount: integer("payment_amount").default(0),
giftAmount: integer("gift_amount").default(0),
- lemonsqueezyOrderId: text("lemonsqueezy_order_id"),
- lemonsqueezyCustomerId: text("lemonsqueezy_customer_id"),
+ molliePaymentId: text("mollie_payment_id"),
paidAt: integer("paid_at", { mode: "timestamp_ms" }),
// Set when the drinkCardValue has been credited to the user's drinkkaart.
// Null means not yet credited (either unpaid, account doesn't exist yet, or
@@ -50,6 +49,6 @@ export const registration = sqliteTable(
index("registration_managementToken_idx").on(table.managementToken),
index("registration_paymentStatus_idx").on(table.paymentStatus),
index("registration_giftAmount_idx").on(table.giftAmount),
- index("registration_lemonsqueezyOrderId_idx").on(table.lemonsqueezyOrderId),
+ index("registration_molliePaymentId_idx").on(table.molliePaymentId),
],
);
diff --git a/packages/env/src/server.ts b/packages/env/src/server.ts
index 79861e1..41a3d43 100644
--- a/packages/env/src/server.ts
+++ b/packages/env/src/server.ts
@@ -25,11 +25,7 @@ export const env = createEnv({
NODE_ENV: z
.enum(["development", "production", "test"])
.default("development"),
- LEMON_SQUEEZY_API_KEY: z.string().min(1).optional(),
- LEMON_SQUEEZY_STORE_ID: z.string().min(1).optional(),
- LEMON_SQUEEZY_VARIANT_ID: z.string().min(1).optional(),
- LEMON_SQUEEZY_DRINKKAART_VARIANT_ID: z.string().min(1).optional(),
- LEMON_SQUEEZY_WEBHOOK_SECRET: z.string().min(1).optional(),
+ MOLLIE_API_KEY: z.string().min(1).optional(),
},
runtimeEnv: process.env,
emptyStringAsUndefined: true,
diff --git a/packages/infra/alchemy.run.ts b/packages/infra/alchemy.run.ts
index dcf04e3..87bab0c 100644
--- a/packages/infra/alchemy.run.ts
+++ b/packages/infra/alchemy.run.ts
@@ -30,14 +30,8 @@ export const web = await TanStackStart("web", {
SMTP_USER: getEnvVar("SMTP_USER"),
SMTP_PASS: getEnvVar("SMTP_PASS"),
SMTP_FROM: getEnvVar("SMTP_FROM"),
- // Payments (Lemon Squeezy)
- LEMON_SQUEEZY_API_KEY: getEnvVar("LEMON_SQUEEZY_API_KEY"),
- LEMON_SQUEEZY_STORE_ID: getEnvVar("LEMON_SQUEEZY_STORE_ID"),
- LEMON_SQUEEZY_VARIANT_ID: getEnvVar("LEMON_SQUEEZY_VARIANT_ID"),
- LEMON_SQUEEZY_DRINKKAART_VARIANT_ID: getEnvVar(
- "LEMON_SQUEEZY_DRINKKAART_VARIANT_ID",
- ),
- LEMON_SQUEEZY_WEBHOOK_SECRET: getEnvVar("LEMON_SQUEEZY_WEBHOOK_SECRET"),
+ // Payments (Mollie)
+ MOLLIE_API_KEY: getEnvVar("MOLLIE_API_KEY"),
},
domains: ["kunstenkamp.be", "www.kunstenkamp.be"],
});