feat(payment): fix zibal refund api, add maskable fields, receipt modal, standardized buttons and order refund options
Deploy Canina / deploy (push) Successful in 41s
Deploy Canina / deploy (push) Successful in 41s
This commit is contained in:
1 parent
f9e40564cf
commit
d62787cd99
22 files changed
+10934
-9318
No files matched your search
@@ -0,0 +1,235 @@
|
||||
import React from 'react';
|
||||
import { Printer, X, CheckCircle2, ShieldCheck, Copy } from 'lucide-react';
|
||||
import { toast } from 'react-hot-toast';
|
||||
import Button from './ui/Button';
|
||||
|
||||
export interface TransactionReceiptData {
|
||||
trackId?: string | number;
|
||||
refNumber?: string | number;
|
||||
amountRials?: number | string;
|
||||
amountTomans?: number | string;
|
||||
statusText?: string;
|
||||
orderNumber?: string;
|
||||
orderId?: string;
|
||||
cardNumber?: string;
|
||||
paidAt?: string;
|
||||
createdAt?: string;
|
||||
fee?: number | string;
|
||||
mobile?: string;
|
||||
description?: string;
|
||||
psp?: string;
|
||||
ip?: string;
|
||||
}
|
||||
|
||||
interface TransactionReceiptModalProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
data: TransactionReceiptData | null;
|
||||
}
|
||||
|
||||
export default function TransactionReceiptModal({
|
||||
isOpen,
|
||||
onClose,
|
||||
data,
|
||||
}: TransactionReceiptModalProps) {
|
||||
if (!isOpen || !data) return null;
|
||||
|
||||
const handlePrint = () => {
|
||||
window.print();
|
||||
};
|
||||
|
||||
const handleCopy = (text: string, label: string) => {
|
||||
if (!text) return;
|
||||
navigator.clipboard.writeText(text);
|
||||
toast.success(`${label} کپی شد`);
|
||||
};
|
||||
|
||||
const rials =
|
||||
data.amountRials !== undefined
|
||||
? Number(data.amountRials)
|
||||
: (Number(data.amountTomans || 0) * 10);
|
||||
const tomans =
|
||||
data.amountTomans !== undefined
|
||||
? Number(data.amountTomans)
|
||||
: Math.floor(Number(data.amountRials || 0) / 10);
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm print:p-0 print:bg-white">
|
||||
<div className="bg-white rounded-3xl max-w-sm w-full shadow-2xl border border-gray-100 overflow-hidden print:border-none print:shadow-none font-vazir" dir="rtl">
|
||||
{/* Modal Header */}
|
||||
<div className="p-4 border-b border-gray-100 flex items-center justify-between print:hidden">
|
||||
<h3 className="font-black text-sm text-gray-900 flex items-center gap-1.5">
|
||||
<ShieldCheck className="w-4 h-4 text-emerald-600" />
|
||||
<span>رسید تراکنش {data.trackId || ''}</span>
|
||||
</h3>
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="text-gray-400 hover:text-gray-700 font-bold p-1 cursor-pointer"
|
||||
>
|
||||
<X className="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* The Zigzag Receipt Slip (Matching Zibal screenshot exactly) */}
|
||||
<div className="p-6 space-y-5 bg-white relative">
|
||||
{/* Top Jagged Border (CSS Jagged effect) */}
|
||||
<div className="w-full h-3 bg-indigo-50/50 -mt-6 mb-3 flex justify-between overflow-hidden opacity-60">
|
||||
{Array.from({ length: 24 }).map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="w-0 h-0 border-l-[6px] border-l-transparent border-r-[6px] border-r-transparent border-t-[8px] border-t-white"
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Amount Display */}
|
||||
<div className="text-center space-y-1">
|
||||
<div className="text-2xl font-black text-emerald-600 font-mono">
|
||||
{rials.toLocaleString('fa-IR')}{' '}
|
||||
<span className="text-sm font-black text-emerald-700">ریال</span>
|
||||
</div>
|
||||
<p className="text-[11px] font-bold text-gray-400 font-mono">
|
||||
({tomans.toLocaleString('fa-IR')} تومان)
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Data List (Aligned exactly like Zibal slip) */}
|
||||
<div className="space-y-2.5 text-xs">
|
||||
{/* Track ID */}
|
||||
<div className="flex items-center justify-between py-1 border-b border-gray-50">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleCopy(String(data.trackId || ''), 'شماره تراکنش')}
|
||||
className="text-indigo-600 hover:text-indigo-800 flex items-center gap-1 font-mono font-bold cursor-pointer"
|
||||
title="کپی"
|
||||
>
|
||||
<Copy className="w-3 h-3" />
|
||||
<span>{data.trackId || '-'}</span>
|
||||
</button>
|
||||
<span className="text-gray-500 font-bold">شماره تراکنش</span>
|
||||
</div>
|
||||
|
||||
{/* Reference Number */}
|
||||
<div className="flex items-center justify-between py-1 border-b border-gray-50">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleCopy(String(data.refNumber || ''), 'شناسه مرجع')}
|
||||
className="text-indigo-600 hover:text-indigo-800 flex items-center gap-1 font-mono font-bold cursor-pointer"
|
||||
title="کپی"
|
||||
>
|
||||
<Copy className="w-3 h-3" />
|
||||
<span>{data.refNumber || '-'}</span>
|
||||
</button>
|
||||
<span className="text-gray-500 font-bold">شناسه مرجع</span>
|
||||
</div>
|
||||
|
||||
{/* Paid At */}
|
||||
<div className="flex items-center justify-between py-1 border-b border-gray-50">
|
||||
<span className="font-mono text-gray-700 font-bold dir-ltr">
|
||||
{data.paidAt || data.createdAt || '-'}
|
||||
</span>
|
||||
<span className="text-gray-500 font-bold">تاریخ پرداخت</span>
|
||||
</div>
|
||||
|
||||
{/* Status */}
|
||||
<div className="flex items-center justify-between py-1 border-b border-gray-50">
|
||||
<span className="text-emerald-600 font-black flex items-center gap-1">
|
||||
<span className="w-2 h-2 rounded-full bg-emerald-500 inline-block"></span>
|
||||
<span>{data.statusText || 'پرداخت موفق'}</span>
|
||||
</span>
|
||||
<span className="text-gray-500 font-bold">وضعیت</span>
|
||||
</div>
|
||||
|
||||
{/* Order ID */}
|
||||
<div className="flex items-center justify-between py-1.5 px-2 bg-gray-50/80 rounded-lg">
|
||||
<span className="font-mono font-bold text-gray-900">
|
||||
{data.orderNumber || data.orderId || '-'}
|
||||
</span>
|
||||
<span className="text-gray-500 font-bold">شناسه سفارش</span>
|
||||
</div>
|
||||
|
||||
{/* Card Number */}
|
||||
<div className="flex items-center justify-between py-1 border-b border-gray-50">
|
||||
<span className="font-mono text-gray-800 font-bold dir-ltr">
|
||||
{data.cardNumber || '-'}
|
||||
</span>
|
||||
<span className="text-gray-500 font-bold">شماره کارت</span>
|
||||
</div>
|
||||
|
||||
{/* Creation Date */}
|
||||
<div className="flex items-center justify-between py-1.5 px-2 bg-gray-50/80 rounded-lg">
|
||||
<span className="font-mono font-bold text-gray-700 dir-ltr">
|
||||
{data.createdAt || data.paidAt || '-'}
|
||||
</span>
|
||||
<span className="text-gray-500 font-bold">تاریخ ایجاد</span>
|
||||
</div>
|
||||
|
||||
{/* Mobile */}
|
||||
<div className="flex items-center justify-between py-1.5 px-2 bg-gray-50/80 rounded-lg">
|
||||
<span className="font-mono font-bold text-gray-800 dir-ltr">
|
||||
{data.mobile || '-'}
|
||||
</span>
|
||||
<span className="text-gray-500 font-bold">شماره موبایل</span>
|
||||
</div>
|
||||
|
||||
{/* Description */}
|
||||
<div className="flex items-center justify-between py-1 border-b border-gray-50">
|
||||
<span className="text-gray-800 font-bold max-w-[180px] truncate text-left">
|
||||
{data.description || 'پرداخت آنلاین - پت شاپ کنینا'}
|
||||
</span>
|
||||
<span className="text-gray-500 font-bold">توضیحات</span>
|
||||
</div>
|
||||
|
||||
{/* PSP */}
|
||||
<div className="flex items-center justify-between py-1.5 px-2 bg-gray-50/80 rounded-lg">
|
||||
<span className="font-bold text-indigo-700 text-[11px]">
|
||||
{data.psp || 'زیبال / بهپرداخت ملت'}
|
||||
</span>
|
||||
<span className="text-gray-500 font-bold">PSP</span>
|
||||
</div>
|
||||
|
||||
{/* Real IP */}
|
||||
<div className="flex items-center justify-between py-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleCopy(String(data.ip || ''), 'آیپی کاربر')}
|
||||
className="text-indigo-600 hover:text-indigo-800 flex items-center gap-1 font-mono font-bold cursor-pointer dir-ltr"
|
||||
title="کپی آیپی"
|
||||
>
|
||||
<Copy className="w-3 h-3" />
|
||||
<span>{data.ip || '-'}</span>
|
||||
</button>
|
||||
<span className="text-gray-500 font-bold">IP</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Bottom Jagged Border */}
|
||||
<div className="w-full h-3 bg-indigo-50/50 -mb-6 mt-4 flex justify-between overflow-hidden opacity-60">
|
||||
{Array.from({ length: 24 }).map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="w-0 h-0 border-l-[6px] border-l-transparent border-r-[6px] border-r-transparent border-b-[8px] border-b-white"
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Actions / Print Footer */}
|
||||
<div className="p-4 bg-gray-50/80 border-t border-gray-100 flex items-center justify-between print:hidden">
|
||||
<Button variant="outline" size="sm" onClick={onClose}>
|
||||
بستن
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
startIcon={Printer}
|
||||
onClick={handlePrint}
|
||||
className="border-gray-300 hover:border-indigo-600 text-indigo-600 hover:bg-indigo-50"
|
||||
>
|
||||
چاپ رسید
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
import React from 'react';
|
||||
import { Info } from 'lucide-react';
|
||||
import Spinner from './Spinner';
|
||||
|
||||
export type ButtonVariant =
|
||||
| 'primary'
|
||||
| 'secondary'
|
||||
| 'danger'
|
||||
| 'success'
|
||||
| 'warning'
|
||||
| 'outline'
|
||||
| 'ghost';
|
||||
|
||||
export type ButtonSize = 'xs' | 'sm' | 'md' | 'lg';
|
||||
|
||||
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
variant?: ButtonVariant;
|
||||
size?: ButtonSize;
|
||||
isLoading?: boolean;
|
||||
startIcon?: React.ComponentType<{ className?: string }>;
|
||||
endIcon?: React.ComponentType<{ className?: string }>;
|
||||
info?: string;
|
||||
badge?: string | number;
|
||||
fullWidth?: boolean;
|
||||
}
|
||||
|
||||
export default function Button({
|
||||
children,
|
||||
variant = 'primary',
|
||||
size = 'md',
|
||||
isLoading = false,
|
||||
startIcon: StartIcon,
|
||||
endIcon: EndIcon,
|
||||
info,
|
||||
badge,
|
||||
fullWidth = false,
|
||||
className = '',
|
||||
disabled,
|
||||
...props
|
||||
}: ButtonProps) {
|
||||
// Base styles: strict whitespace-nowrap and touch-friendly cursor
|
||||
const baseClasses =
|
||||
'inline-flex items-center justify-center font-bold whitespace-nowrap transition-all select-none rounded-xl cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed disabled:pointer-events-none focus:outline-none focus:ring-2 focus:ring-offset-2';
|
||||
|
||||
// Size styling
|
||||
const sizeClasses: Record<ButtonSize, string> = {
|
||||
xs: 'px-2.5 py-1 text-[11px] gap-1.5',
|
||||
sm: 'px-3.5 py-1.5 text-xs gap-2',
|
||||
md: 'px-4 py-2.5 text-xs sm:text-sm gap-2',
|
||||
lg: 'px-6 py-3 text-sm sm:text-base gap-2.5 shadow-md',
|
||||
};
|
||||
|
||||
// Variant styling
|
||||
const variantClasses: Record<ButtonVariant, string> = {
|
||||
primary:
|
||||
'bg-indigo-600 hover:bg-indigo-700 text-white shadow-sm shadow-indigo-200 focus:ring-indigo-500 border border-indigo-600',
|
||||
secondary:
|
||||
'bg-slate-100 hover:bg-slate-200 text-slate-700 focus:ring-slate-400 border border-slate-200',
|
||||
danger:
|
||||
'bg-rose-600 hover:bg-rose-700 text-white shadow-sm shadow-rose-200 focus:ring-rose-500 border border-rose-600',
|
||||
success:
|
||||
'bg-emerald-600 hover:bg-emerald-700 text-white shadow-sm shadow-emerald-200 focus:ring-emerald-500 border border-emerald-600',
|
||||
warning:
|
||||
'bg-amber-500 hover:bg-amber-600 text-white shadow-sm shadow-amber-200 focus:ring-amber-400 border border-amber-500',
|
||||
outline:
|
||||
'bg-white hover:bg-gray-50 text-gray-700 border border-gray-300 focus:ring-indigo-500',
|
||||
ghost:
|
||||
'bg-transparent hover:bg-gray-100 text-gray-600 focus:ring-gray-300 border border-transparent',
|
||||
};
|
||||
|
||||
const iconSizes: Record<ButtonSize, string> = {
|
||||
xs: 'w-3 h-3',
|
||||
sm: 'w-3.5 h-3.5',
|
||||
md: 'w-4 h-4',
|
||||
lg: 'w-5 h-5',
|
||||
};
|
||||
|
||||
return (
|
||||
<button
|
||||
disabled={disabled || isLoading}
|
||||
className={`
|
||||
${baseClasses}
|
||||
${sizeClasses[size]}
|
||||
${variantClasses[variant]}
|
||||
${fullWidth ? 'w-full' : ''}
|
||||
${className}
|
||||
`}
|
||||
{...props}
|
||||
>
|
||||
{isLoading ? (
|
||||
<Spinner size={size === 'lg' ? 'md' : 'sm'} />
|
||||
) : (
|
||||
<>
|
||||
{StartIcon && <StartIcon className={iconSizes[size]} />}
|
||||
{children && <span>{children}</span>}
|
||||
{badge !== undefined && (
|
||||
<span className="px-1.5 py-0.5 rounded-full text-[10px] bg-white/20 text-current font-mono">
|
||||
{badge}
|
||||
</span>
|
||||
)}
|
||||
{EndIcon && <EndIcon className={iconSizes[size]} />}
|
||||
{info && (
|
||||
<span
|
||||
className="inline-flex items-center text-current/80 hover:text-current cursor-help ml-0.5"
|
||||
title={info}
|
||||
>
|
||||
<Info className="w-3.5 h-3.5" />
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Eye, EyeOff, Copy, Check } from 'lucide-react';
|
||||
import { toast } from 'react-hot-toast';
|
||||
|
||||
interface MaskableFieldProps {
|
||||
value?: string | number | null;
|
||||
maskedValue?: string;
|
||||
isMaskedByDefault?: boolean;
|
||||
label?: string;
|
||||
copyable?: boolean;
|
||||
className?: string;
|
||||
valueClassName?: string;
|
||||
dir?: 'ltr' | 'rtl';
|
||||
}
|
||||
|
||||
export default function MaskableField({
|
||||
value,
|
||||
maskedValue,
|
||||
isMaskedByDefault = true,
|
||||
label,
|
||||
copyable = true,
|
||||
className = '',
|
||||
valueClassName = '',
|
||||
dir = 'ltr',
|
||||
}: MaskableFieldProps) {
|
||||
const [isRevealed, setIsRevealed] = useState(!isMaskedByDefault);
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
const rawVal = value !== undefined && value !== null ? String(value) : '';
|
||||
|
||||
// Create mask if not provided
|
||||
const generateMask = (str: string) => {
|
||||
if (!str) return '-';
|
||||
if (str.length <= 4) return '****';
|
||||
if (str.length === 16) {
|
||||
// 16-digit Card: 6037-99**-****-1234
|
||||
return `${str.slice(0, 4)}-${str.slice(4, 6)}**-****-${str.slice(12)}`;
|
||||
}
|
||||
const visibleStart = Math.min(4, Math.floor(str.length / 3));
|
||||
const visibleEnd = Math.min(4, Math.floor(str.length / 3));
|
||||
return `${str.slice(0, visibleStart)}${'*'.repeat(Math.max(4, str.length - visibleStart - visibleEnd))}${str.slice(-visibleEnd)}`;
|
||||
};
|
||||
|
||||
const displayMasked = maskedValue || generateMask(rawVal);
|
||||
const currentText = isRevealed ? (rawVal || '-') : displayMasked;
|
||||
|
||||
const handleCopy = (e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
if (!rawVal) return;
|
||||
navigator.clipboard.writeText(rawVal);
|
||||
setCopied(true);
|
||||
toast.success(`${label || 'مقدار'} در کلیپبورد کپی شد`);
|
||||
setTimeout(() => setCopied(false), 2000);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={`inline-flex items-center gap-1.5 ${className}`}>
|
||||
<span
|
||||
dir={dir}
|
||||
className={`font-mono text-xs select-all ${valueClassName}`}
|
||||
title={isRevealed ? 'مقدار واقعی' : 'مقدار پنهانشده'}
|
||||
>
|
||||
{currentText}
|
||||
</span>
|
||||
|
||||
{rawVal && (
|
||||
<div className="inline-flex items-center gap-1">
|
||||
{/* Toggle Eye Button */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setIsRevealed(!isRevealed);
|
||||
}}
|
||||
className="p-1 text-gray-400 hover:text-indigo-600 hover:bg-indigo-50 rounded-md transition-colors cursor-pointer"
|
||||
title={isRevealed ? 'پنهانسازی' : 'نمایش مقدار اصلی'}
|
||||
>
|
||||
{isRevealed ? <EyeOff className="w-3.5 h-3.5" /> : <Eye className="w-3.5 h-3.5" />}
|
||||
</button>
|
||||
|
||||
{/* Copy to Clipboard Button */}
|
||||
{copyable && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleCopy}
|
||||
className="p-1 text-gray-400 hover:text-emerald-600 hover:bg-emerald-50 rounded-md transition-colors cursor-pointer"
|
||||
title="کپی در کلیپبورد"
|
||||
>
|
||||
{copied ? <Check className="w-3.5 h-3.5 text-emerald-600" /> : <Copy className="w-3.5 h-3.5" />}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user