- src/payments: provider registry and PaymentProvider interface (createCheckout, verifyWebhook/parseWebhook, getTransaction, refund, listTransactions as capabilities), Yoco as the first provider. All four direct Yoco checkout calls go through payments.createCheckout. - Webhook split into the provider part (signature, parsing) and shared processing; same URL (/api/webhooks/yoco), same behaviour. - YocoTransaction renamed in place to ProviderTransaction (+ provider, unique per provider + externalId); Payment.provider added and backfilled to "yoco". Payment.method stays the wallet type so cashups are unchanged. - Site settings → Payments: Enabled toggle and order per provider; Yoco's settings shown while it's enabled. R15 minimum for all online payments. - New endpoint names (/api/payments/checkout, /api/provider-transactions); the old /yoco-checkout and /yoco-transactions paths still work. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
1.9 KiB
TypeScript
38 lines
1.9 KiB
TypeScript
import { test, expect, loginAs, api } from "./fixtures";
|
|
|
|
type ProviderSetting = { id: string; label: string; enabled: boolean; configured: boolean };
|
|
|
|
test.describe("payment providers", () => {
|
|
test("admin: Payments tab turns a provider on and off", async ({ page }) => {
|
|
await loginAs(page, "admin");
|
|
// The tab's older name still opens it.
|
|
await page.goto("/dashboard/admin/settings?tab=yoco");
|
|
await expect(page.getByRole("heading", { name: "Payments", exact: true })).toBeVisible();
|
|
await expect(page.getByRole("heading", { name: "Yoco payments" })).toBeVisible();
|
|
|
|
const providers = page.getByRole("list", { name: "Payment providers" });
|
|
const yoco = providers.getByRole("checkbox", { name: "Enable Yoco" });
|
|
await expect(yoco).toBeChecked();
|
|
|
|
try {
|
|
await yoco.uncheck();
|
|
await expect(page.getByText("Payment providers saved")).toBeVisible();
|
|
await expect(page.getByText(/Online payments are off/)).toBeVisible();
|
|
// A switched-off provider's settings are hidden
|
|
await expect(page.getByRole("heading", { name: "Yoco payments" })).toBeHidden();
|
|
const off = await api<{ providers: { id: string }[]; minimumAmount: number }>(page, "user", "GET", "/api/payments/providers");
|
|
expect(off.providers).toEqual([]);
|
|
expect(off.minimumAmount).toBe(15);
|
|
|
|
await yoco.check();
|
|
await expect(yoco).toBeChecked();
|
|
await expect(page.getByRole("heading", { name: "Yoco payments" })).toBeVisible();
|
|
const settings = await api<{ providers: ProviderSetting[] }>(page, "admin", "GET", "/api/payments/providers/settings");
|
|
expect(settings.providers.find((p) => p.id === "yoco")?.enabled).toBe(true);
|
|
} finally {
|
|
// Leave Yoco on for the other tests.
|
|
await api(page, "admin", "PUT", "/api/payments/providers/settings", { providers: [{ id: "yoco", enabled: true }] });
|
|
}
|
|
});
|
|
});
|