338 lines
16 KiB
TypeScript
338 lines
16 KiB
TypeScript
import React, { useState, useEffect } from 'react';
|
|
import { XCircle, CheckCircle, Check, Download, RefreshCw, Smartphone, PauseCircle } from 'lucide-react';
|
|
import type { VerificationResult, UserProfile } from '../../types';
|
|
import { formatDeepLinkRoute } from '../../utils/navigation';
|
|
|
|
interface PaymentSuccessModalProps {
|
|
verificationResult: VerificationResult;
|
|
onClose: () => void;
|
|
loggedInUser: UserProfile | null;
|
|
onDownloadInvoice: (paymentId: string, invoiceUrl?: string) => void;
|
|
downloadingInvoice: boolean;
|
|
returnRoute?: string;
|
|
appScheme?: string;
|
|
}
|
|
|
|
export const PaymentSuccessModal: React.FC<PaymentSuccessModalProps> = ({
|
|
verificationResult,
|
|
onClose,
|
|
loggedInUser,
|
|
onDownloadInvoice,
|
|
downloadingInvoice,
|
|
returnRoute,
|
|
appScheme,
|
|
}) => {
|
|
const [desktopNotice, setDesktopNotice] = useState(false);
|
|
const [countdown, setCountdown] = useState<number>(10);
|
|
const [isRedirectCancelled, setIsRedirectCancelled] = useState<boolean>(false);
|
|
const [isRedirecting, setIsRedirecting] = useState<boolean>(false);
|
|
|
|
// Enable 10-second auto-redirect countdown tile across all devices (iOS, Android, and web testing)
|
|
const showCountdown = true;
|
|
const route = formatDeepLinkRoute(returnRoute || 'modules');
|
|
|
|
// Launch mobile app across iOS, Android, and Desktop
|
|
const launchMobileApp = () => {
|
|
setIsRedirecting(true);
|
|
const userAgent = navigator.userAgent || '';
|
|
const isAndroid = /Android/i.test(userAgent);
|
|
const isIOS = /iPhone|iPad|iPod/i.test(userAgent);
|
|
|
|
if (isAndroid) {
|
|
// Android Intent format for Chrome / modern Android browsers
|
|
const intentUrl = `intent://${route}#Intent;scheme=acupedia;package=com.anonymous.acupedia;end`;
|
|
window.location.href = intentUrl;
|
|
|
|
setTimeout(() => {
|
|
window.location.href = `acupedia://${route}`;
|
|
}, 500);
|
|
setTimeout(() => {
|
|
window.location.href = `myapp://${route}`;
|
|
}, 1000);
|
|
} else if (isIOS) {
|
|
// iOS Safari and Chrome handle custom URI schemes directly
|
|
const primaryScheme = appScheme || 'acupedia';
|
|
window.location.href = `${primaryScheme}://${route}`;
|
|
|
|
// Fallback in case alternate scheme was registered in Expo
|
|
setTimeout(() => {
|
|
window.location.href = `acupedia://${route}`;
|
|
}, 400);
|
|
setTimeout(() => {
|
|
window.location.href = `myapp://${route}`;
|
|
}, 900);
|
|
} else {
|
|
// Desktop
|
|
window.location.href = `acupedia://${route}`;
|
|
setDesktopNotice(true);
|
|
}
|
|
};
|
|
|
|
// 10-second auto-redirect countdown for mobile & web app testing
|
|
useEffect(() => {
|
|
if (!showCountdown || isRedirectCancelled || isRedirecting) return;
|
|
|
|
if (countdown <= 0) {
|
|
launchMobileApp();
|
|
return;
|
|
}
|
|
|
|
const timer = setInterval(() => {
|
|
setCountdown((prev) => {
|
|
if (prev <= 1) {
|
|
clearInterval(timer);
|
|
launchMobileApp();
|
|
return 0;
|
|
}
|
|
return prev - 1;
|
|
});
|
|
}, 1000);
|
|
|
|
return () => clearInterval(timer);
|
|
}, [countdown, showCountdown, isRedirectCancelled, isRedirecting]);
|
|
|
|
const handleDownloadInvoiceClick = () => {
|
|
setIsRedirectCancelled(true);
|
|
onDownloadInvoice(verificationResult.paymentId || '', verificationResult.invoiceUrl);
|
|
};
|
|
|
|
const handleClose = () => {
|
|
setIsRedirectCancelled(true);
|
|
onClose();
|
|
};
|
|
return (
|
|
<div className="fixed inset-0 z-[100] flex items-center justify-center p-3 sm:p-4 bg-slate-950/75 backdrop-blur-md transition-all duration-300 overflow-y-auto">
|
|
<div className="relative w-full max-w-xl bg-slate-900 border border-slate-800 rounded-2xl p-4 sm:p-5 md:p-6 space-y-3 sm:space-y-4 shadow-2xl text-slate-100 max-h-[92vh] overflow-y-auto my-auto animate-in fade-in zoom-in-95 duration-200">
|
|
{/* Ambient Background Glow */}
|
|
<div className="absolute -top-10 left-1/2 -translate-x-1/2 w-48 h-48 bg-emerald-500/10 rounded-full blur-3xl pointer-events-none" />
|
|
|
|
{/* Close button */}
|
|
<button
|
|
onClick={handleClose}
|
|
className="absolute top-3 right-3 h-7 w-7 rounded-full bg-slate-800 hover:bg-slate-700/80 flex items-center justify-center text-slate-400 hover:text-slate-200 transition-colors"
|
|
>
|
|
<XCircle className="h-4 w-4" />
|
|
</button>
|
|
|
|
{/* Glowing animated green checkmark */}
|
|
<div className="text-center space-y-2 relative z-10">
|
|
<div
|
|
className="inline-flex items-center justify-center h-12 w-12 rounded-full bg-emerald-950/80 border border-emerald-500/30 text-emerald-400 shadow-[0_0_20px_rgba(16,185,129,0.25)] animate-bounce"
|
|
style={{ animationDuration: '2.5s' }}
|
|
>
|
|
<CheckCircle className="h-7 w-7" />
|
|
</div>
|
|
<h3 className="text-lg font-black tracking-tight text-white">
|
|
Thank You for Your Purchase!
|
|
</h3>
|
|
<p className="text-[10px] text-emerald-400 font-extrabold uppercase tracking-wider bg-emerald-950/50 border border-emerald-800/60 px-3 py-1 rounded-full inline-block">
|
|
Clinical Modules Unlocked Successfully
|
|
</p>
|
|
</div>
|
|
|
|
{/* 📱 10-Second Auto-Redirect Tile */}
|
|
{showCountdown && !isRedirectCancelled && (
|
|
<div className="bg-gradient-to-r from-indigo-950/90 via-slate-900 to-indigo-950/90 border border-indigo-500/40 rounded-xl p-3 space-y-2 relative z-10 shadow-lg shadow-indigo-950/40 animate-in fade-in slide-in-from-top-2 duration-300">
|
|
<div className="flex items-center justify-between gap-2.5">
|
|
<div className="flex items-center gap-2.5 min-w-0">
|
|
<div className="h-8 w-8 rounded-lg bg-indigo-500/20 border border-indigo-500/40 flex items-center justify-center text-indigo-400 flex-shrink-0">
|
|
<Smartphone className="h-4 w-4 animate-pulse" />
|
|
</div>
|
|
<div className="min-w-0 text-left">
|
|
<p className="text-xs font-bold text-white flex items-center gap-1.5">
|
|
<span>Returning to Acupedia App</span>
|
|
<span className="inline-flex items-center justify-center bg-indigo-600 text-white font-mono text-[10px] font-extrabold px-1.5 py-0.5 rounded-md min-w-[22px]">
|
|
{countdown}s
|
|
</span>
|
|
</p>
|
|
<p className="text-[10px] text-slate-400 font-medium">
|
|
Redirecting automatically if no action taken
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<button
|
|
type="button"
|
|
onClick={() => setIsRedirectCancelled(true)}
|
|
className="flex-shrink-0 px-2.5 py-1 bg-slate-800 hover:bg-slate-700/80 border border-slate-600/80 hover:border-slate-500 text-slate-200 hover:text-white text-[11px] font-bold rounded-lg transition-colors cursor-pointer flex items-center gap-1"
|
|
title="Pause redirect and stay on page"
|
|
>
|
|
<PauseCircle className="h-3 w-3 text-indigo-400" />
|
|
<span>Stay on Web</span>
|
|
</button>
|
|
</div>
|
|
|
|
{/* Countdown progress bar */}
|
|
<div className="w-full h-1.5 bg-slate-800/80 rounded-full overflow-hidden">
|
|
<div
|
|
className="h-full bg-gradient-to-r from-indigo-500 to-emerald-400 rounded-full transition-all duration-1000 ease-linear"
|
|
style={{ width: `${(countdown / 10) * 100}%` }}
|
|
/>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{/* Banner shown if redirect is cancelled */}
|
|
{showCountdown && isRedirectCancelled && (
|
|
<div className="bg-slate-950/70 border border-slate-800 rounded-xl px-3 py-2 flex items-center justify-between text-[11px] text-slate-400 relative z-10 animate-in fade-in duration-200">
|
|
<span className="flex items-center gap-1.5">
|
|
<span className="h-1.5 w-1.5 rounded-full bg-amber-400" />
|
|
Auto-redirect paused. Take your time to download your invoice.
|
|
</span>
|
|
<button
|
|
type="button"
|
|
onClick={launchMobileApp}
|
|
className="text-emerald-400 hover:text-emerald-300 font-bold ml-2 underline cursor-pointer flex-shrink-0"
|
|
>
|
|
Open App Now
|
|
</button>
|
|
</div>
|
|
)}
|
|
|
|
{/* Content: Mobile App Access Onboarding */}
|
|
<div className="bg-slate-950 border border-slate-800/80 rounded-xl p-3.5 space-y-2.5 relative z-10">
|
|
<p className="text-[11px] text-slate-300 leading-relaxed font-semibold text-center">
|
|
Your subscription entitlements are active! Access your content inside the{' '}
|
|
<span className="text-indigo-400 font-bold">Acupedia Mobile App</span>. Log in with:{' '}
|
|
<span className="text-white underline font-bold">
|
|
{loggedInUser?.email || 'your registered email'}
|
|
</span>
|
|
.
|
|
</p>
|
|
|
|
{/* App download badges */}
|
|
<div className="flex justify-center items-center gap-2.5">
|
|
{/* Apple App Store */}
|
|
<a
|
|
href="#appstore"
|
|
onClick={(e) => e.preventDefault()}
|
|
className="flex items-center gap-2 bg-slate-900 hover:bg-slate-800 text-white px-3 py-1.5 rounded-lg border border-slate-800 hover:border-slate-700 transition-all duration-300 shadow-sm group"
|
|
>
|
|
<svg className="w-3.5 h-3.5 fill-current text-slate-300 group-hover:text-white transition-colors" viewBox="0 0 24 24">
|
|
<path d="M18.71,19.5 C17.88,20.74 17,21.95 15.66,21.97 C14.32,22 13.89,21.18 12.37,21.18 C10.84,21.18 10.37,21.95 9.1,22 C7.79,22.05 6.8,20.68 5.96,19.48 C4.25,17 2.94,12.45 4.7,9.39 C5.57,7.87 7.13,6.91 8.82,6.88 C10.1,6.86 11.32,7.75 12.11,7.75 C12.89,7.75 14.37,6.68 15.92,6.84 C16.57,6.87 18.39,7.1 19.56,8.82 C19.47,8.88 17.39,10.1 17.41,12.63 C17.44,15.65 20.06,16.66 20.1,16.67 C20.08,16.74 19.67,18.11 18.71,19.5 M15.97,4.17 C16.63,3.37 17.07,2.28 16.95,1 C16,1.04 14.9,1.6 14.24,2.38 C13.68,3.04 13.19,4.14 13.34,5.39 C14.39,5.47 15.4,4.88 15.97,4.17 Z" />
|
|
</svg>
|
|
<div className="text-left leading-none">
|
|
<p className="text-[7px] text-slate-400 font-bold uppercase tracking-wider mb-0.5">Download on the</p>
|
|
<p className="text-[11px] font-black text-slate-200 group-hover:text-white transition-colors">App Store</p>
|
|
</div>
|
|
</a>
|
|
|
|
{/* Google Play Store */}
|
|
<a
|
|
href="#playstore"
|
|
onClick={(e) => e.preventDefault()}
|
|
className="flex items-center gap-2 bg-slate-900 hover:bg-slate-800 text-white px-3 py-1.5 rounded-lg border border-slate-800 hover:border-slate-700 transition-all duration-300 shadow-sm group"
|
|
>
|
|
<svg className="w-3.5 h-3.5 fill-current text-slate-300 group-hover:text-white transition-colors" viewBox="0 0 24 24">
|
|
<path d="M3,5.27V18.73L16.55,12L3,5.27M17.87,11.33L21,12.92C21.67,13.25 21.67,13.75 21,14.08L17.87,15.67L15,12L17.87,11.33M3,3C3.58,3 4.2,3.22 4.67,3.58L16,11.08L13.13,12L3,3M3,21L13.13,12L16,12.92L4.67,20.42C4.2,20.78 3.58,21 3,21Z" />
|
|
</svg>
|
|
<div className="text-left leading-none">
|
|
<p className="text-[7px] text-slate-400 font-bold uppercase tracking-wider mb-0.5">Get it on</p>
|
|
<p className="text-[11px] font-black text-slate-200 group-hover:text-white transition-colors">Google Play</p>
|
|
</div>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Details listing: ID, Invoice, Amount, Items */}
|
|
<div className="bg-slate-950/60 border border-slate-800/80 rounded-xl p-3.5 space-y-2.5 text-[11px] relative z-10">
|
|
<div className="flex justify-between items-center text-slate-400 font-semibold">
|
|
<span>Invoice</span>
|
|
<div className="flex items-center gap-1.5">
|
|
<span className="text-white font-mono font-bold bg-slate-800 px-2 py-0.5 rounded text-[10px] border border-slate-700/50">
|
|
{verificationResult.invoiceNumber}
|
|
</span>
|
|
{verificationResult.invoiceNumber && (
|
|
<button
|
|
onClick={handleDownloadInvoiceClick}
|
|
disabled={downloadingInvoice}
|
|
className="text-indigo-400 hover:text-indigo-300 transition-colors p-0.5 cursor-pointer"
|
|
title="Download Invoice PDF"
|
|
>
|
|
<Download className="h-3 w-3" />
|
|
</button>
|
|
)}
|
|
</div>
|
|
</div>
|
|
<div className="flex justify-between items-center text-slate-400 font-semibold gap-2">
|
|
<span className="shrink-0">Payment ID</span>
|
|
<span className="text-white font-mono font-bold bg-slate-800 px-2 py-0.5 rounded text-[10px] border border-slate-700/50 break-all text-right">
|
|
{verificationResult.paymentId}
|
|
</span>
|
|
</div>
|
|
<div className="flex justify-between items-center text-slate-400 font-semibold">
|
|
<span>Amount Paid</span>
|
|
<span className="text-indigo-400 font-extrabold text-xs">
|
|
{verificationResult.currency === 'INR'
|
|
? `₹${verificationResult.amount}`
|
|
: verificationResult.currency === 'EUR'
|
|
? `€${verificationResult.amount}`
|
|
: `$${verificationResult.amount}`}
|
|
</span>
|
|
</div>
|
|
|
|
<div className="h-px bg-slate-800/85" />
|
|
|
|
<div className="space-y-1 text-left">
|
|
<span className="text-[9px] text-slate-500 font-bold uppercase tracking-wider block">
|
|
Unlocked Modules
|
|
</span>
|
|
<div className="flex flex-wrap gap-1">
|
|
{verificationResult.items?.map((itemName: string, idx: number) => (
|
|
<span
|
|
key={idx}
|
|
className="bg-indigo-950/50 text-indigo-300 border border-indigo-900/60 text-[9px] font-bold px-2 py-0.5 rounded-md flex items-center gap-1 shadow-sm"
|
|
>
|
|
<Check className="h-2 w-2 text-indigo-400" /> {itemName}
|
|
</span>
|
|
))}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Action buttons */}
|
|
<div className="space-y-2 relative z-10 mt-2">
|
|
{verificationResult.invoiceNumber && (
|
|
<button
|
|
onClick={handleDownloadInvoiceClick}
|
|
disabled={downloadingInvoice}
|
|
className="w-full h-9 bg-slate-800 hover:bg-slate-700/80 border border-slate-700 text-white font-bold text-xs rounded-lg transition-all duration-300 flex items-center justify-center gap-2 shadow-md cursor-pointer"
|
|
>
|
|
{downloadingInvoice ? (
|
|
<RefreshCw className="h-3.5 w-3.5 animate-spin text-indigo-400" />
|
|
) : (
|
|
<Download className="h-3.5 w-3.5 text-indigo-400" />
|
|
)}
|
|
{downloadingInvoice ? 'Downloading...' : 'Download Invoice PDF'}
|
|
</button>
|
|
)}
|
|
|
|
{/* Open in App Button */}
|
|
<button
|
|
onClick={launchMobileApp}
|
|
className="w-full h-9 bg-emerald-600 hover:bg-emerald-500 text-white font-bold text-xs rounded-lg transition-all duration-300 flex items-center justify-center gap-2 shadow-md shadow-emerald-600/10 cursor-pointer"
|
|
>
|
|
<Smartphone className="h-3.5 w-3.5 text-emerald-200" />
|
|
Open in App / Library
|
|
</button>
|
|
|
|
{desktopNotice && (
|
|
<div className="p-2.5 bg-slate-950 border border-emerald-900/40 rounded-lg text-center animate-in fade-in duration-200">
|
|
<p className="text-[11px] text-emerald-400 font-medium">
|
|
📱 Attempted to launch Acupedia App. If you are on desktop, please open the Acupedia App on your mobile device to view your unlocked content.
|
|
</p>
|
|
</div>
|
|
)}
|
|
|
|
<button
|
|
onClick={handleClose}
|
|
className="w-full h-9 bg-indigo-600 hover:bg-indigo-500 text-white font-bold text-xs rounded-lg transition-all duration-300 flex items-center justify-center gap-2 shadow-md shadow-indigo-600/10 cursor-pointer"
|
|
>
|
|
Return to Storefront
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|