Update PayPal references and tests
This commit is contained in:
40
tests/Unit/LemonSqueezyClientTest.php
Normal file
40
tests/Unit/LemonSqueezyClientTest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Services\LemonSqueezy\LemonSqueezyClient;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LemonSqueezyClientTest extends TestCase
|
||||
{
|
||||
public function test_base_url_is_normalized_when_missing_scheme(): void
|
||||
{
|
||||
$this->app['config']->set('lemonsqueezy.api_key', 'test-token');
|
||||
$this->app['config']->set('lemonsqueezy.base_url', '/v1');
|
||||
|
||||
Http::fake(function ($request) {
|
||||
$this->assertSame('https://api.lemonsqueezy.com/v1/products', $request->url());
|
||||
|
||||
return Http::response(['data' => []], 200);
|
||||
});
|
||||
|
||||
$client = $this->app->make(LemonSqueezyClient::class);
|
||||
$client->get('/products');
|
||||
}
|
||||
|
||||
public function test_base_url_is_forced_to_api_when_pointing_to_local_host(): void
|
||||
{
|
||||
$this->app['config']->set('lemonsqueezy.api_key', 'test-token');
|
||||
$this->app['config']->set('lemonsqueezy.base_url', 'http://localhost/v1');
|
||||
|
||||
Http::fake(function ($request) {
|
||||
$this->assertSame('https://api.lemonsqueezy.com/v1/products', $request->url());
|
||||
|
||||
return Http::response(['data' => []], 200);
|
||||
});
|
||||
|
||||
$client = $this->app->make(LemonSqueezyClient::class);
|
||||
$client->get('/products');
|
||||
}
|
||||
}
|
||||
@@ -5,31 +5,46 @@ const demoTenantCredentials = {
|
||||
password: process.env.E2E_DEMO_TENANT_PASSWORD ?? 'Demo1234!',
|
||||
};
|
||||
|
||||
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) => {
|
||||
test.describe('Checkout Payment Step - PayPal flow', () => {
|
||||
test('creates PayPal order and completes capture', async ({ page }) => {
|
||||
let createPayload: Record<string, unknown> | null = null;
|
||||
let capturePayload: Record<string, unknown> | null = null;
|
||||
|
||||
await page.route('**/paypal/create-order', async (route) => {
|
||||
createPayload = route.request().postDataJSON() as Record<string, unknown>;
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
checkout_url: 'https://fotospiel.lemonsqueezy.com/checkout/success',
|
||||
order_id: 'order_test_123',
|
||||
checkout_session_id: 'session_test_123',
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('https://app.lemonsqueezy.com/js/lemon.js', async (route) => {
|
||||
await page.route('**/paypal/capture-order', async (route) => {
|
||||
capturePayload = route.request().postDataJSON() as Record<string, unknown>;
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
status: 'completed',
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('https://www.paypal.com/sdk/js**', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/javascript',
|
||||
body: `
|
||||
window.createLemonSqueezy = function() {};
|
||||
window.LemonSqueezy = {
|
||||
Setup: function(options) { window.__lemonEventHandler = options?.eventHandler || null; },
|
||||
Url: {
|
||||
Open: function(url) {
|
||||
window.__lemonOpenedUrl = url;
|
||||
}
|
||||
}
|
||||
window.paypal = {
|
||||
Buttons: function(options) {
|
||||
window.__paypalOptions = options;
|
||||
return {
|
||||
render: function() { return Promise.resolve(); },
|
||||
};
|
||||
},
|
||||
};
|
||||
`,
|
||||
});
|
||||
@@ -38,58 +53,27 @@ test.describe('Checkout Payment Step – Lemon Squeezy flow', () => {
|
||||
await openCheckoutPaymentStep(page, demoTenantCredentials);
|
||||
await acceptCheckoutTerms(page);
|
||||
|
||||
await page.evaluate(() => {
|
||||
window.__openedUrls = [];
|
||||
window.open = (url: string, target?: string | null, features?: string | null) => {
|
||||
window.__openedUrls.push({ url, target: target ?? null, features: features ?? null });
|
||||
return null;
|
||||
};
|
||||
await expect.poll(async () => {
|
||||
return page.evaluate(() => Boolean(window.__paypalOptions));
|
||||
}).toBe(true);
|
||||
|
||||
const orderId = await page.evaluate(async () => {
|
||||
return window.__paypalOptions?.createOrder?.();
|
||||
});
|
||||
|
||||
await page.getByRole('button', { name: /Continue with Lemon Squeezy|Weiter mit Lemon Squeezy/ }).first().click();
|
||||
expect(orderId).toBe('order_test_123');
|
||||
await expect(page.getByText(/PayPal-Checkout ist bereit|PayPal checkout is ready/i)).toBeVisible();
|
||||
|
||||
await expect(
|
||||
page.locator(
|
||||
'text=/secure overlay|Overlay|neuen Tab|new tab/i'
|
||||
)
|
||||
).toBeVisible();
|
||||
await page.evaluate(async () => {
|
||||
await window.__paypalOptions?.onApprove?.({ orderID: 'order_test_123' });
|
||||
});
|
||||
|
||||
let mode: 'inline' | 'hosted' | null = null;
|
||||
for (let i = 0; i < 8; i++) {
|
||||
const state = await page.evaluate(() => ({
|
||||
inline: Boolean(window.__lemonOpenedUrl),
|
||||
opened: window.__openedUrls?.length ?? 0,
|
||||
}));
|
||||
|
||||
if (state.inline) {
|
||||
mode = 'inline';
|
||||
break;
|
||||
}
|
||||
|
||||
if (state.opened > 0) {
|
||||
mode = 'hosted';
|
||||
break;
|
||||
}
|
||||
|
||||
await page.waitForTimeout(300);
|
||||
}
|
||||
|
||||
expect(mode).not.toBeNull();
|
||||
|
||||
if (mode === 'inline') {
|
||||
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('lemonsqueezy');
|
||||
}
|
||||
expect(createPayload?.package_id).toBeDefined();
|
||||
expect(capturePayload?.order_id).toBe('order_test_123');
|
||||
});
|
||||
|
||||
test('shows error state when Lemon Squeezy checkout creation fails', async ({ page }) => {
|
||||
await page.route('**/lemonsqueezy/create-checkout', async (route) => {
|
||||
test('shows error state when PayPal checkout creation fails', async ({ page }) => {
|
||||
await page.route('**/paypal/create-order', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 500,
|
||||
contentType: 'application/json',
|
||||
@@ -97,19 +81,18 @@ test.describe('Checkout Payment Step – Lemon Squeezy flow', () => {
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('https://app.lemonsqueezy.com/js/lemon.js', async (route) => {
|
||||
await page.route('https://www.paypal.com/sdk/js**', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/javascript',
|
||||
body: `
|
||||
window.createLemonSqueezy = function() {};
|
||||
window.LemonSqueezy = {
|
||||
Setup: function(options) { window.__lemonEventHandler = options?.eventHandler || null; },
|
||||
Url: {
|
||||
Open: function() {
|
||||
throw new Error('forced Lemon Squeezy failure');
|
||||
}
|
||||
}
|
||||
window.paypal = {
|
||||
Buttons: function(options) {
|
||||
window.__paypalOptions = options;
|
||||
return {
|
||||
render: function() { return Promise.resolve(); },
|
||||
};
|
||||
},
|
||||
};
|
||||
`,
|
||||
});
|
||||
@@ -118,10 +101,20 @@ test.describe('Checkout Payment Step – Lemon Squeezy flow', () => {
|
||||
await openCheckoutPaymentStep(page, demoTenantCredentials);
|
||||
await acceptCheckoutTerms(page);
|
||||
|
||||
await page.getByRole('button', { name: /Continue with Lemon Squeezy|Weiter mit Lemon Squeezy/ }).first().click();
|
||||
await expect.poll(async () => {
|
||||
return page.evaluate(() => Boolean(window.__paypalOptions));
|
||||
}).toBe(true);
|
||||
|
||||
await page.evaluate(async () => {
|
||||
try {
|
||||
await window.__paypalOptions?.createOrder?.();
|
||||
} catch {
|
||||
// swallow error for assertion below
|
||||
}
|
||||
});
|
||||
|
||||
await expect(
|
||||
page.locator('text=/Lemon Squeezy-Checkout konnte nicht gestartet werden|Lemon Squeezy checkout could not be started/i')
|
||||
page.locator('text=/PayPal-Checkout konnte nicht gestartet werden|PayPal checkout could not be started/i')
|
||||
).toBeVisible();
|
||||
});
|
||||
});
|
||||
@@ -168,8 +161,9 @@ async function acceptCheckoutTerms(page: import('@playwright/test').Page) {
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
__openedUrls?: Array<{ url: string; target?: string | null; features?: string | null }>;
|
||||
__lemonOpenedUrl?: string | null;
|
||||
__lemonEventHandler?: ((event: { event: string; data?: unknown }) => void) | null;
|
||||
__paypalOptions?: {
|
||||
createOrder?: () => Promise<string>;
|
||||
onApprove?: (data: { orderID: string }) => Promise<void>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
const shouldRun = process.env.E2E_LEMONSQUEEZY_SANDBOX === '1' || process.env.E2E_PADDLE_SANDBOX === '1';
|
||||
|
||||
test.describe('Lemon Squeezy sandbox checkout (staging)', () => {
|
||||
test.skip(!shouldRun, 'Set E2E_LEMONSQUEEZY_SANDBOX=1 to run live sandbox checkout on staging.');
|
||||
|
||||
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`);
|
||||
|
||||
const acceptCookies = page.getByRole('button', { name: /akzeptieren|accept/i });
|
||||
if (await acceptCookies.isVisible()) {
|
||||
await acceptCookies.click();
|
||||
}
|
||||
|
||||
const checkoutButtons = page.locator('a:has-text("Paket") , a:has-text("Checkout"), a:has-text("Jetzt"), button:has-text("Checkout")');
|
||||
const count = await checkoutButtons.count();
|
||||
|
||||
if (count === 0) {
|
||||
test.skip('No checkout CTA found on packages page');
|
||||
}
|
||||
|
||||
const [requestPromise] = await Promise.all([
|
||||
page.waitForRequest('**/lemonsqueezy/create-checkout'),
|
||||
checkoutButtons.first().click(),
|
||||
]);
|
||||
|
||||
const checkoutRequest = await requestPromise.response();
|
||||
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('lemonsqueezy');
|
||||
});
|
||||
});
|
||||
@@ -1,433 +0,0 @@
|
||||
import type { Page } from '@playwright/test';
|
||||
import fs from 'node:fs/promises';
|
||||
|
||||
import { dismissConsentBanner, expectFixture as expect, test } from '../helpers/test-fixtures';
|
||||
|
||||
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_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({
|
||||
channel: process.env.E2E_BROWSER_CHANNEL ?? 'chrome',
|
||||
userAgent:
|
||||
process.env.E2E_USER_AGENT ??
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
|
||||
launchOptions: {
|
||||
args: ['--disable-blink-features=AutomationControlled'],
|
||||
},
|
||||
});
|
||||
|
||||
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 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 (!/lemonsqueezy|lemon/i.test(url)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const status = response.status();
|
||||
let bodySnippet = '';
|
||||
if (status >= 400 || /checkout|error/i.test(url)) {
|
||||
try {
|
||||
const text = await response.text();
|
||||
bodySnippet = text.trim().slice(0, 2000);
|
||||
} catch {
|
||||
bodySnippet = '';
|
||||
}
|
||||
}
|
||||
|
||||
const entry = [`[${status}] ${url}`, bodySnippet].filter(Boolean).join('\n');
|
||||
lemonsqueezyNetworkLog.push(entry);
|
||||
if (lemonsqueezyNetworkLog.length > 40) {
|
||||
lemonsqueezyNetworkLog.shift();
|
||||
}
|
||||
});
|
||||
|
||||
await page.addInitScript(() => {
|
||||
Object.defineProperty(navigator, 'webdriver', {
|
||||
get: () => undefined,
|
||||
});
|
||||
});
|
||||
|
||||
try {
|
||||
// Jump directly into wizard for Classic package (2)
|
||||
await page.goto(`${baseUrl}/${locale}/${checkoutSlug}/2`);
|
||||
|
||||
await dismissConsentBanner(page);
|
||||
|
||||
await proceedToAccountStep(page);
|
||||
|
||||
await completeRegistrationOrLogin(page, {
|
||||
email: tenantEmail!,
|
||||
password: tenantPassword!,
|
||||
});
|
||||
|
||||
const termsCheckbox = page.locator('#checkout-terms-hero');
|
||||
await expect(termsCheckbox).toBeVisible();
|
||||
await termsCheckbox.click();
|
||||
|
||||
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('/lemonsqueezy/create-checkout') && resp.status() < 500),
|
||||
checkoutCta.click(),
|
||||
]);
|
||||
|
||||
const rawBody = await apiResponse.text();
|
||||
let checkoutPayload: Record<string, unknown> | null = null;
|
||||
try {
|
||||
checkoutPayload = rawBody && rawBody.trim().startsWith('{') ? JSON.parse(rawBody) : null;
|
||||
} catch {
|
||||
checkoutPayload = null;
|
||||
}
|
||||
|
||||
const inlineMode = checkoutPayload?.mode === 'inline' || checkoutPayload?.inline === true;
|
||||
const checkoutUrl = extractCheckoutUrl(checkoutPayload, rawBody);
|
||||
|
||||
if (!inlineMode) {
|
||||
expect(checkoutUrl).toContain('lemonsqueezy');
|
||||
}
|
||||
|
||||
// Navigate to Lemon Squeezy hosted checkout and complete payment.
|
||||
if (inlineMode) {
|
||||
await expect(
|
||||
page.getByText(/Lemon Squeezy|Checkout geöffnet|Checkout opened/i).first()
|
||||
).toBeVisible({ timeout: 20_000 });
|
||||
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(/lemonsqueezy/);
|
||||
} else {
|
||||
throw new Error(`Missing Lemon Squeezy checkout URL. Response: ${rawBody}`);
|
||||
}
|
||||
|
||||
await completeHostedLemonSqueezyCheckout(page, sandboxCard);
|
||||
|
||||
await expect
|
||||
.poll(
|
||||
async () => {
|
||||
const latestCompleted = await request.get('/api/_testing/checkout/sessions/latest', {
|
||||
params: { status: 'completed', email: tenantEmail },
|
||||
});
|
||||
if (!latestCompleted.ok()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const json = await latestCompleted.json();
|
||||
return json?.data?.status ?? null;
|
||||
},
|
||||
{ timeout: 120_000 }
|
||||
)
|
||||
.toBe('completed');
|
||||
|
||||
await page.goto(`${baseUrl}/event-admin/login`);
|
||||
await dismissConsentBanner(page);
|
||||
|
||||
await page.locator('input[name="identifier"]').fill(tenantEmail!);
|
||||
await page.locator('input[name="password"]').fill(tenantPassword!);
|
||||
await page.getByRole('button', { name: /Anmelden|Login/i }).click();
|
||||
|
||||
await expect(page).toHaveURL(/\/event-admin\/mobile\/(dashboard|welcome)/i, { timeout: 30_000 });
|
||||
await expect(page.getByText(/Dashboard|Willkommen/i)).toBeVisible();
|
||||
} finally {
|
||||
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',
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
async function completeRegistrationOrLogin(page: Page, credentials: { email: string; password: string }): Promise<void> {
|
||||
const identifierInput = page.locator('input[name="identifier"]');
|
||||
if (await identifierInput.isVisible()) {
|
||||
await identifierInput.fill(credentials.email);
|
||||
await page.locator('input[name="password"]').fill(credentials.password);
|
||||
await page.getByRole('button', { name: /^Anmelden$|Login/i }).last().click();
|
||||
await expect(page.getByPlaceholder(/Gutscheincode|Coupon/i)).toBeVisible({ timeout: 20_000 });
|
||||
return;
|
||||
}
|
||||
|
||||
await page.fill('input[name="first_name"]', 'Play');
|
||||
await page.fill('input[name="last_name"]', 'Wright');
|
||||
await page.fill('input[name="email"]', credentials.email);
|
||||
const addressInput = page.locator('input[name="address"]');
|
||||
if (await addressInput.isVisible()) {
|
||||
await addressInput.fill('Teststrasse 1, 12345 Berlin');
|
||||
}
|
||||
|
||||
const phoneInput = page.locator('input[name="phone"]');
|
||||
if (await phoneInput.isVisible()) {
|
||||
await phoneInput.fill('+49123456789');
|
||||
}
|
||||
|
||||
const usernameInput = page.locator('input[name="username"]');
|
||||
if (await usernameInput.isVisible()) {
|
||||
await usernameInput.fill(credentials.email);
|
||||
}
|
||||
await page.fill('input[name="password"]', credentials.password);
|
||||
await page.fill('input[name="password_confirmation"]', credentials.password);
|
||||
|
||||
await page.check('input[name="privacy_consent"]');
|
||||
await page.getByRole('button', { name: /Registrieren|Register/i }).last().click();
|
||||
|
||||
try {
|
||||
await expect(page.getByPlaceholder(/Gutscheincode|Coupon/i)).toBeVisible({ timeout: 20_000 });
|
||||
return;
|
||||
} catch {
|
||||
const loginButton = page.getByRole('button', { name: /^Anmelden$|Login/i }).first();
|
||||
if (await loginButton.isVisible()) {
|
||||
await loginButton.click();
|
||||
}
|
||||
}
|
||||
|
||||
await expect(page.locator('input[name="identifier"]')).toBeVisible({ timeout: 10_000 });
|
||||
await page.locator('input[name="identifier"]').fill(credentials.email);
|
||||
await page.locator('input[name="password"]').fill(credentials.password);
|
||||
await page.getByRole('button', { name: /^Anmelden$|Login/i }).last().click();
|
||||
await expect(page.getByPlaceholder(/Gutscheincode|Coupon/i)).toBeVisible({ timeout: 20_000 });
|
||||
}
|
||||
|
||||
async function proceedToAccountStep(page: Page, timeoutMs = 30_000): Promise<void> {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
|
||||
while (Date.now() < deadline) {
|
||||
const accountForm = page.locator('input[name="first_name"], input[name="identifier"]');
|
||||
if (await accountForm.isVisible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
await dismissConsentBanner(page);
|
||||
|
||||
const continueButton = page.getByRole('button', { name: /Weiter|Continue/i }).first();
|
||||
if (await continueButton.isVisible()) {
|
||||
if (await continueButton.isEnabled()) {
|
||||
await continueButton.click();
|
||||
}
|
||||
}
|
||||
|
||||
await page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
throw new Error('Account step did not load in time.');
|
||||
}
|
||||
|
||||
async function completeHostedLemonSqueezyCheckout(
|
||||
page: Page,
|
||||
card: { number: string; expiry: string; cvc: string; name: string; postal: string }
|
||||
): Promise<void> {
|
||||
const cardNumberSelectors = [
|
||||
'input[autocomplete="cc-number"]',
|
||||
'input[name="cardnumber"]',
|
||||
'input[name="card_number"]',
|
||||
];
|
||||
const expirySelectors = [
|
||||
'input[autocomplete="cc-exp"]',
|
||||
'input[name="exp-date"]',
|
||||
'input[name="exp_date"]',
|
||||
'input[name="expiry"]',
|
||||
];
|
||||
const cvcSelectors = [
|
||||
'input[autocomplete="cc-csc"]',
|
||||
'input[name="cvc"]',
|
||||
'input[name="security-code"]',
|
||||
'input[name="cvv"]',
|
||||
];
|
||||
const nameSelectors = [
|
||||
'input[autocomplete="cc-name"]',
|
||||
'input[name="cardholder"]',
|
||||
'input[name="cardholder_name"]',
|
||||
'input[name="cardholder-name"]',
|
||||
];
|
||||
const postalSelectors = [
|
||||
'input[autocomplete="postal-code"]',
|
||||
'input[name="postal"]',
|
||||
'input[name="postal_code"]',
|
||||
'input[name="zip"]',
|
||||
];
|
||||
|
||||
await maybeFillInAnyFrame(page, nameSelectors, card.name);
|
||||
await fillInAnyFrame(page, cardNumberSelectors, card.number);
|
||||
await fillInAnyFrame(page, expirySelectors, card.expiry);
|
||||
await fillInAnyFrame(page, cvcSelectors, card.cvc);
|
||||
await maybeFillInAnyFrame(page, postalSelectors, card.postal);
|
||||
|
||||
const payButton = page.getByRole('button', {
|
||||
name: /Jetzt bezahlen|Pay now|Complete order|Order now|Kaufen|Bezahlen|Zahlung abschließen/i,
|
||||
}).first();
|
||||
await expect(payButton).toBeVisible({ timeout: 20_000 });
|
||||
await payButton.click();
|
||||
}
|
||||
|
||||
async function waitForLemonCardInputs(page: Page, selectors: string[], timeoutMs = 30_000): Promise<void> {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
|
||||
while (Date.now() < deadline) {
|
||||
if (await hasAnySelector(page, selectors)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await hasAnyText(page, /Something went wrong|try again later/i)) {
|
||||
throw new Error('Lemon Squeezy inline checkout returned an error in the iframe.');
|
||||
}
|
||||
|
||||
await page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
throw new Error('Lemon Squeezy card inputs did not appear in time.');
|
||||
}
|
||||
|
||||
async function hasAnySelector(page: Page, selectors: string[]): Promise<boolean> {
|
||||
if (await hasSelectorInFrame(page, selectors)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (const frame of page.frames()) {
|
||||
if (await hasSelectorInFrame(frame, selectors)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async function hasSelectorInFrame(scope: Page | import('@playwright/test').Frame, selectors: string[]): Promise<boolean> {
|
||||
for (const selector of selectors) {
|
||||
if ((await scope.locator(selector).count()) > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async function hasAnyText(page: Page, matcher: RegExp): Promise<boolean> {
|
||||
if ((await page.getByText(matcher).count()) > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (const frame of page.frames()) {
|
||||
if ((await frame.getByText(matcher).count()) > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function extractCheckoutUrl(payload: Record<string, unknown> | null, rawBody: string): string | null {
|
||||
if (payload) {
|
||||
const directUrl = payload.checkout_url ?? payload.url ?? payload.checkoutUrl;
|
||||
if (typeof directUrl === 'string') {
|
||||
return directUrl;
|
||||
}
|
||||
}
|
||||
|
||||
const trimmed = rawBody.trim();
|
||||
if (/^https?:\/\//i.test(trimmed)) {
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
if (trimmed.startsWith('<')) {
|
||||
const match = trimmed.match(/https?:\/\/["'a-zA-Z0-9._~:/?#@!$&'()*+,;=%-]+/);
|
||||
if (match) {
|
||||
return match[0];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function buildTenantEmail(): string | null {
|
||||
const rawEmail = process.env.E2E_TENANT_EMAIL ?? process.env.E2E_LEMONSQUEEZY_EMAIL ?? process.env.E2E_PADDLE_EMAIL ?? null;
|
||||
if (!rawEmail) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!rawEmail.includes('{timestamp}')) {
|
||||
return rawEmail;
|
||||
}
|
||||
|
||||
const timestamp = Math.floor(Date.now() / 1000).toString();
|
||||
return rawEmail.replaceAll('{timestamp}', timestamp);
|
||||
}
|
||||
|
||||
async function fillInAnyFrame(page: Page, selectors: string[], value: string): Promise<void> {
|
||||
const filled = await attemptFill(page, selectors, value);
|
||||
if (filled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const frames = page.frames();
|
||||
for (const frame of frames) {
|
||||
const frameFilled = await attemptFill(frame, selectors, value);
|
||||
if (frameFilled) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(`Unable to find input for selectors: ${selectors.join(', ')}`);
|
||||
}
|
||||
|
||||
async function maybeFillInAnyFrame(page: Page, selectors: string[], value: string): Promise<void> {
|
||||
const filled = await attemptFill(page, selectors, value);
|
||||
if (filled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const frames = page.frames();
|
||||
for (const frame of frames) {
|
||||
const frameFilled = await attemptFill(frame, selectors, value);
|
||||
if (frameFilled) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function attemptFill(
|
||||
scope: Page | import('@playwright/test').Frame,
|
||||
selectors: string[],
|
||||
value: string
|
||||
): Promise<boolean> {
|
||||
for (const selector of selectors) {
|
||||
const locator = scope.locator(selector).first();
|
||||
if ((await locator.count()) === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
await locator.fill(value);
|
||||
return true;
|
||||
} catch {
|
||||
try {
|
||||
await locator.click();
|
||||
await locator.type(value, { delay: 25 });
|
||||
return true;
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
109
tests/ui/purchase/paypal-sandbox-checkout.test.ts
Normal file
109
tests/ui/purchase/paypal-sandbox-checkout.test.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
const shouldRun =
|
||||
process.env.E2E_PAYPAL_SANDBOX === '1' ||
|
||||
process.env.E2E_LEMONSQUEEZY_SANDBOX === '1' ||
|
||||
process.env.E2E_PADDLE_SANDBOX === '1';
|
||||
|
||||
const base = 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 = process.env.E2E_TENANT_EMAIL ?? null;
|
||||
const tenantPassword = process.env.E2E_TENANT_PASSWORD ?? null;
|
||||
|
||||
test.describe('PayPal sandbox checkout (staging)', () => {
|
||||
test.skip(!shouldRun, 'Set E2E_PAYPAL_SANDBOX=1 to run sandbox checkout on staging.');
|
||||
test.skip(!tenantEmail || !tenantPassword, 'Set E2E_TENANT_EMAIL and E2E_TENANT_PASSWORD for sandbox flow.');
|
||||
|
||||
test('creates PayPal order from the checkout wizard', async ({ page }) => {
|
||||
await page.route('https://www.paypal.com/sdk/js**', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/javascript',
|
||||
body: `
|
||||
window.paypal = {
|
||||
Buttons: function(options) {
|
||||
window.__paypalOptions = options;
|
||||
return {
|
||||
render: function() { return Promise.resolve(); },
|
||||
};
|
||||
},
|
||||
};
|
||||
`,
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('**/paypal/create-order', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
order_id: 'order_test_123',
|
||||
checkout_session_id: 'session_test_123',
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
await page.goto(`${base}/${locale}/${checkoutSlug}/2`);
|
||||
|
||||
await proceedToAccountStep(page);
|
||||
await login(page, { email: tenantEmail!, password: tenantPassword! });
|
||||
|
||||
const termsCheckbox = page.locator('#checkout-terms-hero');
|
||||
await expect(termsCheckbox).toBeVisible();
|
||||
await termsCheckbox.click();
|
||||
|
||||
await expect.poll(async () => {
|
||||
return page.evaluate(() => Boolean(window.__paypalOptions));
|
||||
}).toBe(true);
|
||||
|
||||
const orderId = await page.evaluate(async () => {
|
||||
return window.__paypalOptions?.createOrder?.();
|
||||
});
|
||||
|
||||
expect(orderId).toBe('order_test_123');
|
||||
});
|
||||
});
|
||||
|
||||
async function proceedToAccountStep(page: import('@playwright/test').Page, timeoutMs = 30_000): Promise<void> {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
|
||||
while (Date.now() < deadline) {
|
||||
const accountForm = page.locator('input[name="first_name"], input[name="identifier"]');
|
||||
if (await accountForm.isVisible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const continueButton = page.getByRole('button', { name: /Weiter|Continue/i }).first();
|
||||
if (await continueButton.isVisible()) {
|
||||
if (await continueButton.isEnabled()) {
|
||||
await continueButton.click();
|
||||
}
|
||||
}
|
||||
|
||||
await page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
throw new Error('Account step did not load in time.');
|
||||
}
|
||||
|
||||
async function login(page: import('@playwright/test').Page, credentials: { email: string; password: string }) {
|
||||
const identifierInput = page.locator('input[name="identifier"]');
|
||||
if (!(await identifierInput.isVisible())) {
|
||||
return;
|
||||
}
|
||||
|
||||
await identifierInput.fill(credentials.email);
|
||||
await page.locator('input[name="password"]').fill(credentials.password);
|
||||
await page.getByRole('button', { name: /^Anmelden$|Login/i }).last().click();
|
||||
|
||||
await expect(page.getByPlaceholder(/Gutscheincode|Coupon/i)).toBeVisible({ timeout: 20_000 });
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
__paypalOptions?: {
|
||||
createOrder?: () => Promise<string>;
|
||||
};
|
||||
}
|
||||
}
|
||||
248
tests/ui/purchase/paypal-sandbox-full.test.ts
Normal file
248
tests/ui/purchase/paypal-sandbox-full.test.ts
Normal file
@@ -0,0 +1,248 @@
|
||||
import type { Page } from '@playwright/test';
|
||||
import fs from 'node:fs/promises';
|
||||
|
||||
import { dismissConsentBanner, expectFixture as expect, test } from '../helpers/test-fixtures';
|
||||
|
||||
const shouldRun =
|
||||
process.env.E2E_PAYPAL_SANDBOX === '1' ||
|
||||
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;
|
||||
|
||||
test.use({
|
||||
channel: process.env.E2E_BROWSER_CHANNEL ?? 'chrome',
|
||||
userAgent:
|
||||
process.env.E2E_USER_AGENT ??
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
|
||||
launchOptions: {
|
||||
args: ['--disable-blink-features=AutomationControlled'],
|
||||
},
|
||||
});
|
||||
|
||||
test.describe('PayPal sandbox full flow (staging)', () => {
|
||||
test.skip(!shouldRun, 'Set E2E_PAYPAL_SANDBOX=1 to run sandbox checkout on staging.');
|
||||
test.skip(!tenantEmail || !tenantPassword, 'Set E2E_TENANT_EMAIL and E2E_TENANT_PASSWORD for sandbox flow.');
|
||||
|
||||
test('register, simulate PayPal completion, and login to event admin', async ({ page }, testInfo) => {
|
||||
const paypalNetworkLog: string[] = [];
|
||||
|
||||
page.on('response', async (response) => {
|
||||
const url = response.url();
|
||||
if (!/paypal/i.test(url)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const status = response.status();
|
||||
let bodySnippet = '';
|
||||
if (status >= 400 || /checkout|error/i.test(url)) {
|
||||
try {
|
||||
const text = await response.text();
|
||||
bodySnippet = text.trim().slice(0, 2000);
|
||||
} catch {
|
||||
bodySnippet = '';
|
||||
}
|
||||
}
|
||||
|
||||
const entry = [`[${status}] ${url}`, bodySnippet].filter(Boolean).join('
|
||||
');
|
||||
paypalNetworkLog.push(entry);
|
||||
if (paypalNetworkLog.length > 40) {
|
||||
paypalNetworkLog.shift();
|
||||
}
|
||||
});
|
||||
|
||||
await page.addInitScript(() => {
|
||||
Object.defineProperty(navigator, 'webdriver', {
|
||||
get: () => undefined,
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('https://www.paypal.com/sdk/js**', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/javascript',
|
||||
body: `
|
||||
window.paypal = {
|
||||
Buttons: function(options) {
|
||||
window.__paypalOptions = options;
|
||||
return {
|
||||
render: function() { return Promise.resolve(); },
|
||||
};
|
||||
},
|
||||
};
|
||||
`,
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('**/paypal/create-order', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
order_id: 'order_test_123',
|
||||
checkout_session_id: 'session_test_123',
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('**/paypal/capture-order', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
status: 'completed',
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
try {
|
||||
await page.goto(`${baseUrl}/${locale}/${checkoutSlug}/2`);
|
||||
|
||||
await dismissConsentBanner(page);
|
||||
|
||||
await proceedToAccountStep(page);
|
||||
|
||||
await completeRegistrationOrLogin(page, {
|
||||
email: tenantEmail!,
|
||||
password: tenantPassword!,
|
||||
});
|
||||
|
||||
const termsCheckbox = page.locator('#checkout-terms-hero');
|
||||
await expect(termsCheckbox).toBeVisible();
|
||||
await termsCheckbox.click();
|
||||
|
||||
await expect.poll(async () => {
|
||||
return page.evaluate(() => Boolean(window.__paypalOptions));
|
||||
}).toBe(true);
|
||||
|
||||
await page.evaluate(async () => {
|
||||
await window.__paypalOptions?.createOrder?.();
|
||||
await window.__paypalOptions?.onApprove?.({ orderID: 'order_test_123' });
|
||||
});
|
||||
|
||||
await expect(page.getByText(/Marketing-Dashboard/)).toBeVisible();
|
||||
|
||||
await page.goto(`${baseUrl}/event-admin/login`);
|
||||
await dismissConsentBanner(page);
|
||||
|
||||
await page.locator('input[name="identifier"]').fill(tenantEmail!);
|
||||
await page.locator('input[name="password"]').fill(tenantPassword!);
|
||||
await page.getByRole('button', { name: /Anmelden|Login/i }).click();
|
||||
|
||||
await expect(page).toHaveURL(/\/event-admin\/mobile\/(dashboard|welcome)/i, { timeout: 30_000 });
|
||||
await expect(page.getByText(/Dashboard|Willkommen/i)).toBeVisible();
|
||||
} finally {
|
||||
if (paypalNetworkLog.length > 0) {
|
||||
const logPath = testInfo.outputPath('paypal-network-log.txt');
|
||||
await fs.writeFile(logPath, paypalNetworkLog.join('
|
||||
|
||||
'), 'utf8');
|
||||
await testInfo.attach('paypal-network-log', {
|
||||
path: logPath,
|
||||
contentType: 'text/plain',
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
async function completeRegistrationOrLogin(page: Page, credentials: { email: string; password: string }): Promise<void> {
|
||||
const identifierInput = page.locator('input[name="identifier"]');
|
||||
if (await identifierInput.isVisible()) {
|
||||
await identifierInput.fill(credentials.email);
|
||||
await page.locator('input[name="password"]').fill(credentials.password);
|
||||
await page.getByRole('button', { name: /^Anmelden$|Login/i }).last().click();
|
||||
await expect(page.getByPlaceholder(/Gutscheincode|Coupon/i)).toBeVisible({ timeout: 20_000 });
|
||||
return;
|
||||
}
|
||||
|
||||
await page.fill('input[name="first_name"]', 'Play');
|
||||
await page.fill('input[name="last_name"]', 'Wright');
|
||||
await page.fill('input[name="email"]', credentials.email);
|
||||
const addressInput = page.locator('input[name="address"]');
|
||||
if (await addressInput.isVisible()) {
|
||||
await addressInput.fill('Teststrasse 1, 12345 Berlin');
|
||||
}
|
||||
|
||||
const phoneInput = page.locator('input[name="phone"]');
|
||||
if (await phoneInput.isVisible()) {
|
||||
await phoneInput.fill('+49123456789');
|
||||
}
|
||||
|
||||
const usernameInput = page.locator('input[name="username"]');
|
||||
if (await usernameInput.isVisible()) {
|
||||
await usernameInput.fill(credentials.email);
|
||||
}
|
||||
await page.fill('input[name="password"]', credentials.password);
|
||||
await page.fill('input[name="password_confirmation"]', credentials.password);
|
||||
|
||||
await page.check('input[name="privacy_consent"]');
|
||||
await page.getByRole('button', { name: /Registrieren|Register/i }).last().click();
|
||||
|
||||
try {
|
||||
await expect(page.getByPlaceholder(/Gutscheincode|Coupon/i)).toBeVisible({ timeout: 20_000 });
|
||||
return;
|
||||
} catch {
|
||||
const loginButton = page.getByRole('button', { name: /^Anmelden$|Login/i }).first();
|
||||
if (await loginButton.isVisible()) {
|
||||
await loginButton.click();
|
||||
}
|
||||
}
|
||||
|
||||
await expect(page.locator('input[name="identifier"]')).toBeVisible({ timeout: 10_000 });
|
||||
await page.locator('input[name="identifier"]').fill(credentials.email);
|
||||
await page.locator('input[name="password"]').fill(credentials.password);
|
||||
await page.getByRole('button', { name: /^Anmelden$|Login/i }).last().click();
|
||||
await expect(page.getByPlaceholder(/Gutscheincode|Coupon/i)).toBeVisible({ timeout: 20_000 });
|
||||
}
|
||||
|
||||
async function proceedToAccountStep(page: Page, timeoutMs = 30_000): Promise<void> {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
|
||||
while (Date.now() < deadline) {
|
||||
const accountForm = page.locator('input[name="first_name"], input[name="identifier"]');
|
||||
if (await accountForm.isVisible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
await dismissConsentBanner(page);
|
||||
|
||||
const continueButton = page.getByRole('button', { name: /Weiter|Continue/i }).first();
|
||||
if (await continueButton.isVisible()) {
|
||||
if (await continueButton.isEnabled()) {
|
||||
await continueButton.click();
|
||||
}
|
||||
}
|
||||
|
||||
await page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
throw new Error('Account step did not load in time.');
|
||||
}
|
||||
|
||||
function buildTenantEmail(): string | null {
|
||||
const rawEmail = process.env.E2E_TENANT_EMAIL ?? process.env.E2E_PAYPAL_EMAIL ?? process.env.E2E_LEMONSQUEEZY_EMAIL ?? process.env.E2E_PADDLE_EMAIL ?? null;
|
||||
if (!rawEmail) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!rawEmail.includes('{timestamp}')) {
|
||||
return rawEmail;
|
||||
}
|
||||
|
||||
const timestamp = Math.floor(Date.now() / 1000).toString();
|
||||
return rawEmail.replaceAll('{timestamp}', timestamp);
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
__paypalOptions?: {
|
||||
createOrder?: () => Promise<string>;
|
||||
onApprove?: (data: { orderID: string }) => Promise<void>;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,12 @@ import { test, expectFixture as expect } from '../helpers/test-fixtures';
|
||||
|
||||
const shouldRun = process.env.E2E_TESTING_API === '1';
|
||||
|
||||
test.describe('Classic package checkout with Lemon Squeezy completion', () => {
|
||||
test.describe('Classic package checkout with PayPal 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,
|
||||
simulateLemonSqueezyCompletion,
|
||||
getTestMailbox,
|
||||
}) => {
|
||||
await clearTestMailbox();
|
||||
await seedTestCoupons();
|
||||
@@ -18,44 +15,43 @@ test.describe('Classic package checkout with Lemon Squeezy completion', () => {
|
||||
const unique = Date.now();
|
||||
const email = `checkout+${unique}@example.test`;
|
||||
const password = 'Password123!';
|
||||
await page.addInitScript(() => {
|
||||
window.__openedWindows = [];
|
||||
const originalOpen = window.open;
|
||||
window.open = function (...args) {
|
||||
window.__openedWindows.push(args);
|
||||
return originalOpen?.apply(this, args) ?? null;
|
||||
};
|
||||
});
|
||||
|
||||
await page.route('https://app.lemonsqueezy.com/js/lemon.js', async (route) => {
|
||||
await page.route('https://www.paypal.com/sdk/js**', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/javascript',
|
||||
body: `
|
||||
window.__lemonEventHandler = null;
|
||||
window.__lemonOpenedUrl = null;
|
||||
window.LemonSqueezy = {
|
||||
Setup(options) {
|
||||
window.__lemonEventHandler = options?.eventHandler || null;
|
||||
},
|
||||
Url: {
|
||||
Open(url) {
|
||||
window.__lemonOpenedUrl = url;
|
||||
},
|
||||
window.paypal = {
|
||||
Buttons: function(options) {
|
||||
window.__paypalOptions = options;
|
||||
return {
|
||||
render: function() { return Promise.resolve(); },
|
||||
};
|
||||
},
|
||||
};
|
||||
`,
|
||||
});
|
||||
});
|
||||
|
||||
let lemonsqueezyRequestPayload: Record<string, unknown> | null = null;
|
||||
await page.route('**/lemonsqueezy/create-checkout', async (route) => {
|
||||
lemonsqueezyRequestPayload = route.request().postDataJSON() as Record<string, unknown>;
|
||||
let paypalRequestPayload: Record<string, unknown> | null = null;
|
||||
await page.route('**/paypal/create-order', async (route) => {
|
||||
paypalRequestPayload = route.request().postDataJSON() as Record<string, unknown>;
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
checkout_url: 'https://fotospiel.lemonsqueezy.com/checkout/abc123',
|
||||
order_id: 'order_test_123',
|
||||
checkout_session_id: 'session_test_123',
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('**/paypal/capture-order', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
status: 'completed',
|
||||
}),
|
||||
});
|
||||
});
|
||||
@@ -113,85 +109,36 @@ test.describe('Classic package checkout with Lemon Squeezy completion', () => {
|
||||
await expect(termsCheckbox).toBeVisible();
|
||||
await termsCheckbox.click();
|
||||
|
||||
await page.getByRole('button', { name: /Weiter mit Lemon Squeezy|Continue with Lemon Squeezy/i }).first().click();
|
||||
await expect.poll(async () => {
|
||||
return page.evaluate(() => Boolean(window.__paypalOptions));
|
||||
}).toBe(true);
|
||||
|
||||
let checkoutMode: 'inline' | 'hosted' | null = null;
|
||||
for (let i = 0; i < 8; i++) {
|
||||
const state = await page.evaluate(() => ({
|
||||
inline: Boolean(window.__lemonOpenedUrl),
|
||||
opened: window.__openedWindows?.length ?? 0,
|
||||
}));
|
||||
|
||||
if (state.inline) {
|
||||
checkoutMode = 'inline';
|
||||
break;
|
||||
}
|
||||
|
||||
if (state.opened > 0) {
|
||||
checkoutMode = 'hosted';
|
||||
break;
|
||||
}
|
||||
|
||||
await page.waitForTimeout(300);
|
||||
}
|
||||
|
||||
expect(checkoutMode).not.toBeNull();
|
||||
|
||||
if (checkoutMode === 'hosted') {
|
||||
await expect.poll(async () => {
|
||||
return page.evaluate(() => window.__openedWindows?.[0]?.[0] ?? null);
|
||||
}).toContain('https://fotospiel.lemonsqueezy.com/checkout/abc123');
|
||||
}
|
||||
|
||||
await page.evaluate(() => {
|
||||
window.__lemonEventHandler?.({
|
||||
event: 'Checkout.Success',
|
||||
data: { id: 'ord_test', attributes: { checkout_id: 'chk_123' } },
|
||||
});
|
||||
const orderId = await page.evaluate(async () => {
|
||||
return window.__paypalOptions?.createOrder?.();
|
||||
});
|
||||
|
||||
let session = null;
|
||||
for (let i = 0; i < 6; i++) {
|
||||
session = await getLatestCheckoutSession({ email });
|
||||
if (session) {
|
||||
break;
|
||||
}
|
||||
await page.waitForTimeout(500);
|
||||
}
|
||||
expect(orderId).toBe('order_test_123');
|
||||
|
||||
if (session) {
|
||||
await simulateLemonSqueezyCompletion(session.id);
|
||||
|
||||
for (let i = 0; i < 6; i++) {
|
||||
const refreshed = await getLatestCheckoutSession({ email });
|
||||
if (refreshed?.status === 'completed') {
|
||||
session = refreshed;
|
||||
break;
|
||||
}
|
||||
await page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
expect(session?.status).toBe('completed');
|
||||
}
|
||||
await page.evaluate(async () => {
|
||||
await window.__paypalOptions?.onApprove?.({ orderID: 'order_test_123' });
|
||||
});
|
||||
|
||||
await expect(page.getByText(/Marketing-Dashboard/)).toBeVisible();
|
||||
await expect(
|
||||
page.getByRole('button', { name: /Zum Admin-Bereich|To Admin Area/i })
|
||||
).toBeVisible();
|
||||
|
||||
if (lemonsqueezyRequestPayload) {
|
||||
expect(lemonsqueezyRequestPayload['coupon_code']).toBe('PERCENT10');
|
||||
if (paypalRequestPayload) {
|
||||
expect(paypalRequestPayload['coupon_code']).toBe('PERCENT10');
|
||||
}
|
||||
|
||||
const messages = await getTestMailbox();
|
||||
expect(messages.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
__openedWindows?: unknown[];
|
||||
__lemonEventHandler?: ((event: { event: string; data?: unknown }) => void) | null;
|
||||
__lemonOpenedUrl?: string | null;
|
||||
__paypalOptions?: {
|
||||
createOrder?: () => Promise<string>;
|
||||
onApprove?: (data: { orderID: string }) => Promise<void>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user