Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions src/components/checkout/PaymentSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@
PayPalPaymentForm,
type PayPalPaymentFormHandle,
} from "@/components/checkout/PayPalPaymentForm";
import {
RazorpayPaymentForm,
type RazorpayPaymentFormHandle,
} from "@/components/checkout/RazorpayPaymentForm";

Check failure on line 35 in src/components/checkout/PaymentSection.tsx

View workflow job for this annotation

GitHub Actions / Type Check

Cannot find module '@/components/checkout/RazorpayPaymentForm' or its corresponding type declarations.
import {
confirmWithSavedCard,
StripePaymentForm,
type StripePaymentFormHandle,
} from "@/components/checkout/StripePaymentForm";

import { Checkbox } from "@/components/ui/checkbox";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
import { useCountryStates } from "@/hooks/useCountryStates";
Expand Down Expand Up @@ -158,12 +163,15 @@
const [paymentSessionId, setPaymentSessionId] = useState<string | null>(null);
const [gatewayError, setGatewayError] = useState<string | null>(null);
const [loading, setLoading] = useState(false);

const gatewayHandleRef = useRef<
| StripePaymentFormHandle
| AdyenPaymentFormHandle
| PayPalPaymentFormHandle
| RazorpayPaymentFormHandle
| null
>(null);

const initRef = useRef(false);
const sessionRequestIdRef = useRef(0);
const completionInFlightRef = useRef(false);
Expand All @@ -173,7 +181,8 @@
handle:
| StripePaymentFormHandle
| AdyenPaymentFormHandle
| PayPalPaymentFormHandle,
| PayPalPaymentFormHandle
| RazorpayPaymentFormHandle,
) => {
gatewayHandleRef.current = handle;
},
Expand Down Expand Up @@ -517,8 +526,14 @@
| undefined;
const gatewayId = resolveGatewayId(selectedMethod.type);
const isStripe = gatewayId === "stripe";

// --- ADDED RAZORPAY TO APPROVAL FLAG ---
const isApprovalDriven =
gatewayId === "adyen" || gatewayId === "paypal";
gatewayId === "adyen" ||
gatewayId === "paypal" ||
gatewayId === "razorpay";
// ---------------------------------------

const canUseSavedCard =
isStripe && Boolean(selectedCardId && clientSecret);

Expand Down Expand Up @@ -548,7 +563,7 @@
return { error };
}

// Approval-driven gateways (Adyen, PayPal) complete the order
// Approval-driven gateways (Adyen, PayPal, Razorpay) complete the order
// via handleGatewayApproved when their callback fires — don't
// call onPaymentComplete here or we'll race with the callback.
if (isApprovalDriven) {
Expand Down Expand Up @@ -895,6 +910,19 @@
</div>
) : null;
}
case "razorpay": {
return ext ? (
<div className="p-4">
<RazorpayPaymentForm
key={ext._external_id as string}
sessionData={ext}
cart={cart}
onReady={handleGatewayReady}
onApproved={handleGatewayApproved}
/>
</div>
) : null;
}
default:
return (
<div className="px-4 py-6 text-center">
Expand Down
Loading