Migrate billing from Paddle to Lemon Squeezy

This commit is contained in:
Codex Agent
2026-02-03 10:59:54 +01:00
parent 2f4ebfefd4
commit a0ef90e13a
228 changed files with 4369 additions and 4067 deletions

View File

@@ -6,7 +6,7 @@ import { test, expectFixture as expect } from '../helpers/test-fixtures';
* This suite is currently skipped until we have stable seed data and
* authentication helpers for Playwright. Once those are in place we can
* remove the skip and let the flow exercise the welcome -> packages -> summary
* steps with mocked Paddle APIs.
* steps with mocked Lemon Squeezy APIs.
*/
test.describe('Tenant Onboarding Welcome Flow', () => {
test('redirects unauthenticated users to login', async ({ page }) => {
@@ -47,8 +47,8 @@ test.describe('Tenant Onboarding Welcome Flow', () => {
await expect(page).toHaveURL(/\/event-admin\/mobile\/welcome\/summary/);
await expect(page.getByRole('heading', { name: /Bestellübersicht/i })).toBeVisible();
// Validate Paddle payment section.
await expect(page.getByRole('heading', { name: /^Paddle$/i })).toBeVisible();
// Validate billing CTA is present on summary.
await expect(page.getByRole('button', { name: /Go to billing|Zum Billing|Zu Billing/i })).toBeVisible();
// Continue to the setup step without completing a purchase.
await page.getByRole('button', { name: /Weiter zum Setup/i }).click();

View File

@@ -41,7 +41,7 @@ export type TestingApiFixtures = {
getTestMailbox: () => Promise<MailboxEntry[]>;
seedTestCoupons: (definitions?: CouponSeedDefinition[]) => Promise<Array<{ id: number; code: string }>>;
getLatestCheckoutSession: (filters?: { email?: string; tenantId?: number; status?: string }) => Promise<CheckoutSessionSummary | null>;
simulatePaddleCompletion: (sessionId: string, overrides?: Partial<PaddleSimulationOverrides>) => Promise<void>;
simulateLemonSqueezyCompletion: (sessionId: string, overrides?: Partial<LemonSqueezySimulationOverrides>) => Promise<void>;
fetchJoinToken: (params: { eventId?: number; slug?: string; ensureActive?: boolean }) => Promise<JoinTokenPayload>;
};
@@ -58,9 +58,9 @@ export type CheckoutSessionSummary = {
created_at: string | null;
};
export type PaddleSimulationOverrides = {
export type LemonSqueezySimulationOverrides = {
event_type: string;
transaction_id?: string;
order_id?: string;
status?: string;
checkout_id?: string;
metadata?: Record<string, unknown>;
@@ -156,10 +156,10 @@ export const test = base.extend<TenantAdminFixtures & TestingApiFixtures>({
});
},
simulatePaddleCompletion: async ({ request }, use) => {
await use(async (sessionId: string, overrides?: Partial<PaddleSimulationOverrides>) => {
simulateLemonSqueezyCompletion: async ({ request }, use) => {
await use(async (sessionId: string, overrides?: Partial<LemonSqueezySimulationOverrides>) => {
await expectApiSuccess(
request.post(`/api/_testing/checkout/sessions/${sessionId}/simulate-paddle`, {
request.post(`/api/_testing/checkout/sessions/${sessionId}/simulate-lemonsqueezy`, {
data: overrides,
})
);

View File

@@ -5,29 +5,29 @@ const demoTenantCredentials = {
password: process.env.E2E_DEMO_TENANT_PASSWORD ?? 'Demo1234!',
};
test.describe('Checkout Payment Step Paddle flow', () => {
test('opens Paddle checkout and shows success notice', async ({ page }) => {
await page.route('**/paddle/create-checkout', async (route) => {
test.describe('Checkout Payment Step Lemon Squeezy flow', () => {
test('opens Lemon Squeezy checkout and shows success notice', async ({ page }) => {
await page.route('**/lemonsqueezy/create-checkout', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
checkout_url: 'https://paddle.test/checkout/success',
checkout_url: 'https://fotospiel.lemonsqueezy.com/checkout/success',
}),
});
});
await page.route('https://cdn.paddle.com/paddle/v2/paddle.js', async (route) => {
await page.route('https://app.lemonsqueezy.com/js/lemon.js', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/javascript',
body: `
window.Paddle = {
Environment: { set: function(env) { window.__paddleEnv = env; } },
Initialize: function(opts) { window.__paddleInit = opts; },
Checkout: {
open: function(config) {
window.__paddleOpenConfig = config;
window.createLemonSqueezy = function() {};
window.LemonSqueezy = {
Setup: function(options) { window.__lemonEventHandler = options?.eventHandler || null; },
Url: {
Open: function(url) {
window.__lemonOpenedUrl = url;
}
}
};
@@ -46,7 +46,7 @@ test.describe('Checkout Payment Step Paddle flow', () => {
};
});
await page.getByRole('button', { name: /Continue with Paddle|Weiter mit Paddle/ }).first().click();
await page.getByRole('button', { name: /Continue with Lemon Squeezy|Weiter mit Lemon Squeezy/ }).first().click();
await expect(
page.locator(
@@ -57,7 +57,7 @@ test.describe('Checkout Payment Step Paddle flow', () => {
let mode: 'inline' | 'hosted' | null = null;
for (let i = 0; i < 8; i++) {
const state = await page.evaluate(() => ({
inline: Boolean(window.__paddleOpenConfig),
inline: Boolean(window.__lemonOpenedUrl),
opened: window.__openedUrls?.length ?? 0,
}));
@@ -77,19 +77,19 @@ test.describe('Checkout Payment Step Paddle flow', () => {
expect(mode).not.toBeNull();
if (mode === 'inline') {
const inlineConfig = await page.evaluate(() => window.__paddleOpenConfig ?? null);
expect(inlineConfig).not.toBeNull();
const inlineUrl = await page.evaluate(() => window.__lemonOpenedUrl ?? null);
expect(inlineUrl).not.toBeNull();
}
if (mode === 'hosted') {
await expect.poll(async () => {
return page.evaluate(() => window.__openedUrls?.[0]?.url ?? null);
}).toContain('paddle');
}).toContain('lemonsqueezy');
}
});
test('shows error state when Paddle checkout creation fails', async ({ page }) => {
await page.route('**/paddle/create-checkout', async (route) => {
test('shows error state when Lemon Squeezy checkout creation fails', async ({ page }) => {
await page.route('**/lemonsqueezy/create-checkout', async (route) => {
await route.fulfill({
status: 500,
contentType: 'application/json',
@@ -97,17 +97,17 @@ test.describe('Checkout Payment Step Paddle flow', () => {
});
});
await page.route('https://cdn.paddle.com/paddle/v2/paddle.js', async (route) => {
await page.route('https://app.lemonsqueezy.com/js/lemon.js', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/javascript',
body: `
window.Paddle = {
Environment: { set: function(env) { window.__paddleEnv = env; } },
Initialize: function(opts) { window.__paddleInit = opts; },
Checkout: {
open: function() {
throw new Error('forced paddle failure');
window.createLemonSqueezy = function() {};
window.LemonSqueezy = {
Setup: function(options) { window.__lemonEventHandler = options?.eventHandler || null; },
Url: {
Open: function() {
throw new Error('forced Lemon Squeezy failure');
}
}
};
@@ -118,10 +118,10 @@ test.describe('Checkout Payment Step Paddle flow', () => {
await openCheckoutPaymentStep(page, demoTenantCredentials);
await acceptCheckoutTerms(page);
await page.getByRole('button', { name: /Continue with Paddle|Weiter mit Paddle/ }).first().click();
await page.getByRole('button', { name: /Continue with Lemon Squeezy|Weiter mit Lemon Squeezy/ }).first().click();
await expect(
page.locator('text=/Paddle-Checkout konnte nicht gestartet werden|Paddle checkout could not be started/i')
page.locator('text=/Lemon Squeezy-Checkout konnte nicht gestartet werden|Lemon Squeezy checkout could not be started/i')
).toBeVisible();
});
});
@@ -169,8 +169,7 @@ async function acceptCheckoutTerms(page: import('@playwright/test').Page) {
declare global {
interface Window {
__openedUrls?: Array<{ url: string; target?: string | null; features?: string | null }>;
__paddleOpenConfig?: { url?: string; items?: Array<{ priceId: string; quantity: number }>; settings?: { displayMode?: string } };
__paddleEnv?: string;
__paddleInit?: Record<string, unknown>;
__lemonOpenedUrl?: string | null;
__lemonEventHandler?: ((event: { event: string; data?: unknown }) => void) | null;
}
}

View File

@@ -1,11 +1,11 @@
import { expect, test } from '@playwright/test';
const shouldRun = process.env.E2E_PADDLE_SANDBOX === '1';
const shouldRun = process.env.E2E_LEMONSQUEEZY_SANDBOX === '1' || process.env.E2E_PADDLE_SANDBOX === '1';
test.describe('Paddle sandbox checkout (staging)', () => {
test.skip(!shouldRun, 'Set E2E_PADDLE_SANDBOX=1 to run live sandbox checkout on staging.');
test.describe('Lemon Squeezy sandbox checkout (staging)', () => {
test.skip(!shouldRun, 'Set E2E_LEMONSQUEEZY_SANDBOX=1 to run live sandbox checkout on staging.');
test('creates Paddle checkout session from packages page', async ({ page }) => {
test('creates Lemon Squeezy checkout session from packages page', async ({ page }) => {
const base = process.env.E2E_BASE_URL ?? 'https://test-y0k0.fotospiel.app';
await page.goto(`${base}/packages`);
@@ -23,16 +23,16 @@ test.describe('Paddle sandbox checkout (staging)', () => {
}
const [requestPromise] = await Promise.all([
page.waitForRequest('**/paddle/create-checkout'),
page.waitForRequest('**/lemonsqueezy/create-checkout'),
checkoutButtons.first().click(),
]);
const checkoutRequest = await requestPromise.response();
expect(checkoutRequest, 'Expected paddle/create-checkout request to resolve').toBeTruthy();
expect(checkoutRequest, 'Expected lemonsqueezy/create-checkout request to resolve').toBeTruthy();
expect(checkoutRequest!.status()).toBeLessThan(400);
const body = await checkoutRequest!.json();
const checkoutUrl = body.checkout_url ?? body.url ?? '';
expect(checkoutUrl).toContain('paddle');
expect(checkoutUrl).toContain('lemonsqueezy');
});
});

View File

@@ -3,18 +3,18 @@ import fs from 'node:fs/promises';
import { dismissConsentBanner, expectFixture as expect, test } from '../helpers/test-fixtures';
const shouldRun = process.env.E2E_PADDLE_SANDBOX === '1';
const shouldRun = process.env.E2E_LEMONSQUEEZY_SANDBOX === '1' || process.env.E2E_PADDLE_SANDBOX === '1';
const baseUrl = process.env.E2E_BASE_URL ?? 'https://test-y0k0.fotospiel.app';
const locale = process.env.E2E_LOCALE ?? 'de';
const checkoutSlug = locale === 'en' ? 'checkout' : 'bestellen';
const tenantEmail = buildTenantEmail();
const tenantPassword = process.env.E2E_TENANT_PASSWORD ?? null;
const sandboxCard = {
number: process.env.E2E_PADDLE_CARD_NUMBER ?? '4242 4242 4242 4242',
expiry: process.env.E2E_PADDLE_CARD_EXPIRY ?? '12/34',
cvc: process.env.E2E_PADDLE_CARD_CVC ?? '123',
name: process.env.E2E_PADDLE_CARD_NAME ?? 'Playwright Tester',
postal: process.env.E2E_PADDLE_CARD_POSTAL ?? '10115',
number: process.env.E2E_LEMONSQUEEZY_CARD_NUMBER ?? process.env.E2E_PADDLE_CARD_NUMBER ?? '4242 4242 4242 4242',
expiry: process.env.E2E_LEMONSQUEEZY_CARD_EXPIRY ?? process.env.E2E_PADDLE_CARD_EXPIRY ?? '12/34',
cvc: process.env.E2E_LEMONSQUEEZY_CARD_CVC ?? process.env.E2E_PADDLE_CARD_CVC ?? '123',
name: process.env.E2E_LEMONSQUEEZY_CARD_NAME ?? process.env.E2E_PADDLE_CARD_NAME ?? 'Playwright Tester',
postal: process.env.E2E_LEMONSQUEEZY_CARD_POSTAL ?? process.env.E2E_PADDLE_CARD_POSTAL ?? '10115',
};
test.use({
@@ -27,16 +27,16 @@ test.use({
},
});
test.describe('Paddle sandbox full flow (staging)', () => {
test.skip(!shouldRun, 'Set E2E_PADDLE_SANDBOX=1 to run live sandbox checkout on staging.');
test.describe('Lemon Squeezy sandbox full flow (staging)', () => {
test.skip(!shouldRun, 'Set E2E_LEMONSQUEEZY_SANDBOX=1 to run live sandbox checkout on staging.');
test.skip(!tenantEmail || !tenantPassword, 'Set E2E_TENANT_EMAIL and E2E_TENANT_PASSWORD for sandbox flow.');
test('register, pay via Paddle sandbox, and login to event admin', async ({ page, request }, testInfo) => {
const paddleNetworkLog: string[] = [];
test('register, pay via Lemon Squeezy sandbox, and login to event admin', async ({ page, request }, testInfo) => {
const lemonsqueezyNetworkLog: string[] = [];
page.on('response', async (response) => {
const url = response.url();
if (!/paddle/i.test(url)) {
if (!/lemonsqueezy|lemon/i.test(url)) {
return;
}
@@ -52,9 +52,9 @@ test.describe('Paddle sandbox full flow (staging)', () => {
}
const entry = [`[${status}] ${url}`, bodySnippet].filter(Boolean).join('\n');
paddleNetworkLog.push(entry);
if (paddleNetworkLog.length > 40) {
paddleNetworkLog.shift();
lemonsqueezyNetworkLog.push(entry);
if (lemonsqueezyNetworkLog.length > 40) {
lemonsqueezyNetworkLog.shift();
}
});
@@ -81,11 +81,11 @@ test.describe('Paddle sandbox full flow (staging)', () => {
await expect(termsCheckbox).toBeVisible();
await termsCheckbox.click();
const checkoutCta = page.getByRole('button', { name: /Weiter mit Paddle|Continue with Paddle/i }).first();
const checkoutCta = page.getByRole('button', { name: /Weiter mit Lemon Squeezy|Continue with Lemon Squeezy/i }).first();
await expect(checkoutCta).toBeVisible({ timeout: 20000 });
const [apiResponse] = await Promise.all([
page.waitForResponse((resp) => resp.url().includes('/paddle/create-checkout') && resp.status() < 500),
page.waitForResponse((resp) => resp.url().includes('/lemonsqueezy/create-checkout') && resp.status() < 500),
checkoutCta.click(),
]);
@@ -101,23 +101,23 @@ test.describe('Paddle sandbox full flow (staging)', () => {
const checkoutUrl = extractCheckoutUrl(checkoutPayload, rawBody);
if (!inlineMode) {
expect(checkoutUrl).toContain('paddle');
expect(checkoutUrl).toContain('lemonsqueezy');
}
// Navigate to Paddle hosted checkout and complete payment.
// Navigate to Lemon Squeezy hosted checkout and complete payment.
if (inlineMode) {
await expect(
page.getByText(/Checkout geöffnet|Checkout opened|Paddle-Checkout/i).first()
page.getByText(/Lemon Squeezy|Checkout geöffnet|Checkout opened/i).first()
).toBeVisible({ timeout: 20_000 });
await waitForPaddleCardInputs(page, ['input[autocomplete="cc-number"]', 'input[name="cardnumber"]', 'input[name="card_number"]']);
await waitForLemonCardInputs(page, ['input[autocomplete="cc-number"]', 'input[name="cardnumber"]', 'input[name="card_number"]']);
} else if (checkoutUrl) {
await page.goto(checkoutUrl);
await expect(page).toHaveURL(/paddle/);
await expect(page).toHaveURL(/lemonsqueezy/);
} else {
throw new Error(`Missing Paddle checkout URL. Response: ${rawBody}`);
throw new Error(`Missing Lemon Squeezy checkout URL. Response: ${rawBody}`);
}
await completeHostedPaddleCheckout(page, sandboxCard);
await completeHostedLemonSqueezyCheckout(page, sandboxCard);
await expect
.poll(
@@ -146,10 +146,10 @@ test.describe('Paddle sandbox full flow (staging)', () => {
await expect(page).toHaveURL(/\/event-admin\/mobile\/(dashboard|welcome)/i, { timeout: 30_000 });
await expect(page.getByText(/Dashboard|Willkommen/i)).toBeVisible();
} finally {
if (paddleNetworkLog.length > 0) {
const logPath = testInfo.outputPath('paddle-network-log.txt');
await fs.writeFile(logPath, paddleNetworkLog.join('\n\n'), 'utf8');
await testInfo.attach('paddle-network-log', {
if (lemonsqueezyNetworkLog.length > 0) {
const logPath = testInfo.outputPath('lemonsqueezy-network-log.txt');
await fs.writeFile(logPath, lemonsqueezyNetworkLog.join('\n\n'), 'utf8');
await testInfo.attach('lemonsqueezy-network-log', {
path: logPath,
contentType: 'text/plain',
});
@@ -232,7 +232,7 @@ async function proceedToAccountStep(page: Page, timeoutMs = 30_000): Promise<voi
throw new Error('Account step did not load in time.');
}
async function completeHostedPaddleCheckout(
async function completeHostedLemonSqueezyCheckout(
page: Page,
card: { number: string; expiry: string; cvc: string; name: string; postal: string }
): Promise<void> {
@@ -279,7 +279,7 @@ async function completeHostedPaddleCheckout(
await payButton.click();
}
async function waitForPaddleCardInputs(page: Page, selectors: string[], timeoutMs = 30_000): Promise<void> {
async function waitForLemonCardInputs(page: Page, selectors: string[], timeoutMs = 30_000): Promise<void> {
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
@@ -288,13 +288,13 @@ async function waitForPaddleCardInputs(page: Page, selectors: string[], timeoutM
}
if (await hasAnyText(page, /Something went wrong|try again later/i)) {
throw new Error('Paddle inline checkout returned an error in the iframe.');
throw new Error('Lemon Squeezy inline checkout returned an error in the iframe.');
}
await page.waitForTimeout(500);
}
throw new Error('Paddle card inputs did not appear in time.');
throw new Error('Lemon Squeezy card inputs did not appear in time.');
}
async function hasAnySelector(page: Page, selectors: string[]): Promise<boolean> {
@@ -359,7 +359,7 @@ function extractCheckoutUrl(payload: Record<string, unknown> | null, rawBody: st
}
function buildTenantEmail(): string | null {
const rawEmail = process.env.E2E_TENANT_EMAIL ?? process.env.E2E_PADDLE_EMAIL ?? null;
const rawEmail = process.env.E2E_TENANT_EMAIL ?? process.env.E2E_LEMONSQUEEZY_EMAIL ?? process.env.E2E_PADDLE_EMAIL ?? null;
if (!rawEmail) {
return null;
}

View File

@@ -2,14 +2,14 @@ import { test, expectFixture as expect } from '../helpers/test-fixtures';
const shouldRun = process.env.E2E_TESTING_API === '1';
test.describe('Classic package checkout with Paddle completion', () => {
test.describe('Classic package checkout with Lemon Squeezy completion', () => {
test.skip(!shouldRun, 'Set E2E_TESTING_API=1 to enable checkout tests that use /api/_testing endpoints.');
test('registers, applies coupon, and reaches confirmation', async ({
page,
clearTestMailbox,
seedTestCoupons,
getLatestCheckoutSession,
simulatePaddleCompletion,
simulateLemonSqueezyCompletion,
getTestMailbox,
}) => {
await clearTestMailbox();
@@ -27,23 +27,20 @@ test.describe('Classic package checkout with Paddle completion', () => {
};
});
await page.route('https://cdn.paddle.com/paddle/v2/paddle.js', async (route) => {
await page.route('https://app.lemonsqueezy.com/js/lemon.js', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/javascript',
body: `
window.__paddleEventCallback = null;
window.__paddleInitOptions = null;
window.__paddleCheckoutConfig = null;
window.Paddle = {
Environment: { set() {} },
Initialize(options) {
window.__paddleInitOptions = options;
window.__paddleEventCallback = options?.eventCallback || null;
window.__lemonEventHandler = null;
window.__lemonOpenedUrl = null;
window.LemonSqueezy = {
Setup(options) {
window.__lemonEventHandler = options?.eventHandler || null;
},
Checkout: {
open(config) {
window.__paddleCheckoutConfig = config;
Url: {
Open(url) {
window.__lemonOpenedUrl = url;
},
},
};
@@ -51,14 +48,14 @@ test.describe('Classic package checkout with Paddle completion', () => {
});
});
let paddleRequestPayload: Record<string, unknown> | null = null;
await page.route('**/paddle/create-checkout', async (route) => {
paddleRequestPayload = route.request().postDataJSON() as Record<string, unknown>;
let lemonsqueezyRequestPayload: Record<string, unknown> | null = null;
await page.route('**/lemonsqueezy/create-checkout', async (route) => {
lemonsqueezyRequestPayload = route.request().postDataJSON() as Record<string, unknown>;
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
checkout_url: 'https://sandbox.paddle.test/checkout/abc123',
checkout_url: 'https://fotospiel.lemonsqueezy.com/checkout/abc123',
}),
});
});
@@ -116,12 +113,12 @@ test.describe('Classic package checkout with Paddle completion', () => {
await expect(termsCheckbox).toBeVisible();
await termsCheckbox.click();
await page.getByRole('button', { name: /Weiter mit Paddle|Continue with Paddle/i }).first().click();
await page.getByRole('button', { name: /Weiter mit Lemon Squeezy|Continue with Lemon Squeezy/i }).first().click();
let checkoutMode: 'inline' | 'hosted' | null = null;
for (let i = 0; i < 8; i++) {
const state = await page.evaluate(() => ({
inline: Boolean(window.__paddleCheckoutConfig),
inline: Boolean(window.__lemonOpenedUrl),
opened: window.__openedWindows?.length ?? 0,
}));
@@ -143,11 +140,14 @@ test.describe('Classic package checkout with Paddle completion', () => {
if (checkoutMode === 'hosted') {
await expect.poll(async () => {
return page.evaluate(() => window.__openedWindows?.[0]?.[0] ?? null);
}).toContain('https://sandbox.paddle.test/checkout/abc123');
}).toContain('https://fotospiel.lemonsqueezy.com/checkout/abc123');
}
await page.evaluate(() => {
window.__paddleEventCallback?.({ name: 'checkout.completed' });
window.__lemonEventHandler?.({
event: 'Checkout.Success',
data: { id: 'ord_test', attributes: { checkout_id: 'chk_123' } },
});
});
let session = null;
@@ -160,7 +160,7 @@ test.describe('Classic package checkout with Paddle completion', () => {
}
if (session) {
await simulatePaddleCompletion(session.id);
await simulateLemonSqueezyCompletion(session.id);
for (let i = 0; i < 6; i++) {
const refreshed = await getLatestCheckoutSession({ email });
@@ -179,8 +179,8 @@ test.describe('Classic package checkout with Paddle completion', () => {
page.getByRole('button', { name: /Zum Admin-Bereich|To Admin Area/i })
).toBeVisible();
if (paddleRequestPayload) {
expect(paddleRequestPayload['coupon_code']).toBe('PERCENT10');
if (lemonsqueezyRequestPayload) {
expect(lemonsqueezyRequestPayload['coupon_code']).toBe('PERCENT10');
}
const messages = await getTestMailbox();
@@ -191,8 +191,7 @@ test.describe('Classic package checkout with Paddle completion', () => {
declare global {
interface Window {
__openedWindows?: unknown[];
__paddleEventCallback?: ((event: { name: string }) => void) | null;
__paddleInitOptions?: unknown;
__paddleCheckoutConfig?: unknown;
__lemonEventHandler?: ((event: { event: string; data?: unknown }) => void) | null;
__lemonOpenedUrl?: string | null;
}
}