Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe('POST /forms-admin/payments/action', () => {
totalCents: 20000,
currency: 'usd',
entryId: 'e1',
returnUrl: 'https://example.com/',
returnUrl: 'https://example.com/forms-pay/success',
cancelUrl: 'https://example.com/',
});
expect(attachPaymentMock).toHaveBeenCalledWith(
Expand Down Expand Up @@ -258,14 +258,17 @@ describe('POST /forms-admin/payments/action', () => {
expect(res.headers.get('Location')).toBe('/forms-admin/entries/e1/');
});

it("computes the PayPal returnUrl/cancelUrl trailingSlash-aware, never a hardcoded slashless URL (B1)", async () => {
it("computes the PayPal returnUrl/cancelUrl trailingSlash-aware, with the success page as returnUrl and the site root as cancelUrl (B1)", async () => {
(config as { trailingSlash?: 'always' | 'never' | 'ignore' }).trailingSlash = 'always';
getEntryByIdMock.mockResolvedValueOnce(makeEntry());

await callPost({ entryId: 'e1', provider: 'paypal', amount: '200' });

expect(createOrderMock).toHaveBeenCalledWith(
expect.objectContaining({ returnUrl: 'https://example.com/', cancelUrl: 'https://example.com/' }),
expect.objectContaining({
returnUrl: 'https://example.com/forms-pay/success/',
cancelUrl: 'https://example.com/',
}),
);
});

Expand Down
12 changes: 5 additions & 7 deletions packages/astro-forms/src/server/routes/admin/payment-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,16 @@ export const POST: APIRoute = async ({ request }) => {
const result = await createPaymentLink({ amountCents, currency: DEFAULT_CURRENCY, memo, entryId });
link = { url: result.url, providerRef: result.providerRef };
} else if (paypalConfigured()) {
// No dedicated payment-confirmation page exists in this plan's scope
// (that lands with 03-05's /forms-pay/success) — both return/cancel
// land on the site root, computed trailingSlash-aware (B1). The
// inbound webhook (03-07) remains the sole source of payment truth,
// never this browser redirect.
const returnUrl = `${config.siteUrl}${adminUrl('/', trailingSlash)}`;
// PayPal's return URL now targets the shared success page, while the
// cancel URL keeps sending the visitor back to the site root.
const returnUrl = `${config.siteUrl}${adminUrl('/forms-pay/success', trailingSlash)}`;
const cancelUrl = `${config.siteUrl}${adminUrl('/', trailingSlash)}`;
const order = await createOrder({
totalCents: amountCents,
currency: DEFAULT_CURRENCY,
entryId,
returnUrl,
cancelUrl: returnUrl,
cancelUrl,
});
if (order) link = { url: order.approvalUrl, providerRef: order.providerRef };
}
Expand Down