diff --git a/src/pages/CheckoutPage.tsx b/src/pages/CheckoutPage.tsx index 8788a23..0f72ed5 100644 --- a/src/pages/CheckoutPage.tsx +++ b/src/pages/CheckoutPage.tsx @@ -6,9 +6,6 @@ import { PaymentMethodList } from '../features/payments/components/PaymentMethod import type { PaymentMethod } from '../features/payments/components/PaymentMethodList' import { SnapPaymentTrigger } from '../features/payments/snap/SnapPaymentTrigger' import { usePaymentConfig } from '../features/payments/lib/usePaymentConfig' -import { Logger } from '../lib/logger' -import React from 'react' - interface AutoSnapPaymentProps { orderId: string amount: number @@ -24,7 +21,8 @@ function AutoSnapPayment({ orderId, amount, customer, onChargeInitiated, onSucce const hasTriggered = React.useRef(false) React.useEffect(() => { - if (hasTriggered.current) return + // Only trigger when we have valid orderId and amount + if (!orderId || !amount || hasTriggered.current) return hasTriggered.current = true const triggerPayment = async () => { @@ -97,6 +95,18 @@ function AutoSnapPayment({ orderId, amount, customer, onChargeInitiated, onSucce return () => clearTimeout(timer) }, [orderId, amount, customer, onChargeInitiated, onSuccess, onError]) + // Don't render anything until we have valid data + if (!orderId || !amount) { + return ( +
+
+
+

Memuat data pembayaran...

+
+
+ ) + } + return (
{error && ( diff --git a/src/pages/PayPage.tsx b/src/pages/PayPage.tsx index 09c6f00..1f0ffba 100644 --- a/src/pages/PayPage.tsx +++ b/src/pages/PayPage.tsx @@ -27,7 +27,8 @@ function AutoSnapPayment({ orderId, amount, customer, onChargeInitiated, onSucce const hasTriggered = React.useRef(false) React.useEffect(() => { - if (hasTriggered.current) return + // Only trigger when we have valid orderId and amount + if (!orderId || !amount || hasTriggered.current) return hasTriggered.current = true const triggerPayment = async () => { @@ -100,6 +101,18 @@ function AutoSnapPayment({ orderId, amount, customer, onChargeInitiated, onSucce return () => clearTimeout(timer) }, [orderId, amount, customer, onChargeInitiated, onSuccess, onError]) + // Don't render anything until we have valid data + if (!orderId || !amount) { + return ( +
+
+
+

Memuat data pembayaran...

+
+
+ ) + } + return (
{error && (