From 4f2e83228304f629388a96139612d0e2bc157039 Mon Sep 17 00:00:00 2001 From: ShivaniKhaire Date: Sat, 3 Oct 2026 17:25:48 +0530 Subject: [PATCH] fix(checkout): ensure "Open in App" button reliably launches mobile app (#7) --- src/App.tsx | 11 +++- .../checkout/PaymentSuccessModal.tsx | 53 +++++++++++++++++-- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 8c5ec65..1cbc898 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -658,9 +658,18 @@ export default function App() { message: verifyRes.data.message || 'Payment verified successfully and module entitlements unlocked!' }); + // If on mobile browser, automatically attempt to redirect to mobile app after successful payment if (/Android|iPhone|iPad|iPod/i.test(navigator.userAgent)) { setTimeout(() => { - window.location.href = 'acupedia://'; + if (/Android/i.test(navigator.userAgent)) { + // Use Android Intent format to avoid blocked navigation in Android Chrome + window.location.href = 'intent://#Intent;scheme=acupedia;package=com.anonymous.acupedia;end'; + setTimeout(() => { + window.location.href = 'acupedia://'; + }, 500); + } else { + window.location.href = 'acupedia://'; + } }, 1500); } diff --git a/src/components/checkout/PaymentSuccessModal.tsx b/src/components/checkout/PaymentSuccessModal.tsx index f665a26..234bbfe 100644 --- a/src/components/checkout/PaymentSuccessModal.tsx +++ b/src/components/checkout/PaymentSuccessModal.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import { XCircle, CheckCircle, Check, Download, RefreshCw, Smartphone } from 'lucide-react'; import type { VerificationResult, UserProfile } from '../../types'; @@ -17,6 +17,42 @@ export const PaymentSuccessModal: React.FC = ({ onDownloadInvoice, downloadingInvoice, }) => { + const [desktopNotice, setDesktopNotice] = useState(false); + + // Handler to reliably launch the Acupedia Mobile App across platforms (Android, iOS, and Desktop) + const handleOpenApp = (e: React.MouseEvent) => { + e.preventDefault(); + const userAgent = navigator.userAgent || ''; + const isAndroid = /Android/i.test(userAgent); + const isIOS = /iPhone|iPad|iPod/i.test(userAgent); + + if (isAndroid) { + // Android Chrome requires an Intent URI format to launch apps by package and scheme reliably + const intentUrl = 'intent://#Intent;scheme=acupedia;package=com.anonymous.acupedia;end'; + window.location.href = intentUrl; + + // Fallback to custom URI schemes in case intent fails or Expo uses alternate scheme + setTimeout(() => { + window.location.href = 'acupedia://'; + }, 500); + setTimeout(() => { + window.location.href = 'myapp://'; + }, 1000); + } else if (isIOS) { + // iOS Safari and Chrome handle custom URI schemes directly + window.location.href = 'acupedia://'; + + // Fallback in case Expo uses default 'myapp://' scheme + setTimeout(() => { + window.location.href = 'myapp://'; + }, 500); + } else { + // On desktop browsers, try opening the registered custom scheme + window.location.href = 'acupedia://'; + // Show helpful desktop feedback informing the user how to access content on mobile + setDesktopNotice(true); + } + }; return (
@@ -175,14 +211,25 @@ export const PaymentSuccessModal: React.FC = ({ )} + {/* Open in App Button */} - Open Acupedia Mobile App + Open in App + {desktopNotice && ( +
+

+ 📱 Attempted to launch Acupedia App. If you are on desktop, please open the Acupedia App on your mobile device to view your unlocked content. +

+
+ )} +