"use client"; import React, { useCallback, useEffect, useState } from "react"; import { useAuth } from "@/hooks/useAuth"; import { apiFetch } from "@/lib/api"; import { useDismissingState } from "@/hooks/useDismissingState"; import { Copy, CreditCard, KeyRound, Trash2, Webhook } from "lucide-react"; import { errorMessage } from "@/lib/utils"; type Source = "db" | "env" | "none"; interface YocoConfig { secretKeyMasked: string; secretKeySource: Source; mode: "test" | "live" | "unknown"; webhookSecretMasked: string; webhookSecretSource: Source; webhookId: string; webhookUrl: string; configured: boolean; } interface YocoWebhook { id: string; name: string; url: string; mode: "test" | "live"; isActive: boolean; pointsHere: boolean; } const inputCls = "w-full border rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-brand-400"; const primaryBtn = "px-3 py-1.5 text-sm rounded-lg bg-brand-600 hover:bg-brand-700 disabled:opacity-50 text-white font-medium"; const secondaryBtn = "px-3 py-1.5 text-sm rounded-lg bg-gray-100 hover:bg-gray-200 disabled:opacity-50"; function ModeBadge({ mode }: { mode: string }) { if (mode !== "test" && mode !== "live") return null; return ( {mode === "live" ? "Live" : "Test"} ); } function SourceNote({ source }: { source: Source }) { if (source === "env") { return
From the server's .env file. Save it here to store it in the database instead.
; } if (source === "none") returnNot set.
; return null; } function Card({ icon: Icon, title, subtitle, children }: { icon: React.ElementType; title: string; subtitle: string; children: React.ReactNode; }) { return ({subtitle}
Online card payments. Secrets are stored encrypted and never shown in full.
Loading…
) : cfg && ( <> {/* ── API key ─────────────────────────────────────────────────── */}{cfg.secretKeyMasked || "—"}
The key is checked with Yoco before it is saved.
{cfg.webhookSecretMasked || "—"}
{cfg.webhookSecretSource === "db" && (
)}
{cfg.webhookUrl || "—"}
{cfg.webhookUrl && (
)}
Registers a webhook with Yoco and saves the secret it returns. Yoco only shows the secret once, so it is stored straight away.
Add the secret key first.
) ) : (Paste the secret of a webhook you registered yourself.
setSecretInput(e.target.value)} />Add the secret key to see the webhooks.
) : hooksError ? ({hooksError}
) : hooks.length === 0 ? (No webhooks registered.
) : ({h.url}
{!h.pointsHere &&This URL isn't this server's webhook endpoint.
} {confirmDelete === h.id && h.isActive && (This is the active webhook. Deleting it also removes the stored secret, and payments won't be confirmed until a new one is set up.
)}