Payment Card
billingsdk/payment-cardFreeBlock
A payment card component
Install it
npx shadcn@latest add https://billingsdk.com/r/payment-card.jsonSource
1"use client";23import { useEffect, useState } from "react";4import { cn } from "@/lib/utils";5import {6 Card,7 CardContent,8 CardDescription,9 CardHeader,10 CardTitle,11} from "@/components/ui/card";12import { Input } from "@/components/ui/input";13import { Label } from "@/components/ui/label";14import { Button } from "@/components/ui/button";15import { ArrowRight, Check } from "lucide-react";16import { AnimatePresence, motion } from "motion/react";1718export interface finalTextProps {19 text: string;20}2122export interface PaymentCardProps {23 title: string;24 description: string;25 price: string;26 feature?: string;27 featuredescription?: string;28 feature2?: string;29 feature2description?: string;30 finalText?: finalTextProps[];31 onPay?: (data: {32 cardNumber: string;33 expiry: string;34 cvc: string;35 }) => Promise<void> | void;36 className?: string;37}3839export function PaymentCard({40 title,41 description,42 price,43 feature,44 featuredescription,45 feature2,46 feature2description,47 finalText = [],48 onPay,49 className,50}: PaymentCardProps) {51 const [cardNumber, setCardNumber] = useState("");52 const [expiry, setExpiry] = useState("");53 const [cvc, setCvc] = useState("");54 const [index, setIndex] = useState(0);55 const [errors, setErrors] = useState<{56 card?: string;57 expiry?: string;58 cvc?: string;59 }>({});6061 const validate = () => {62 const newErrors: typeof errors = {};6364 // Card number validation65 if (!/^[0-9 ]{16,19}$/.test(cardNumber)) {66 newErrors.card = "Card number must be 16 digits and only numbers.";67 }6869 // Expiry validation70 if (!/^(0[1-9]|1[0-2])\/\d{2}$/.test(expiry)) {71 newErrors.expiry = "Enter a valid expiry date (MM/YY).";72 } else {73 const [month, year] = expiry.split("/").map(Number);74 const now = new Date();75 const firstInvalidDay = new Date(2000 + year, month, 1);76 if (firstInvalidDay <= now) {77 newErrors.expiry = "Card has expired.";78 }79 }8081 // CVC validation82 if (!/^[0-9]{3,4}$/.test(cvc)) {83 newErrors.cvc = "CVC must be 3 or 4 digits.";84 }8586 setErrors(newErrors);87 return Object.keys(newErrors).length === 0;88 };8990 const handlePay = () => {91 if (validate()) {92 if (onPay) {93 onPay({ cardNumber, expiry, cvc });94 console.log("Payment processed!");95 } else {96 console.log("error");97 }98 }99 };100101 // Final text animation102 useEffect(() => {103 if (!finalText || finalText.length === 0) return;104105// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from billingsdk
All 35 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| All Componentsall | billingsdk | Blocks | Free | no deps | |
| Top Bannerbanner | billingsdk | Blocks | Free | 2 deps · 2 files | |
| Billing Screenbilling-screen | billingsdk | Blocks | Free | 2 deps · 2 files | |
| Billing Settingsbilling-settings | billingsdk | Blocks | Free | 2 deps · 2 files | |
| Billing Settings 2billing-settings-2 | billingsdk | Blocks | Free | 1 dep · 2 files | |
| Cancel Subscription Cardcancel-subscription-card | billingsdk | Blocks | Free | 1 dep · 3 files | |
| Cancel Subscription Dialogcancel-subscription-dialog | billingsdk | Blocks | Free | 1 dep · 3 files | |
| Detailed Usage Tabledetailed-usage-table | billingsdk | Blocks | Free | no deps · 2 files |
