"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2569],{2569:function(e,n,r){r.r(n),r.d(n,{default:function(){return razorpay_payment_modal}});var a=r(85893),t=r(67294),use_razorpay=()=>{let e=(0,t.useMemo)(()=>!0,[]),n=(0,t.useCallback)(()=>!!(e&&"Razorpay"in window),[]),r=(0,t.useCallback)(()=>{if(e)return new Promise((e,n)=>{let r=document.createElement("script");r.src="https://checkout.razorpay.com/v1/checkout.js",r.onload=n=>e(n),r.onerror=e=>n(e),document.body.appendChild(r)})},[]);return{checkScriptLoaded:n,loadRazorpayScript:r}},o=r(71798),l=r(5233),i=r(45009),u=r(52324),c=r(44555),s=r(34483),d=r(83454),razorpay_payment_modal=e=>{let{trackingNumber:n,paymentIntentInfo:r}=e,{t:m}=(0,l.$G)(),{closeModal:p}=(0,i.SO)(),{loadRazorpayScript:y,checkScriptLoaded:_}=use_razorpay(),{settings:f,isLoading:v}=(0,u.r)(),{order:k,isLoading:w,refetch:b}=(0,c.Aj)({tracking_number:n}),{createOrderPayment:h}=(0,c.fY)(),{customer_name:z,customer_contact:g,customer:j,billing_address:C}=null!=k?k:{},E=(0,t.useCallback)(async()=>{var e;_()||await y();let a={key:d.env.NEXT_PUBLIC_RAZORPAY_KEY_ID,amount:null==r?void 0:r.amount,currency:null==r?void 0:r.currency,name:z,description:"".concat(m("text-order"),"#").concat(n),image:null==f?void 0:null===(e=f.logo)||void 0===e?void 0:e.original,order_id:null==r?void 0:r.payment_id,handler:async()=>{p(),h({tracking_number:n,payment_gateway:"razorpay"})},prefill:{...z&&{name:z},...g&&{contact:"+".concat(g)},...(null==j?void 0:j.email)&&{email:null==j?void 0:j.email}},notes:{address:(0,o.T)(C)},modal:{ondismiss:async()=>{p(),await b()}}},t=window.Razorpay(a);return t.open()},[w,v]);return((0,t.useEffect)(()=>{w||v||(async()=>{await E()})()},[w,v]),w||v)?(0,a.jsx)(s.ZP,{showText:!1}):null}},71798:function(e,n,r){r.d(n,{T:function(){return formatAddress}});function formatAddress(e){if(!e)return;let n=["street_address","state","city","zip","country"].reduce((n,r)=>({...n,[r]:e[r]}),{}),r=Object.fromEntries(Object.entries(n).filter(e=>{let[n,r]=e;return!!r}));return Object.values(r).join(", ")}}}]);