Blocks / Payment form

Payment form

Card or bank (SEPA) details, formatted and checked as typed. Test mode is announced.

import { PaymentForm, luhnValid, ibanValid, TEST_CARDS, TEST_IBANS } from "@forgeron/ui";
/01 → Card
import { PaymentForm } from "@forgeron/ui";
import { useState } from "react";

export default function Card() {
  const [done, setDone] = useState("");
  return (
    <div style={{ display: "grid", gap: 12 }}>
      <PaymentForm
        submitLabel="Pay 120.00 EUR"
        onSubmit={(p) => setDone(p.method === "card" ? `Test card ending ${p.last4} accepted` : "")}
      />
      {done ? <p style={{ margin: 0, font: "12px var(--font-mono)" }}>{done}</p> : null}
    </div>
  );
}
/02 → Bank
import { PaymentForm } from "@forgeron/ui";

export default function Bank() {
  return <PaymentForm defaultMethod="bank" methods={["bank"]} submitLabel="Set up the debit" />;
}
API → Props
PropTypeDefaultDescription
method / defaultMethod"card" | "bank""card"Controlled or not, with onMethodChange.
methodsPaymentMethod[]—Which are offered; one hides the switch.
testModebooleantrueA Test mode banner and a button that fills a published test number. A live form is a deliberate `false`.
onSubmit(payment) => void—Once, when valid: { method, values } (card also brand and last4). The fields are cleared after. Nothing is stored or logged here.
onValidityChange(valid: boolean) => void—Only whether it could be sent, never a value.
mandateTextstring—The sentence the person accepts.
submitLabelstring"Pay"The button.
disabledboolean—Locks the form.
classNamestring—Extra classes.