Billing Payment Methods
A payment method management block for billing settings pages. Lists saved cards with a brand icon, masked last 4 digits, expiry date, a default badge, and an inline near-expiry warning. Each row exposes a set-default action and a remove action that asks for confirmation before deleting. Built with shadcn/ui Button and Badge components, Lucide icons, and Tailwind CSS.
Docs
Installation
A real shadcn registry command, not a copy-paste stand-in: it fetches this block plus its button, badge dependencies and any missing npm packages, and installs them straight into your project.
npx shadcn add https://staaarter.com/r/billing-payment-methods.jsonPrefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/billing/billing4.tsx instead.
Usage
The file also exports billing4Demo, the exact props behind the preview above. Spread it to get a working section in one line, then replace it with your own data.
import { Billing4, billing4Demo } from "@/components/blocks/billing/billing4"; export default function Page() { return <Billing4 {...billing4Demo} />; }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| heading | string | "Payment methods" | Section heading above the list. |
| description | string | none | One-line description under the heading. |
| methods | PaymentMethodItem[] | none | Saved payment methods to render, used to seed the component's internal state. |
| addHref | string | "#" | Destination for the 'Add payment method' link. |
| addLabel | string | "Add payment method" | Label for the add-method link. |
| className | string | none | Extra classes for the outer section element. |
Types
interface PaymentMethodItem { id: string; brand: "visa" | "mastercard" | "amex" | "discover" | "other"; last4: string; expiryMonth: number; expiryYear: number; isDefault?: boolean; expiringSoon?: boolean; }
Behavior notes
- The methods prop only seeds initial state, the component copies it into useState so set-default and remove actions update the list on the client without a page reload.
- Clicking 'Remove' doesn't delete immediately, it swaps that row's actions for an inline 'Remove this card? Confirm / Cancel' prompt, and only the Confirm click removes the item from state.
- Clicking 'Set as default' moves the Default badge to that row and clears it from every other row in one state update.
- The brand icon is looked up internally from a Record<CardBrand, LucideIcon> keyed by the plain 'brand' string on each item, no icon or component is ever accepted as a prop.
- expiringSoon is a plain boolean on the data rather than computed from the current date, so the 'Near expiry' badge renders identically on the server and after client hydration.
Frequently asked questions
More Billing Blocks
View all →Billing Invoice List
Invoice history table with status badges, formatted amounts, and a per-row download link, built with shadcn/ui and Tailwind CSS.
Billing Failed Payment Alert
High-contrast failed-payment alert with a message, a retry button, and an optional update-payment-method button, built with shadcn/ui and Tailwind CSS.
Billing Credit Balance
Compact credit balance card with a large total, an optional purchased-versus-promotional breakdown, a low-balance notice, and a top-up button.
Billing Add Card
A card entry form for React and Next.js with auto-formatted fields, internal brand detection, and per-field validation feedback built with shadcn/ui and Tailwind CSS.
Billing Coupon Code
An inline promo code input for React and Next.js with a simulated loading state, an applied summary showing the discount amount, and an invalid-code message.
Billing Subscription Summary
A subscription summary card with plan name, price, renewal date, and per-metric usage bars, plus manage and upgrade actions.