diff --git a/components/payment/paymentComponent.jsx b/components/payment/paymentComponent.jsx index 6a9c075..eb45c40 100644 --- a/components/payment/paymentComponent.jsx +++ b/components/payment/paymentComponent.jsx @@ -11,8 +11,15 @@ const PaymentComponent = ({ amount, onSuccess }) => { const [error, setError] = useState(null); const [isProcessing, setIsProcessing] = useState(false); const [usdAmount, setUsdAmount] = useState(null); - const [userData, setUserData] = useState({ name: "", email: "", contact: "" }); const [showPopup, setShowPopup] = useState(false); + const [shippingData, setShippingData] = useState({ + address_line_1: "", + address_line_2: "", + state: "", + city: "", + country_code: "", + postal_code: "", + }); useEffect(() => { const fetchExchangeRate = async () => { @@ -71,13 +78,21 @@ const PaymentComponent = ({ amount, onSuccess }) => { }; const handlePaymentSuccess = (response) => { - onSuccess?.(response); + onSuccess?.({ + ...response, + shippingData, // Include the shipping data in the success callback + }); }; const handleRazorpayPayment = async () => { + if (!shippingData.address_line_1 || !shippingData.city || !shippingData.postal_code) { + setError("Please fill in all required fields."); + return; + } + try { const order = await createOrder(); - + console.log(shippingData) const options = { key: "rzp_test_1SbLmNX2nCKRZA", amount: order.amount, @@ -86,11 +101,12 @@ const PaymentComponent = ({ amount, onSuccess }) => { description: "", order_id: order.id, prefill: { - name: userData.name, - email: userData.email, - contact: userData.contact, + name: shippingData.address_line_1, + email: shippingData.address_line_2, + contact: shippingData.city, }, handler: (response) => { + response.address = shippingData handlePaymentSuccess(response); // Pass the response to the success handler }, }; @@ -172,7 +188,7 @@ const PaymentComponent = ({ amount, onSuccess }) => {