@quantaroute/checkout 1.8.2 → 1.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/embed/quantaroute-checkout.css +1 -1
- package/dist/embed/quantaroute-checkout.js +1 -1
- package/dist/lib/index.d.ts +11 -1
- package/dist/lib/quantaroute-checkout.es.js +88 -80
- package/dist/lib/quantaroute-checkout.umd.js +59 -51
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/SavedAddressStep.tsx +100 -7
- package/src/core/types.ts +11 -1
- package/src/styles/checkout.css +61 -0
|
@@ -61,7 +61,7 @@ if(429===i.status)throw new Error("Rate limit exceeded.")
|
|
|
61
61
|
let e=""
|
|
62
62
|
try{e=await i.text()}catch{}throw new Error(`Pincode validation failed (${i.status}): ${e||i.statusText}`)}const o=await i.json()
|
|
63
63
|
if(!o.success||!o.data)throw new Error(o.message??"Pincode validation failed.")
|
|
64
|
-
return o.data}function T(e){return e.some(e=>"delivery"===(e.delivery??"").trim().toLowerCase())}function
|
|
64
|
+
return o.data}function T(e){return e.some(e=>"delivery"===(e.delivery??"").trim().toLowerCase())}function I(e){return q(e)}function P(e){return _(e)}async function B(e,r,n=x,a=5,t,i){let o,l=`${n.replace(/\/$/,"")}/v1/digipin/autocomplete?q=${encodeURIComponent(e.trim())}&limit=${Math.min(a,10)}`
|
|
65
65
|
"number"==typeof t&&"number"==typeof i&&(l+=`&lat=${t.toFixed(6)}&lng=${i.toFixed(6)}`)
|
|
66
66
|
try{o=await fetch(l,{method:"GET",headers:{"x-api-key":r},signal:E(8e3)})}catch(e){if(e instanceof Error&&("TimeoutError"===e.name||"AbortError"===e.name))throw new Error("Autocomplete request timed out.")
|
|
67
67
|
throw new Error(`Network error: ${e instanceof Error?e.message:String(e)}`)}if(!o.ok){if(401===o.status||403===o.status)throw new Error("Invalid API key.")
|
|
@@ -75,13 +75,13 @@ try{e=await t.text()}catch{}if(401===t.status||403===t.status)throw new Error("I
|
|
|
75
75
|
if(429===t.status)throw new Error("Rate limit exceeded. Upgrade your plan or try again later.")
|
|
76
76
|
throw new Error(`API error ${t.status}: ${e||t.statusText}`)}const i=await t.json()
|
|
77
77
|
if(!i.success)throw new Error(i.message??"Reverse geocoding failed")
|
|
78
|
-
return i}function
|
|
78
|
+
return i}function M(){const[e,r]=t({loading:!1,error:null})
|
|
79
79
|
return{...e,locate:i(e=>{navigator.geolocation?(r({loading:!0,error:null}),navigator.geolocation.getCurrentPosition(({coords:n})=>{r({loading:!1,error:null}),e(n.latitude,n.longitude)},e=>{let n="Unable to get location."
|
|
80
|
-
e.code===e.PERMISSION_DENIED?n="Location permission denied. Please enable it in browser settings.":e.code===e.POSITION_UNAVAILABLE?n="Location unavailable. Try again or place the pin manually.":e.code===e.TIMEOUT&&(n="Location request timed out. Try again."),r({loading:!1,error:n})},{enableHighAccuracy:!0,timeout:12e3,maximumAge:0})):r({loading:!1,error:"Geolocation is not supported by your browser."})},[]),clearError:i(()=>{r(e=>({...e,error:null}))},[])}}const
|
|
81
|
-
function F(e,r){return e||(r?R[r]:
|
|
80
|
+
e.code===e.PERMISSION_DENIED?n="Location permission denied. Please enable it in browser settings.":e.code===e.POSITION_UNAVAILABLE?n="Location unavailable. Try again or place the pin manually.":e.code===e.TIMEOUT&&(n="Location request timed out. Try again."),r({loading:!1,error:n})},{enableHighAccuracy:!0,timeout:12e3,maximumAge:0})):r({loading:!1,error:"Geolocation is not supported by your browser."})},[]),clearError:i(()=>{r(e=>({...e,error:null}))},[])}}const O="https://maps.quantaroute.com/styles/quantaroute.json",D="https://maps.quantaroute.com/styles/quantaroute-pro-light.json",$="https://maps.quantaroute.com/styles/quantaroute-pro-dark.json",R={pro:O,light:D,dark:$},U="https://maps.quantaroute.com/styles.json"
|
|
81
|
+
function F(e,r){return e||(r?R[r]:O)}const j="https://maps.quantaroute.com"
|
|
82
82
|
function W(e,r){if(!r||!e.startsWith(j))return e
|
|
83
83
|
try{const n=new URL(e)
|
|
84
|
-
return n.searchParams.set("key",r),n.toString()}catch{return e}}function z(e){if(e)return r=>r.startsWith(j)?{url:W(r,e)}:{url:r}}const V="https://maps.quantaroute.com/geojson/india.geojson",J=
|
|
84
|
+
return n.searchParams.set("key",r),n.toString()}catch{return e}}function z(e){if(e)return r=>r.startsWith(j)?{url:W(r,e)}:{url:r}}const V="https://maps.quantaroute.com/geojson/india.geojson",J=O,H="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",K="https://tiles.openfreemap.org/styles/positron"
|
|
85
85
|
function G(){if("undefined"==typeof window)return null
|
|
86
86
|
const e=window.maplibregl
|
|
87
87
|
return e&&"function"==typeof e.Map&&"function"==typeof e.Marker?e:null}function Q(e,r,n=8e3,a=100){const t=Date.now()
|
|
@@ -93,19 +93,19 @@ return l(),()=>{o=!0,null!==i&&window.clearTimeout(i)}}function Z(e,r){if(!C(e,r
|
|
|
93
93
|
try{return w(e,r)}catch{return null}}const Y="#0ea5e9"
|
|
94
94
|
function X(e=Y){const r=document.createElement("div")
|
|
95
95
|
return r.className="qr-pin",r.setAttribute("aria-label","Drag to adjust your location"),r.style.width="40px",r.style.height="52px",r.innerHTML=`\n <svg\n class="qr-pin__svg"\n width="40"\n height="52"\n viewBox="0 0 40 52"\n overflow="visible"\n fill="none"\n xmlns="http://www.w3.org/2000/svg"\n aria-hidden="true"\n >\n <defs>\n \x3c!--\n The filter region must be generous enough to contain the shadow blur.\n stdDeviation=3 → ~9px blur radius; our region extends 50% on each side.\n overflow="visible" on the <svg> lets it paint outside the viewport.\n --\x3e\n <filter id="qr-pin-shadow" x="-60%" y="-40%" width="220%" height="220%">\n <feDropShadow dx="0" dy="3" stdDeviation="3.5"\n flood-color="#000" flood-opacity="0.28"/>\n </filter>\n </defs>\n\n \x3c!-- Teardrop body — tip is at (20, 52) = bottom-center of the SVG --\x3e\n <path\n d="M20 0C9.402 0 0 9.402 0 20C0 34 20 52 20 52S40 34 40 20C40 9.402 30.598 0 20 0Z"\n fill="${e}"\n filter="url(#qr-pin-shadow)"\n />\n \x3c!-- Dot inside the pin --\x3e\n <circle cx="20" cy="20" r="9" fill="white"/>\n <circle cx="20" cy="20" r="5" fill="${e}"/>\n </svg>\n\n \x3c!--\n Pulse ring — position: absolute inside .qr-pin (position: relative).\n bottom: -(height/2) → bottom: -10px centres the 20×20 circle\n exactly at y = PIN_H = 52px = the pin tip coordinate.\n --\x3e\n <div class="qr-pin__pulse" aria-hidden="true"></div>\n `,r}function ee(e){const r=null==e?void 0:e.querySelector(".maplibregl-ctrl-attrib")
|
|
96
|
-
r instanceof HTMLElement&&(r.classList.add("maplibregl-compact"),r.classList.remove("maplibregl-compact-show"),r.removeAttribute("open"))}const re=({onLocationConfirm:a,defaultLat:d,defaultLng:c,mapHeight:h="380px",theme:p="light",indiaBoundaryUrl:m,enableSearch:y=!0,apiKey:f,apiBaseUrl:b,brandColor:v=Y,mapStyle:_,mapTheme:q,embedMode:w="bundled",mapsKey:k})=>{const C=F(_,q),x=o(null),E=o(null),S=o(null),L=d??13.00427,T=c??77.589291,A=void 0!==d&&void 0!==c,[
|
|
96
|
+
r instanceof HTMLElement&&(r.classList.add("maplibregl-compact"),r.classList.remove("maplibregl-compact-show"),r.removeAttribute("open"))}const re=({onLocationConfirm:a,defaultLat:d,defaultLng:c,mapHeight:h="380px",theme:p="light",indiaBoundaryUrl:m,enableSearch:y=!0,apiKey:f,apiBaseUrl:b,brandColor:v=Y,mapStyle:_,mapTheme:q,embedMode:w="bundled",mapsKey:k})=>{const C=F(_,q),x=o(null),E=o(null),S=o(null),L=d??13.00427,T=c??77.589291,A=void 0!==d&&void 0!==c,[O,D]=t(L),[$,R]=t(T),[U,j]=t(()=>Z(L,T)),[V,J]=t(!1),[H,K]=t("loading"),[G,re]=t(null),[ne,ae]=t(""),[te,ie]=t([]),[oe,le]=t(!1),[se,de]=t(null),[ce,ue]=t(!1),he=o(null),pe=o(0),me=o(null),ye=l(),{loading:fe,error:be,locate:ve,clearError:_e}=M(),ge=i((e,r)=>{D(e),R(r),j(Z(e,r))},[]),qe=i((e,r)=>{var n,a
|
|
97
97
|
ge(e,r),null==(n=E.current)||n.flyTo({center:[r,e],zoom:18,duration:900,essential:!0}),null==(a=S.current)||a.setLngLat([r,e])},[ge]),we=i(e=>{const r=e.target.value
|
|
98
98
|
ae(r),de(null),he.current&&clearTimeout(he.current)
|
|
99
99
|
const n=++pe.current,a=r.trim()
|
|
100
100
|
if(!a)return ie([]),ue(!1),void le(!1)
|
|
101
|
-
if(
|
|
101
|
+
if(I(a)){le(!1)
|
|
102
102
|
try{const e=N(a),r=parseFloat(e.latitude),n=parseFloat(e.longitude)
|
|
103
|
-
qe(r,n),ie([]),ue(!1),ae(g(a))}catch{de("Invalid DigiPin code")}}else{if(
|
|
103
|
+
qe(r,n),ie([]),ue(!1),ae(g(a))}catch{de("Invalid DigiPin code")}}else{if(P(a))return ie([]),ue(!1),void le(!1)
|
|
104
104
|
if(a.length<3)return ie([]),ue(!1),void le(!1)
|
|
105
|
-
le(!0),he.current=setTimeout(async()=>{try{const e=f??"",r=await B(a,e,b,5,
|
|
105
|
+
le(!0),he.current=setTimeout(async()=>{try{const e=f??"",r=await B(a,e,b,5,O,$)
|
|
106
106
|
if(n!==pe.current)return
|
|
107
107
|
ie(r),ue(r.length>0)}catch(e){if(n!==pe.current)return
|
|
108
|
-
de(e instanceof Error?e.message:"Search failed"),ie([]),ue(!1)}finally{n===pe.current&&le(!1)}},400)}},[f,b,qe,
|
|
108
|
+
de(e instanceof Error?e.message:"Search failed"),ie([]),ue(!1)}finally{n===pe.current&&le(!1)}},400)}},[f,b,qe,O,$]),Ne=i(e=>{var r
|
|
109
109
|
qe(e.coordinates.latitude,e.coordinates.longitude),he.current&&clearTimeout(he.current),pe.current+=1,le(!1),ae(""),ie([]),ue(!1),null==(r=me.current)||r.blur()},[qe]),ke=i(e=>{"Escape"===e.key&&(he.current&&clearTimeout(he.current),pe.current+=1,le(!1),ie([]),ue(!1),ae(""))},[])
|
|
110
110
|
s(()=>{if(!x.current)return
|
|
111
111
|
let e=!1,r=null,n=null
|
|
@@ -123,8 +123,8 @@ null==f||f.setLngLat([r.lng,r.lat]),u(r.lat,r.lng),y.easeTo({center:[r.lng,r.lat
|
|
|
123
123
|
E.current=i,n=o}catch(e){K("error"),re(e instanceof Error?e.message:"Map failed to initialize.")}}
|
|
124
124
|
return"external"===w?r=Q(i,()=>{e||(K("unavailable"),re("Map could not load. Check your connection and try again."))}):i(u),()=>{e=!0,null==r||r(),he.current&&clearTimeout(he.current),S.current=null,E.current=null,null==n||n()}},[v,w,A,m,L,T,k,C,ge])
|
|
125
125
|
const Ce=i(()=>{_e(),ve((e,r)=>{var n,a
|
|
126
|
-
ge(e,r),null==(n=E.current)||n.flyTo({center:[r,e],zoom:18,duration:1400,essential:!0}),null==(a=S.current)||a.setLngLat([r,e])})},[ve,_e,ge]),xe=i(()=>{U&&a(
|
|
127
|
-
return e("div",{className:"qr-map-wrapper",children:[e("div",{className:"qr-step-header",children:[r("div",{className:"qr-step-badge",children:"1"}),e("div",{className:"qr-step-text",children:[r("span",{className:"qr-step-title",children:"Pin Your Location"}),r("span",{className:"qr-step-sub",children:"Tap the map or drag the pin to your exact home / office"})]})]}),y&&e("div",{className:"qr-search-bar",role:"search",children:[e("div",{className:"qr-search-bar__input-wrap",children:[e("svg",{className:"qr-search-bar__icon","aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("circle",{cx:"11",cy:"11",r:"8"}),r("path",{d:"M21 21l-4.35-4.35"})]}),r("input",{ref:me,type:"search",className:"qr-search-bar__input",placeholder:"Search address, 'pharmacy near me', or DigiPin…",value:ne,onChange:we,onKeyDown:ke,autoComplete:"off",autoCorrect:"off",autoCapitalize:"characters",spellCheck:!1,"aria-label":"Search address or DigiPin","aria-autocomplete":"list","aria-controls":ce?ye:void 0,"aria-expanded":ce}),oe&&r("span",{className:"qr-search-bar__spinner qr-spinner qr-spinner--sm","aria-hidden":"true"}),ne&&!oe&&r("button",{type:"button",className:"qr-search-bar__clear",onClick:()=>{ae(""),ie([]),ue(!1),de(null)},"aria-label":"Clear search",tabIndex:-1,children:"×"})]}),se&&r("p",{className:"qr-search-bar__error",role:"alert",children:se}),ce&&te.length>0&&r("ul",{id:ye,className:"qr-search-bar__dropdown",role:"listbox","aria-label":"Address suggestions",children:te.map((n,a)=>e("li",{className:"qr-search-bar__suggestion",role:"option","aria-selected":"false",onMouseDown:e=>{e.preventDefault(),Ne(n)},children:[e("svg",{className:"qr-search-bar__suggestion-icon","aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r("path",{d:"M12 2C8.134 2 5 5.134 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.866-3.134-7-7-7z"}),r("circle",{cx:"12",cy:"9",r:"2.5"})]}),e("div",{className:"qr-search-bar__suggestion-text",children:[r("span",{className:"qr-search-bar__suggestion-name",children:n.displayName}),n.address&&n.address!==n.displayName&&r("span",{className:"qr-search-bar__suggestion-sub",children:n.address})]})]},a))}),e("p",{className:"qr-search-bar__hint",children:[r("span",{className:"qr-search-bar__hint-chip",children:"DigiPin"}),"Type your DigiPin code for instant offline lookup — no API call"]})]}),e("div",{className:"qr-map-outer",style:{height:h},children:[r("div",{ref:x,className:"qr-map-canvas"}),Le&&r("div",{className:"qr-map-notice",role:"loading"===H?"status":"alert",children:"loading"===H?e(n,{children:[r("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}),r("span",{children:"Loading map…"})]}):G??"Map is unavailable. Please try again."}),U&&e("div",{className:"qr-digipin-badge","aria-live":"polite","aria-label":`DigiPin: ${U}`,children:[r("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r("span",{className:"qr-digipin-badge__code",children:U})]}),!Ee&&V&&r("div",{className:"qr-map-notice",role:"status",children:"Move map to India to get a DigiPin"}),r("button",{className:"qr-locate-btn"+(fe?" qr-locate-btn--loading":""),onClick:Ce,disabled:fe||"ready"!==H,title:"Use my current location","aria-label":"Use my current location",type:"button",children:fe?r("span",{className:"qr-spinner","aria-hidden":"true"}):e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("circle",{cx:"12",cy:"12",r:"3",fill:"currentColor",stroke:"none"}),r("circle",{cx:"12",cy:"12",r:"7"}),r("path",{d:"M12 2v3M12 19v3M2 12h3M19 12h3"})]})}),be&&e("div",{className:"qr-geo-error",role:"alert",children:[r("span",{children:be}),r("button",{type:"button",className:"qr-geo-error__dismiss",onClick:_e,"aria-label":"Dismiss error",children:"×"})]})]}),V&&e("div",{className:"qr-coords-strip","aria-label":"Current pin coordinates",children:[e("span",{children:[
|
|
126
|
+
ge(e,r),null==(n=E.current)||n.flyTo({center:[r,e],zoom:18,duration:1400,essential:!0}),null==(a=S.current)||a.setLngLat([r,e])})},[ve,_e,ge]),xe=i(()=>{U&&a(O,$,U)},[O,$,U,a]),Ee=null!==U,Se=Ee&&V&&"ready"===H,Le="ready"!==H
|
|
127
|
+
return e("div",{className:"qr-map-wrapper",children:[e("div",{className:"qr-step-header",children:[r("div",{className:"qr-step-badge",children:"1"}),e("div",{className:"qr-step-text",children:[r("span",{className:"qr-step-title",children:"Pin Your Location"}),r("span",{className:"qr-step-sub",children:"Tap the map or drag the pin to your exact home / office"})]})]}),y&&e("div",{className:"qr-search-bar",role:"search",children:[e("div",{className:"qr-search-bar__input-wrap",children:[e("svg",{className:"qr-search-bar__icon","aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("circle",{cx:"11",cy:"11",r:"8"}),r("path",{d:"M21 21l-4.35-4.35"})]}),r("input",{ref:me,type:"search",className:"qr-search-bar__input",placeholder:"Search address, 'pharmacy near me', or DigiPin…",value:ne,onChange:we,onKeyDown:ke,autoComplete:"off",autoCorrect:"off",autoCapitalize:"characters",spellCheck:!1,"aria-label":"Search address or DigiPin","aria-autocomplete":"list","aria-controls":ce?ye:void 0,"aria-expanded":ce}),oe&&r("span",{className:"qr-search-bar__spinner qr-spinner qr-spinner--sm","aria-hidden":"true"}),ne&&!oe&&r("button",{type:"button",className:"qr-search-bar__clear",onClick:()=>{ae(""),ie([]),ue(!1),de(null)},"aria-label":"Clear search",tabIndex:-1,children:"×"})]}),se&&r("p",{className:"qr-search-bar__error",role:"alert",children:se}),ce&&te.length>0&&r("ul",{id:ye,className:"qr-search-bar__dropdown",role:"listbox","aria-label":"Address suggestions",children:te.map((n,a)=>e("li",{className:"qr-search-bar__suggestion",role:"option","aria-selected":"false",onMouseDown:e=>{e.preventDefault(),Ne(n)},children:[e("svg",{className:"qr-search-bar__suggestion-icon","aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r("path",{d:"M12 2C8.134 2 5 5.134 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.866-3.134-7-7-7z"}),r("circle",{cx:"12",cy:"9",r:"2.5"})]}),e("div",{className:"qr-search-bar__suggestion-text",children:[r("span",{className:"qr-search-bar__suggestion-name",children:n.displayName}),n.address&&n.address!==n.displayName&&r("span",{className:"qr-search-bar__suggestion-sub",children:n.address})]})]},a))}),e("p",{className:"qr-search-bar__hint",children:[r("span",{className:"qr-search-bar__hint-chip",children:"DigiPin"}),"Type your DigiPin code for instant offline lookup — no API call"]})]}),e("div",{className:"qr-map-outer",style:{height:h},children:[r("div",{ref:x,className:"qr-map-canvas"}),Le&&r("div",{className:"qr-map-notice",role:"loading"===H?"status":"alert",children:"loading"===H?e(n,{children:[r("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}),r("span",{children:"Loading map…"})]}):G??"Map is unavailable. Please try again."}),U&&e("div",{className:"qr-digipin-badge","aria-live":"polite","aria-label":`DigiPin: ${U}`,children:[r("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r("span",{className:"qr-digipin-badge__code",children:U})]}),!Ee&&V&&r("div",{className:"qr-map-notice",role:"status",children:"Move map to India to get a DigiPin"}),r("button",{className:"qr-locate-btn"+(fe?" qr-locate-btn--loading":""),onClick:Ce,disabled:fe||"ready"!==H,title:"Use my current location","aria-label":"Use my current location",type:"button",children:fe?r("span",{className:"qr-spinner","aria-hidden":"true"}):e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("circle",{cx:"12",cy:"12",r:"3",fill:"currentColor",stroke:"none"}),r("circle",{cx:"12",cy:"12",r:"7"}),r("path",{d:"M12 2v3M12 19v3M2 12h3M19 12h3"})]})}),be&&e("div",{className:"qr-geo-error",role:"alert",children:[r("span",{children:be}),r("button",{type:"button",className:"qr-geo-error__dismiss",onClick:_e,"aria-label":"Dismiss error",children:"×"})]})]}),V&&e("div",{className:"qr-coords-strip","aria-label":"Current pin coordinates",children:[e("span",{children:[O.toFixed(5),"° N"]}),r("span",{className:"qr-coords-sep",children:"·"}),e("span",{children:[$.toFixed(5),"° E"]})]}),e("div",{className:"qr-map-actions",children:[e("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:xe,disabled:!Se,children:["Confirm Location",r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M5 12h14M12 5l7 7-7 7"})})]}),!Ee&&V&&r("p",{className:"qr-map-hint",children:"Move the pin to a location in India to continue"}),"ready"!==H&&r("p",{className:"qr-map-hint",children:"loading"===H?"Loading the map before location confirmation.":"Map is unavailable, so location confirmation is paused."})]})]})}
|
|
128
128
|
async function ne(e,r){const n=await fetch(`${e.functionBaseUrl}/checkout-otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"send",mobile:r,merchant_id:e.merchantId})}),a=await n.json().catch(()=>({}))
|
|
129
129
|
if(!n.ok||!a.success)throw new Error(a.error??"Failed to send OTP. Please try again.")}async function ae(e,r,n,a){const t=await fetch(`${e.functionBaseUrl}/checkout-otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"verify",mobile:r,otp:n,merchant_id:e.merchantId,...a})}),i=await t.json().catch(()=>({}))
|
|
130
130
|
if(!t.ok||!i.success)throw new Error(i.error??"Invalid or expired OTP.")
|
|
@@ -187,7 +187,7 @@ case"SET_LABEL_TEXT":return"ready"!==e.status?e:{...e,labelText:r.value.slice(0,
|
|
|
187
187
|
case"SUBMIT_START":return"ready"!==e.status?e:{...e,submitting:!0}
|
|
188
188
|
case"SUBMIT_END":return"ready"!==e.status?e:{...e,submitting:!1}
|
|
189
189
|
default:return e}}const Te=({digipin:a,lat:t,lng:o,apiKey:l,apiBaseUrl:c,onAddressComplete:u,onBack:h,onError:p,checkoutConfig:m,serviceabilitySessionToken:y,enableServiceabilityCheck:f=!1,showIndiaPostDeliveryWarning:b=!1,serviceabilityBlockCheckout:v,onServiceabilityResult:_,initialValues:g,submitLabel:q="Save Address"})=>{var w,N,k,C
|
|
190
|
-
const[x,E]=d(Le,{status:"loading"}),
|
|
190
|
+
const[x,E]=d(Le,{status:"loading"}),I=i(async()=>{var e
|
|
191
191
|
E({type:"LOAD_START"})
|
|
192
192
|
try{const[r,n]=await Promise.all([S(t,o,l,c),A(a,l,c)]),i=(null==(e=r.data.administrative_info.pincode)?void 0:e.replace(/\D/g,"").slice(0,6))??""
|
|
193
193
|
if(6!==i.length)return E({type:"LOAD_ERROR",message:"Could not determine a valid 6-digit pincode for this location. Please adjust the map pin."}),void(null==p||p(new Error("Missing or invalid pincode")))
|
|
@@ -197,21 +197,21 @@ const d=T(s.offices)
|
|
|
197
197
|
let u=null
|
|
198
198
|
if(f&&(null==m?void 0:m.functionBaseUrl)&&m.merchantId&&y)try{u=await fe(m,y,i,{lat:t,lng:o}),null==_||_(u)}catch{}E({type:"LOAD_SUCCESS",adminInfo:r.data.administrative_info,alternatives:r.data.alternatives||[],addressComponents:n.data.addressComponents,pincodeHasDelivery:d,serviceabilityResult:u,initialValues:g})}catch(e){const r=e instanceof Error?e.message:"Failed to fetch address data."
|
|
199
199
|
E({type:"LOAD_ERROR",message:r}),null==p||p(e instanceof Error?e:new Error(r))}},[a,t,o,l,c,p,m,y,f,_,g])
|
|
200
|
-
s(()=>{
|
|
201
|
-
const
|
|
200
|
+
s(()=>{I()},[I])
|
|
201
|
+
const P=i(async e=>{var r
|
|
202
202
|
if(e.preventDefault(),"ready"!==x.status||x.submitting)return
|
|
203
203
|
const{adminInfo:n,selectedLocality:i,selectedLabel:l,labelText:s,fields:d}=x
|
|
204
204
|
if("other"===l&&!s.trim())return
|
|
205
205
|
if((null==(r=x.serviceabilityResult)?void 0:r.checked)&&!1===x.serviceabilityResult.serviceable&&(v??x.serviceabilityResult.block_checkout))return
|
|
206
206
|
const c=[d.flatNumber,d.floorNumber?`Floor ${d.floorNumber}`:"",d.buildingName,d.streetName,i,n.district,n.state,n.pincode].filter(Boolean),h={digipin:a,lat:t,lng:o,state:n.state,district:n.district,division:n.division,locality:i,pincode:n.pincode,delivery:n.delivery,country:n.country??"India",...d,formattedAddress:c.join(", "),label:l,..."other"===l?{labelText:s.trim()}:{}}
|
|
207
207
|
E({type:"SUBMIT_START"})
|
|
208
|
-
try{await u(h)}finally{E({type:"SUBMIT_END"})}},[x,a,t,o,u,v]),B="ready"===x.status&&(null==(w=x.serviceabilityResult)?void 0:w.checked)&&!1===x.serviceabilityResult.serviceable&&(v??x.serviceabilityResult.block_checkout),
|
|
209
|
-
return e("div",{className:"qr-form-wrapper",children:[e("div",{className:"qr-step-header",children:[r("button",{type:"button",className:"qr-back-btn",onClick:h,"aria-label":"Back to map",children:r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}),r("div",{className:"qr-step-badge",children:"2"}),e("div",{className:"qr-step-text",children:[r("span",{className:"qr-step-title",children:"Add Address Details"}),r("span",{className:"qr-step-sub",children:"Flat number and building info"})]})]}),e("div",{className:"qr-form-digipin-strip",children:[e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("path",{d:"M21 10c0 7-9 13-9 13S3 17 3 10a9 9 0 0118 0z"}),r("circle",{cx:"12",cy:"10",r:"3"})]}),r("span",{className:"qr-form-digipin-strip__label",children:"DigiPin"}),r("span",{className:"qr-form-digipin-strip__code",children:a})]}),"loading"===x.status&&e("div",{className:"qr-loading-state","aria-busy":"true","aria-label":"Fetching address details",children:[r("div",{className:"qr-spinner qr-spinner--lg","aria-hidden":"true"}),r("p",{className:"qr-loading-state__text",children:"Fetching address details…"})]}),"error"===x.status&&e("div",{className:"qr-error-state",role:"alert",children:[r("div",{className:"qr-error-state__icon","aria-hidden":"true",children:"⚠"}),r("p",{className:"qr-error-state__msg",children:x.message}),r("button",{type:"button",className:"qr-btn qr-btn--secondary qr-btn--sm",onClick:()=>{
|
|
208
|
+
try{await u(h)}finally{E({type:"SUBMIT_END"})}},[x,a,t,o,u,v]),B="ready"===x.status&&(null==(w=x.serviceabilityResult)?void 0:w.checked)&&!1===x.serviceabilityResult.serviceable&&(v??x.serviceabilityResult.block_checkout),M="ready"===x.status&&(null==(N=x.serviceabilityResult)?void 0:N.checked)&&!1===x.serviceabilityResult.serviceable,O="ready"===x.status&&!x.pincodeHasDelivery&&!0!==(null==(k=x.serviceabilityResult)?void 0:k.serviceable)&&!M&&((null==(C=x.serviceabilityResult)?void 0:C.show_india_post_delivery_warning)??b)
|
|
209
|
+
return e("div",{className:"qr-form-wrapper",children:[e("div",{className:"qr-step-header",children:[r("button",{type:"button",className:"qr-back-btn",onClick:h,"aria-label":"Back to map",children:r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}),r("div",{className:"qr-step-badge",children:"2"}),e("div",{className:"qr-step-text",children:[r("span",{className:"qr-step-title",children:"Add Address Details"}),r("span",{className:"qr-step-sub",children:"Flat number and building info"})]})]}),e("div",{className:"qr-form-digipin-strip",children:[e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("path",{d:"M21 10c0 7-9 13-9 13S3 17 3 10a9 9 0 0118 0z"}),r("circle",{cx:"12",cy:"10",r:"3"})]}),r("span",{className:"qr-form-digipin-strip__label",children:"DigiPin"}),r("span",{className:"qr-form-digipin-strip__code",children:a})]}),"loading"===x.status&&e("div",{className:"qr-loading-state","aria-busy":"true","aria-label":"Fetching address details",children:[r("div",{className:"qr-spinner qr-spinner--lg","aria-hidden":"true"}),r("p",{className:"qr-loading-state__text",children:"Fetching address details…"})]}),"error"===x.status&&e("div",{className:"qr-error-state",role:"alert",children:[r("div",{className:"qr-error-state__icon","aria-hidden":"true",children:"⚠"}),r("p",{className:"qr-error-state__msg",children:x.message}),r("button",{type:"button",className:"qr-btn qr-btn--secondary qr-btn--sm",onClick:()=>{I()},children:"Retry"})]}),"ready"===x.status&&e("form",{onSubmit:P,className:"qr-form",noValidate:!0,children:[e("fieldset",{className:"qr-fieldset",children:[e("legend",{className:"qr-fieldset__legend",children:[r("span",{className:"qr-fieldset__icon","aria-hidden":"true",children:"📍"}),"Auto-detected from your digipin"]}),e("div",{className:"qr-auto-grid",children:[e("div",{className:"qr-auto-row",children:[r("span",{className:"qr-auto-row__label",children:"State"}),r("span",{className:"qr-auto-row__value",children:x.adminInfo.state})]}),e("div",{className:"qr-auto-row",children:[r("span",{className:"qr-auto-row__label",children:"District"}),r("span",{className:"qr-auto-row__value",children:x.adminInfo.district})]}),e("div",{className:"qr-auto-row qr-auto-row--full",children:[r("span",{className:"qr-auto-row__label",children:"Locality"}),x.localityOptions.length>1?r("select",{className:"qr-auto-row__select",value:x.selectedLocality,onChange:e=>E({type:"SET_LOCALITY",locality:e.target.value}),"aria-label":"Select locality",children:x.localityOptions.map(e=>r("option",{value:e,children:e},e))}):r("span",{className:"qr-auto-row__value",children:x.selectedLocality})]}),e("div",{className:"qr-auto-row",children:[r("span",{className:"qr-auto-row__label",children:"Pincode"}),r("span",{className:"qr-auto-row__value qr-auto-row__value--pin",children:x.adminInfo.pincode})]})]})]}),M&&x.serviceabilityResult&&e("div",{className:"qr-pincode-banner "+(B?"qr-pincode-banner--error":"qr-pincode-banner--warning"),role:B?"alert":"status","aria-live":"polite",children:[r("span",{className:"qr-pincode-banner__icon","aria-hidden":"true",children:B?"!":"⚠"}),e("div",{className:"qr-pincode-banner__text",children:[r("strong",{children:B?"Delivery unavailable":"Delivery may be limited"}),r("span",{children:x.serviceabilityResult.message??(B?"This seller does not currently deliver to this pincode.":"This seller recommends confirming delivery availability for this pincode.")})]})]}),O&&e("div",{className:"qr-pincode-banner qr-pincode-banner--info",role:"status","aria-live":"polite",children:[r("span",{className:"qr-pincode-banner__icon","aria-hidden":"true",children:"i"}),e("div",{className:"qr-pincode-banner__text",children:[r("strong",{children:"India Post: no home-delivery office"}),r("span",{children:"Courier partners may still deliver to this pincode."})]})]}),e("fieldset",{className:"qr-fieldset",children:[r("legend",{className:"qr-fieldset__legend qr-fieldset__legend--compact",children:"Save as"}),r("div",{className:"qr-label-picker",role:"radiogroup","aria-label":"Address label",children:[{value:"home",title:"Home"},{value:"work",title:"Work"},{value:"other",title:"Other"}].map(({value:n,title:a})=>e("button",{type:"button",role:"radio","aria-checked":x.selectedLabel===n,className:"qr-label-picker__option"+(x.selectedLabel===n?" qr-label-picker__option--active":""),onClick:()=>E({type:"SET_LABEL",label:n}),children:[r("span",{className:"qr-label-picker__icon",children:r(Ee,{label:n})}),r("span",{children:a})]},n))}),"other"===x.selectedLabel&&e("div",{className:"qr-label-text-field",children:[e("label",{className:"qr-field__label",htmlFor:"qr-labelText",children:["Label name",r("span",{className:"qr-required","aria-hidden":"true",children:"*"})]}),r("input",{id:"qr-labelText",type:"text",className:"qr-field__input",placeholder:"e.g. Friend's home, Gym",value:x.labelText,onChange:e=>E({type:"SET_LABEL_TEXT",value:e.target.value}),maxLength:64,required:!0,"aria-required":"true",autoComplete:"off"})]})]}),e("fieldset",{className:"qr-fieldset",children:[e("legend",{className:"qr-fieldset__legend",children:[r("span",{className:"qr-fieldset__icon","aria-hidden":"true",children:"🏠"}),"Your details"]}),e("div",{className:"qr-fields-grid",children:[e("div",{className:"qr-field qr-field--full",children:[e("label",{className:"qr-field__label",htmlFor:"qr-flatNumber",children:["Flat / House Number",r("span",{className:"qr-required","aria-hidden":"true",children:"*"})]}),r("input",{id:"qr-flatNumber",type:"text",className:"qr-field__input",placeholder:"e.g. 4B, Flat 201, House No. 12",value:x.fields.flatNumber,onChange:e=>E({type:"SET_FIELD",key:"flatNumber",value:e.target.value}),autoComplete:"address-line1",required:!0,"aria-required":"true"})]}),e("div",{className:"qr-field",children:[e("label",{className:"qr-field__label",htmlFor:"qr-floorNumber",children:["Floor",r("span",{className:"qr-optional",children:"optional"})]}),r("input",{id:"qr-floorNumber",type:"text",className:"qr-field__input",placeholder:"e.g. 3rd, Ground",value:x.fields.floorNumber,onChange:e=>E({type:"SET_FIELD",key:"floorNumber",value:e.target.value})})]}),e("div",{className:"qr-field",children:[e("label",{className:"qr-field__label",htmlFor:"qr-buildingName",children:["Building / Society",r("span",{className:"qr-optional",children:"optional"})]}),r("input",{id:"qr-buildingName",type:"text",className:"qr-field__input",placeholder:"e.g. Sunshine Apts, DDA Colony",value:x.fields.buildingName,onChange:e=>E({type:"SET_FIELD",key:"buildingName",value:e.target.value}),autoComplete:"address-line2"})]}),e("div",{className:"qr-field qr-field--full",children:[e("label",{className:"qr-field__label",htmlFor:"qr-streetName",children:["Street / Area",r("span",{className:"qr-optional",children:"optional"})]}),r("input",{id:"qr-streetName",type:"text",className:"qr-field__input",placeholder:"e.g. MG Road, Sector 12",value:x.fields.streetName,onChange:e=>E({type:"SET_FIELD",key:"streetName",value:e.target.value}),autoComplete:"address-level3"})]})]})]}),e("div",{className:"qr-form-actions",children:[e("button",{type:"button",className:"qr-btn qr-btn--ghost",onClick:h,children:[r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M19 12H5M12 19l-7-7 7-7"})}),"Adjust Pin"]}),r("button",{type:"submit",className:"qr-btn qr-btn--primary qr-btn--grow",disabled:x.submitting||!x.fields.flatNumber.trim()||"other"===x.selectedLabel&&!x.labelText.trim()||Boolean(B),children:x.submitting?e(n,{children:[r("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}),"Saving…"]}):e(n,{children:[q,r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M20 6L9 17l-5-5"})})]})})]})]})]})},Ie=({onOtpSent:a,onSkip:l,functionBaseUrl:s,merchantId:d})=>{const[c,u]=t(""),[h,p]=t(!1),[m,y]=t(null),f=o(null),b=i(e=>{u(e.target.value.replace(/\D/g,"").slice(0,10)),y(null)},[]),v=i(async e=>{var r
|
|
210
210
|
if(e.preventDefault(),10!==c.length)return y("Enter a valid 10-digit mobile number."),void(null==(r=f.current)||r.focus())
|
|
211
211
|
p(!0),y(null)
|
|
212
212
|
try{await ne({functionBaseUrl:s,merchantId:d},`+91${c}`),a(`+91${c}`)}catch(e){y(e instanceof Error?e.message:"Failed to send OTP. Please try again.")}finally{p(!1)}},[c,s,d,a])
|
|
213
213
|
return e("div",{className:"qr-auth-step",children:[r("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:e("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r("path",{d:"M16 14h4l2 5-2.5 1.5a11 11 0 005 5L26 23l5 2v4c0 1.1-.9 2-2 2A18 18 0 0114 16c0-1.1.9-2 2-2z",stroke:"var(--qr-primary)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}),r("h3",{className:"qr-auth-step__title",children:"Faster checkout"}),r("p",{className:"qr-auth-step__sub",children:"Enter your mobile to load saved addresses"}),e("form",{onSubmit:v,noValidate:!0,children:[e("div",{className:"qr-phone-field"+(m?" qr-phone-field--error":""),children:[r("span",{className:"qr-phone-field__prefix","aria-hidden":"true",children:"+91"}),r("input",{ref:f,type:"tel",inputMode:"numeric",className:"qr-phone-field__input",placeholder:"98765 43210",value:c,onChange:b,maxLength:10,autoComplete:"tel-national","aria-label":"Mobile number","aria-describedby":m?"qr-phone-error":void 0,"aria-invalid":!!m,disabled:h})]}),m&&r("p",{id:"qr-phone-error",className:"qr-auth-step__error",role:"alert",children:m}),r("button",{type:"submit",className:"qr-btn qr-btn--primary qr-btn--full",disabled:h||10!==c.length,children:h?r("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}):e(n,{children:["Send OTP",r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M5 12h14M12 5l7 7-7 7"})})]})})]}),r("button",{type:"button",className:"qr-auth-step__skip",onClick:l,disabled:h,children:"Skip, enter address manually"})]})}
|
|
214
|
-
function
|
|
214
|
+
function Pe(e){const r=e.replace(/\D/g,"")
|
|
215
215
|
return r.length<4?e:`+91 ${r.slice(2,7)} **${r.slice(-3)}`}const Be=({mobile:n,onVerified:a,onBack:l,functionBaseUrl:d,merchantId:c,sessionContext:u})=>{const[h,p]=t(Array(6).fill("")),[m,y]=t(!1),[f,b]=t(null),[v,_]=t(30),[g,q]=t(!1),w=o([]),N=o(null)
|
|
216
216
|
s(()=>(N.current=setInterval(()=>{_(e=>e<=1?(clearInterval(N.current),0):e-1)},1e3),()=>{N.current&&clearInterval(N.current)}),[])
|
|
217
217
|
const k=e=>{var r
|
|
@@ -227,22 +227,30 @@ r.split("").forEach((e,r)=>{n[r]=e}),p(n),b(null),k(Math.min(r.length,5))},[]),S
|
|
|
227
227
|
try{const e=await ae({functionBaseUrl:d,merchantId:c},n,S,u)
|
|
228
228
|
a(e.session_token,e.buyer_id,e.session_id)}catch(e){b(e instanceof Error?e.message:"Verification failed. Please try again."),p(Array(6).fill("")),k(0)}finally{y(!1)}}},[L,S,n,d,c,a,u])
|
|
229
229
|
s(()=>{L&&!m&&T()},[L])
|
|
230
|
-
const
|
|
230
|
+
const I=i(async()=>{if(!(v>0||g)){q(!0),b(null),p(Array(6).fill(""))
|
|
231
231
|
try{await ne({functionBaseUrl:d,merchantId:c},n),_(30),N.current=setInterval(()=>{_(e=>e<=1?(clearInterval(N.current),0):e-1)},1e3),k(0)}catch(e){b(e instanceof Error?e.message:"Failed to resend OTP.")}finally{q(!1)}}},[v,g,d,c,n])
|
|
232
|
-
return e("div",{className:"qr-auth-step",children:[r("button",{type:"button",className:"qr-back-btn qr-back-btn--auth",onClick:l,disabled:m,children:r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M19 12H5M12 5l-7 7 7 7"})})}),r("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:e("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r("rect",{x:"13",y:"16",width:"22",height:"16",rx:"2",stroke:"var(--qr-primary)",strokeWidth:"1.8",fill:"none"}),r("path",{d:"M13 22h22",stroke:"var(--qr-primary)",strokeWidth:"1.8"}),r("circle",{cx:"18",cy:"29",r:"1.5",fill:"var(--qr-primary)"}),r("circle",{cx:"24",cy:"29",r:"1.5",fill:"var(--qr-primary)"}),r("circle",{cx:"30",cy:"29",r:"1.5",fill:"var(--qr-primary)"})]})}),r("h3",{className:"qr-auth-step__title",children:"Enter OTP"}),e("p",{className:"qr-auth-step__sub",children:["Sent to ",r("strong",{children:
|
|
233
|
-
function De({label:e}){return r("home"===e?Ae:"work"===e?Oe
|
|
232
|
+
return e("div",{className:"qr-auth-step",children:[r("button",{type:"button",className:"qr-back-btn qr-back-btn--auth",onClick:l,disabled:m,children:r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M19 12H5M12 5l-7 7 7 7"})})}),r("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:e("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r("rect",{x:"13",y:"16",width:"22",height:"16",rx:"2",stroke:"var(--qr-primary)",strokeWidth:"1.8",fill:"none"}),r("path",{d:"M13 22h22",stroke:"var(--qr-primary)",strokeWidth:"1.8"}),r("circle",{cx:"18",cy:"29",r:"1.5",fill:"var(--qr-primary)"}),r("circle",{cx:"24",cy:"29",r:"1.5",fill:"var(--qr-primary)"}),r("circle",{cx:"30",cy:"29",r:"1.5",fill:"var(--qr-primary)"})]})}),r("h3",{className:"qr-auth-step__title",children:"Enter OTP"}),e("p",{className:"qr-auth-step__sub",children:["Sent to ",r("strong",{children:Pe(n)})]}),r("div",{className:"qr-otp-boxes",role:"group","aria-label":"Enter one-time password",children:h.map((e,n)=>r("input",{ref:e=>{w.current[n]=e},type:"text",inputMode:"numeric",maxLength:1,className:`qr-otp-box${e?" qr-otp-box--filled":""}${f?" qr-otp-box--error":""}`,value:e,onChange:e=>C(n,e.target.value),onKeyDown:e=>x(n,e),onPaste:E,onFocus:e=>e.target.select(),"aria-label":`OTP digit ${n+1}`,disabled:m,autoComplete:0===n?"one-time-code":"off"},n))}),f&&r("p",{className:"qr-auth-step__error",role:"alert",children:f}),r("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:T,disabled:!L||m,children:m?r("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}):"Verify OTP"}),r("p",{className:"qr-auth-step__resend",children:v>0?e("span",{children:["Resend OTP in ",v,"s"]}):r("button",{type:"button",className:"qr-link-btn",onClick:I,disabled:g,children:g?"Sending…":"Resend OTP"})})]})},Ae=()=>e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r("path",{d:"M3 9.5L12 3l9 6.5V20a1 1 0 01-1 1H4a1 1 0 01-1-1V9.5z"}),r("path",{d:"M9 21V12h6v9"})]}),Me=()=>e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r("rect",{x:"2",y:"7",width:"20",height:"14",rx:"2"}),r("path",{d:"M16 7V5a2 2 0 00-2-2h-4a2 2 0 00-2 2v2"})]}),Oe=()=>e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r("path",{d:"M12 2C8.134 2 5 5.134 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.866-3.134-7-7-7z"}),r("circle",{cx:"12",cy:"9",r:"2.5"})]})
|
|
233
|
+
function De({label:e}){return r("home"===e?Ae:"work"===e?Me:Oe,{})}function $e(e){var r
|
|
234
234
|
const n=null==(r=e.label_text)?void 0:r.trim()
|
|
235
|
-
return"other"===e.label&&n?n:e.label.charAt(0).toUpperCase()+e.label.slice(1)}
|
|
236
|
-
|
|
237
|
-
|
|
235
|
+
return"other"===e.label&&n?n:e.label.charAt(0).toUpperCase()+e.label.slice(1)}const Re=()=>e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"M12 7.5v5.5M12 16.5h.01"})]})
|
|
236
|
+
function Ue({address:a,onUse:t,onDelete:i,onSetDefault:o,deleting:l,selecting:s,locked:d,unavailableReason:c,error:u}){const h=`qr-addr-note-${a.id}`,p=`qr-addr-error-${a.id}`,m=Boolean(c),y=[a.flat_number,a.building_name,a.street_name,a.locality,a.district,a.state,a.pincode].filter(Boolean),f=[a.flat_number,a.building_name,a.street_name].filter(Boolean).join(", "),b=[a.locality,a.district].filter(Boolean).join(", "),v=[a.state,a.pincode].filter(Boolean).join(" – "),_=y.length>0?void 0:a.locality||a.district||a.state
|
|
237
|
+
return e("div",{className:`qr-addr-card${a.is_default&&!m?" qr-addr-card--default":""}${m?" qr-addr-card--unavailable":""}`,children:[e("div",{className:"qr-addr-card__header",children:[r("div",{className:"qr-addr-card__label-icon",children:r(De,{label:a.label})}),r("span",{className:"qr-addr-card__label",children:$e(a)}),a.is_default&&r("span",{className:"qr-addr-card__default-badge",children:"Default"}),e("div",{className:"qr-addr-card__actions",children:[!a.is_default&&r("button",{type:"button",className:"qr-icon-btn",title:"Set as default",onClick:o,disabled:d,"aria-label":"Set as default address",children:r("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:r("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})})}),r("button",{type:"button",className:"qr-icon-btn qr-icon-btn--danger",title:"Delete address",onClick:i,disabled:l||d,"aria-label":"Delete address",children:l?r("span",{className:"qr-spinner qr-spinner--xs","aria-hidden":"true"}):e("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r("polyline",{points:"3 6 5 6 21 6"}),r("path",{d:"M19 6l-1 14a2 2 0 01-2 2H8a2 2 0 01-2-2L5 6"}),r("path",{d:"M10 11v6M14 11v6"}),r("path",{d:"M9 6V4a1 1 0 011-1h4a1 1 0 011 1v2"})]})})]})]}),e("div",{className:"qr-addr-card__body",children:[_?r("p",{className:"qr-addr-card__line",children:_}):e(n,{children:[f&&r("p",{className:"qr-addr-card__line",children:f}),b&&r("p",{className:"qr-addr-card__line qr-addr-card__line--muted",children:b}),v&&r("p",{className:"qr-addr-card__line qr-addr-card__line--muted",children:v})]}),e("div",{className:"qr-addr-card__meta",children:[a.digipin?e("span",{className:"qr-digipin-badge qr-digipin-badge--inline qr-digipin-badge--sm",children:[r("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r("span",{className:"qr-digipin-badge__code",children:a.digipin})]}):r("span",{className:"qr-addr-card__pending-pin",children:"Pin confirmation needed"}),a.saved_at_brand&&e("span",{className:"qr-addr-card__brand-chip",title:`First saved at ${a.saved_at_brand}`,children:[r("svg",{viewBox:"0 0 12 12",fill:"currentColor","aria-hidden":"true",children:r("path",{d:"M1 1h4.5l5.5 5.5-4.5 4.5L1 5.5V1zm2 1.5a.75.75 0 100 1.5.75.75 0 000-1.5z"})}),a.saved_at_brand]})]})]}),m&&e("div",{className:"qr-addr-card__unavailable",id:h,children:[r(Re,{}),e("div",{children:[e("p",{className:"qr-addr-card__unavailable-title",children:["Not deliverable",a.pincode?` to ${a.pincode}`:""]}),r("p",{className:"qr-addr-card__unavailable-text",children:c})]})]}),r("button",{type:"button",className:"qr-btn qr-btn--full qr-btn--sm "+(m?"qr-btn--ghost":"qr-btn--primary"),onClick:t,disabled:d||m,"aria-busy":s,"aria-describedby":m?h:u?p:void 0,children:s?e(n,{children:[r("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}),"Confirming…"]}):m?"Can't deliver here":"Deliver here"}),u&&!m&&e("p",{className:"qr-addr-card__error",id:p,role:"alert",children:[r(Re,{}),u]})]})}const Fe=({sessionToken:n,functionBaseUrl:a,merchantId:l,onSelectAddress:d,onAddNew:c,checkDeliverable:u})=>{const[h,p]=t([]),[m,y]=t(!0),[f,b]=t(null),[v,_]=t(null),[g,q]=t(null),[w,N]=t({}),[k,C]=t({}),x=o(!1),E={functionBaseUrl:a,merchantId:l},S=i(async()=>{y(!0),b(null)
|
|
238
|
+
try{const e=await ie(E,n)
|
|
238
239
|
if(0===e.length)return void c()
|
|
239
|
-
|
|
240
|
-
s(()=>{
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
return
|
|
240
|
+
p(e)}catch(e){b(e instanceof Error?e.message:"Failed to load addresses.")}finally{y(!1)}},[n])
|
|
241
|
+
s(()=>{S()},[S]),s(()=>{if(!u||0===h.length)return
|
|
242
|
+
let e=!1
|
|
243
|
+
const r=new Map
|
|
244
|
+
for(const e of h){const n=e.pincode||e.id
|
|
245
|
+
r.set(n,[...r.get(n)??[],e])}return r.forEach(r=>{u(r[0]).then(n=>{!e&&n&&N(e=>{const a={...e}
|
|
246
|
+
return r.forEach(e=>{a[e.id]=n}),a})}).catch(()=>{})}),()=>{e=!0}},[h,u])
|
|
247
|
+
const L=i(async e=>{_(e)
|
|
248
|
+
try{await le(E,n,e),p(r=>{const n=r.filter(r=>r.id!==e)
|
|
249
|
+
return 0===n.length&&c(),n})}catch(e){b(e instanceof Error?e.message:"Failed to delete address.")}finally{_(null)}},[n,c]),T=i(async e=>{try{await se(E,n,e),p(r=>r.map(r=>({...r,is_default:r.id===e})))}catch(e){b(e instanceof Error?e.message:"Failed to set default.")}},[n]),I=i(async e=>{if(!x.current){x.current=!0,q(e.id),C(r=>{const{[e.id]:n,...a}=r
|
|
250
|
+
return a})
|
|
251
|
+
try{await d(e)}catch(r){const n=r instanceof Error?r.message:"Could not use this address. Please try again."
|
|
252
|
+
"ADDRESS_UNDELIVERABLE"===(null==r?void 0:r.code)?N(r=>({...r,[e.id]:n})):C(r=>({...r,[e.id]:n})),x.current=!1,q(null)}}},[d])
|
|
253
|
+
return m?r("div",{className:"qr-saved-step",children:r("div",{className:"qr-saved-step__loading","aria-live":"polite",children:r("span",{className:"qr-spinner","aria-label":"Loading addresses"})})}):f&&0===h.length?e("div",{className:"qr-saved-step",children:[r("p",{className:"qr-auth-step__error",role:"alert",children:f}),r("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--full",onClick:S,children:"Retry"}),r("button",{type:"button",className:"qr-auth-step__skip",onClick:c,children:"Enter address manually"})]}):e("div",{className:"qr-saved-step",children:[e("div",{className:"qr-step-header",children:[r("div",{className:"qr-step-badge qr-step-badge--saved",children:e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("path",{d:"M12 2C8.134 2 5 5.134 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.866-3.134-7-7-7z"}),r("circle",{cx:"12",cy:"9",r:"2.5"})]})}),e("div",{className:"qr-step-text",children:[r("span",{className:"qr-step-title",children:"Saved Addresses"}),r("span",{className:"qr-step-sub",children:"Pick one or add a new location"})]})]}),f&&r("p",{className:"qr-auth-step__error",role:"alert",children:f}),r("div",{className:"qr-saved-step__list",children:h.map(e=>r(Ue,{address:e,onUse:()=>{I(e)},onDelete:()=>L(e.id),onSetDefault:()=>T(e.id),deleting:v===e.id,selecting:g===e.id,locked:null!==g,unavailableReason:w[e.id],error:k[e.id]},e.id))}),h.length>0&&h.every(e=>w[e.id])&&r("p",{className:"qr-saved-step__hint",role:"status",children:"None of your saved addresses can be delivered to right now. Add a new address to continue."}),e("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--full",onClick:c,disabled:null!==g,children:[r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M12 5v14M5 12h14"})}),"Add new address"]})]})},je=({checkoutConfig:n,sessionToken:a,pincode:i,cartTotalPaise:o,theme:l="light",onCodAllowedChange:d})=>{const[c,u]=t("loading"),[h,p]=t(!1),[m,y]=t()
|
|
246
254
|
return s(()=>{let e=!1
|
|
247
255
|
return u("loading"),(async()=>{try{const r=await me(n,a,i,o)
|
|
248
256
|
if(e)return
|
|
@@ -250,31 +258,31 @@ p(r.cod_allowed),null==d||d(r.cod_allowed),y(r.cod_allowed?void 0:r.reason?funct
|
|
|
250
258
|
case"pincode_blocked":return"COD is not available for this pincode."
|
|
251
259
|
case"cart_value_exceeded":return"COD is not available for this order value."
|
|
252
260
|
case"invalid_pincode":return"Enter a valid pincode to check COD."
|
|
253
|
-
default:return"COD is not available."}}(r.reason):void 0),u("ready")}catch{e||(u("error"),p(!1),y("Could not verify COD. Try again."))}})(),()=>{e=!0}},[n,a,i,o]),e("div",{className:"qr-cod-banner"+("dark"===l?" qr-cod-banner--dark":""),role:"status","aria-live":"polite",children:[r("div",{className:"qr-cod-banner__title",children:"Cash on Delivery"}),"loading"===c&&r("p",{className:"qr-cod-banner__text qr-cod-banner__text--muted",children:"Checking availability…"}),"error"===c&&r("p",{className:"qr-cod-banner__text qr-cod-banner__text--warn",children:m}),"ready"===c&&h&&r("p",{className:"qr-cod-banner__text qr-cod-banner__text--ok",children:"Available for this address."}),"ready"===c&&!h&&m&&r("p",{className:"qr-cod-banner__text qr-cod-banner__text--muted",children:m})]})},
|
|
254
|
-
let
|
|
255
|
-
const
|
|
261
|
+
default:return"COD is not available."}}(r.reason):void 0),u("ready")}catch{e||(u("error"),p(!1),y("Could not verify COD. Try again."))}})(),()=>{e=!0}},[n,a,i,o]),e("div",{className:"qr-cod-banner"+("dark"===l?" qr-cod-banner--dark":""),role:"status","aria-live":"polite",children:[r("div",{className:"qr-cod-banner__title",children:"Cash on Delivery"}),"loading"===c&&r("p",{className:"qr-cod-banner__text qr-cod-banner__text--muted",children:"Checking availability…"}),"error"===c&&r("p",{className:"qr-cod-banner__text qr-cod-banner__text--warn",children:m}),"ready"===c&&h&&r("p",{className:"qr-cod-banner__text qr-cod-banner__text--ok",children:"Available for this address."}),"ready"===c&&!h&&m&&r("p",{className:"qr-cod-banner__text qr-cod-banner__text--muted",children:m})]})},We=({copy:n,ctaUrl:a,theme:t="light"})=>e("div",{className:"qr-prepaid-nudge"+("dark"===t?" qr-prepaid-nudge--dark":""),role:"complementary","aria-label":"Prepaid offer",children:[r("p",{className:"qr-prepaid-nudge__copy",children:n}),a?r("a",{href:a,className:"qr-btn qr-btn--primary qr-btn--sm qr-prepaid-nudge__cta",target:"_blank",rel:"noopener noreferrer",children:"Pay online instead"}):null]}),ze="https://checkout.razorpay.com/v1/checkout.js"
|
|
262
|
+
let Ve=null
|
|
263
|
+
const Je=({checkoutConfig:n,sessionToken:a,sessionId:i,amountPaise:o,enableCod:l=!1,codAllowed:d=!1,addressRisk:c,theme:u="light",onComplete:h,onBack:p,onEvent:m,orderConfirmationUrl:y})=>{const[f,b]=t(!1),[v,_]=t(null),g="dark"===u
|
|
256
264
|
s(()=>{null==m||m("payment_step_viewed")},[m])
|
|
257
265
|
const q=`₹${(o/100).toLocaleString("en-IN")}`,w=(null==c?void 0:c.interventions.includes("hide_cod"))??!1,N="high"===(null==c?void 0:c.level)?"high":"medium"===(null==c?void 0:c.level)?"medium":"low"
|
|
258
266
|
return e("div",{className:"qr-payment-step"+(g?" qr-payment-step--dark":""),children:[p?r("button",{type:"button",className:"qr-back-btn qr-back-btn--auth",onClick:p,disabled:f,children:"← Back"}):null,r("h3",{className:"qr-auth-step__title",children:"Choose payment"}),e("p",{className:"qr-auth-step__sub",children:["Order total: ",r("strong",{children:q})]}),v?r("p",{className:"qr-auth-step__error",role:"alert",children:v}):null,c&&"low"!==c.level?e("div",{className:`qr-risk-banner qr-risk-banner--${N}`,role:"status",children:[r("strong",{children:"high"===c.level?"Address needs extra confirmation":"Address confidence check"}),r("span",{children:c.reasons[0]}),w?r("span",{children:"Cash on Delivery is disabled for this order. Online payment is still available."}):null]}):null,e("button",{type:"button",className:"qr-payment-option qr-payment-option--primary",onClick:async()=>{b(!0),_(null)
|
|
259
|
-
try{await(window.Razorpay?Promise.resolve():
|
|
260
|
-
null==(n=document.querySelector(`script[src="${
|
|
267
|
+
try{await(window.Razorpay?Promise.resolve():Ve||(Ve=new Promise((e,r)=>{var n
|
|
268
|
+
null==(n=document.querySelector(`script[src="${ze}"]`))||n.remove()
|
|
261
269
|
const a=document.createElement("script")
|
|
262
|
-
a.src=
|
|
263
|
-
const t=e=>{window.clearTimeout(i),a.remove(),
|
|
264
|
-
a.onload=()=>{window.clearTimeout(i),window.Razorpay?e():t("Razorpay unavailable")},a.onerror=()=>t("Failed to load Razorpay"),document.body.appendChild(a)}),
|
|
270
|
+
a.src=ze,a.async=!0
|
|
271
|
+
const t=e=>{window.clearTimeout(i),a.remove(),Ve=null,r(new Error(e))},i=window.setTimeout(()=>t("Razorpay took too long to load"),15e3)
|
|
272
|
+
a.onload=()=>{window.clearTimeout(i),window.Razorpay?e():t("Razorpay unavailable")},a.onerror=()=>t("Failed to load Razorpay"),document.body.appendChild(a)}),Ve))
|
|
265
273
|
const e=await ge(n,a,o)
|
|
266
274
|
await new Promise((r,t)=>{window.Razorpay?new window.Razorpay({key:e.razorpay_key_id,amount:e.amount_paise,currency:e.currency,order_id:e.razorpay_order_id,name:"Checkout",handler:async e=>{try{const t=await qe(n,a,{razorpay_order_id:e.razorpay_order_id,razorpay_payment_id:e.razorpay_payment_id,razorpay_signature:e.razorpay_signature,payment_method:"prepaid"})
|
|
267
275
|
if(null==m||m("payment_method_selected",t.payment_method),h({paymentMethod:t.payment_method,razorpayOrderId:t.razorpay_order_id,razorpayPaymentId:t.razorpay_payment_id}),y){const e=y.replace("{{sessionId}}",i??"")
|
|
268
276
|
window.location.href=e}r()}catch(e){t(e)}},modal:{ondismiss:()=>t(new Error("Payment cancelled"))}}).open():t(new Error("Razorpay unavailable"))})}catch(e){_(e instanceof Error?e.message:"Payment failed")}finally{b(!1)}},disabled:f,children:[r("span",{className:"qr-payment-option__icon","aria-hidden":"true",children:"UPI"}),e("span",{className:"qr-payment-option__copy",children:[r("span",{className:"qr-payment-option__title",children:f?"Processing...":"Pay online"}),r("span",{className:"qr-payment-option__sub",children:"UPI, cards, wallets"})]}),r("strong",{className:"qr-payment-option__amount",children:q})]}),l&&d&&!w?e("button",{type:"button",className:"qr-payment-option qr-payment-option--secondary",onClick:async()=>{b(!0),_(null)
|
|
269
277
|
try{const e=await we(n,a)
|
|
270
|
-
null==m||m("payment_method_selected",e.payment_method),h({paymentMethod:e.payment_method})}catch(e){_(e instanceof Error?e.message:"Failed to select COD")}finally{b(!1)}},disabled:f,children:[r("span",{className:"qr-payment-option__icon","aria-hidden":"true",children:"₹"}),e("span",{className:"qr-payment-option__copy",children:[r("span",{className:"qr-payment-option__title",children:"Cash on Delivery"}),r("span",{className:"qr-payment-option__sub",children:"Pay when the order arrives"})]})]}):null,i?e("p",{className:"qr-payment-step__meta",children:["Session ",i.slice(0,8),"…"]}):null]})},
|
|
278
|
+
null==m||m("payment_method_selected",e.payment_method),h({paymentMethod:e.payment_method})}catch(e){_(e instanceof Error?e.message:"Failed to select COD")}finally{b(!1)}},disabled:f,children:[r("span",{className:"qr-payment-option__icon","aria-hidden":"true",children:"₹"}),e("span",{className:"qr-payment-option__copy",children:[r("span",{className:"qr-payment-option__title",children:"Cash on Delivery"}),r("span",{className:"qr-payment-option__sub",children:"Pay when the order arrives"})]})]}):null,i?e("p",{className:"qr-payment-step__meta",children:["Session ",i.slice(0,8),"…"]}):null]})},He=({onOtpSent:a,onSkip:l,functionBaseUrl:s,merchantId:d})=>{const[c,u]=t(""),[h,p]=t(!1),[m,y]=t(null),f=o(null),b=i(e=>{u(e.target.value.trim()),y(null)},[]),v=i(async e=>{var r
|
|
271
279
|
if(e.preventDefault(),!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(c))return y("Enter a valid email address."),void(null==(r=f.current)||r.focus())
|
|
272
280
|
p(!0),y(null)
|
|
273
281
|
try{const{reused:e}=await he({functionBaseUrl:s,merchantId:d},c)
|
|
274
282
|
a(c.toLowerCase(),{reused:e})}catch(e){y(e instanceof Error?e.message:"Failed to send code. Please try again.")}finally{p(!1)}},[c,s,d,a])
|
|
275
283
|
return e("div",{className:"qr-auth-step",children:[r("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:e("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r("rect",{x:"11",y:"15",width:"26",height:"18",rx:"3",stroke:"var(--qr-primary)",strokeWidth:"1.8",fill:"none"}),r("path",{d:"M11 18l13 9 13-9",stroke:"var(--qr-primary)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r("h3",{className:"qr-auth-step__title",children:"Faster checkout"}),r("p",{className:"qr-auth-step__sub",children:"Enter your email to load saved addresses"}),e("form",{onSubmit:v,noValidate:!0,children:[r("div",{className:"qr-email-field"+(m?" qr-email-field--error":""),children:r("input",{ref:f,type:"email",inputMode:"email",className:"qr-email-field__input",placeholder:"you@example.com",value:c,onChange:b,autoComplete:"email","aria-label":"Email address","aria-describedby":m?"qr-email-error":void 0,"aria-invalid":!!m,disabled:h})}),m&&r("p",{id:"qr-email-error",className:"qr-auth-step__error",role:"alert",children:m}),r("button",{type:"submit",className:"qr-btn qr-btn--primary qr-btn--full",disabled:h||c.length<5,children:h?r("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}):e(n,{children:["Send Code",r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M5 12h14M12 5l7 7-7 7"})})]})})]}),r("button",{type:"button",className:"qr-auth-step__skip",onClick:l,disabled:h,children:"Skip, enter address manually"})]})}
|
|
276
|
-
function
|
|
277
|
-
return!n||r.length<=1?e:`${r[0]}***@${n}`}const
|
|
284
|
+
function Ke(e){const[r,n]=e.split("@")
|
|
285
|
+
return!n||r.length<=1?e:`${r[0]}***@${n}`}const Ge=({email:a,codeReused:l=!1,onVerified:d,onBack:c,functionBaseUrl:u,merchantId:h,sessionContext:p})=>{const[m,y]=t(Array(6).fill("")),[f,b]=t(!1),[v,_]=t(null),[g,q]=t(60),[w,N]=t(!1),k=o([]),C=o(null)
|
|
278
286
|
s(()=>(C.current=setInterval(()=>{q(e=>e<=1?(clearInterval(C.current),0):e-1)},1e3),()=>{C.current&&clearInterval(C.current)}),[])
|
|
279
287
|
const x=e=>{var r
|
|
280
288
|
return null==(r=k.current[e])?void 0:r.focus()},E=i((e,r)=>{const n=r.replace(/\D/g,"").slice(-1)
|
|
@@ -285,56 +293,56 @@ return n[e-1]="",n}),x(e-1)):"ArrowLeft"===r.key&&e>0?x(e-1):"ArrowRight"===r.ke
|
|
|
285
293
|
const r=e.clipboardData.getData("text").replace(/\D/g,"").slice(0,6)
|
|
286
294
|
if(!r)return
|
|
287
295
|
const n=Array(6).fill("")
|
|
288
|
-
r.split("").forEach((e,r)=>{n[r]=e}),y(n),_(null),x(Math.min(r.length,5))},[]),T=m.join(""),
|
|
296
|
+
r.split("").forEach((e,r)=>{n[r]=e}),y(n),_(null),x(Math.min(r.length,5))},[]),T=m.join(""),I=6===T.length&&!m.includes(""),P=i(async()=>{if(I){b(!0),_(null)
|
|
289
297
|
try{const e=await pe({functionBaseUrl:u,merchantId:h},a,T,p)
|
|
290
|
-
d(e.session_token,e.buyer_id,e.session_id)}catch(e){_(e instanceof Error?e.message:"Verification failed. Please try again."),y(Array(6).fill("")),x(0)}finally{b(!1)}}},[
|
|
291
|
-
s(()=>{
|
|
298
|
+
d(e.session_token,e.buyer_id,e.session_id)}catch(e){_(e instanceof Error?e.message:"Verification failed. Please try again."),y(Array(6).fill("")),x(0)}finally{b(!1)}}},[I,T,a,u,h,d,p])
|
|
299
|
+
s(()=>{I&&!f&&P()},[I])
|
|
292
300
|
const B=i(async()=>{if(!(g>0||w)){N(!0),_(null),y(Array(6).fill(""))
|
|
293
301
|
try{await he({functionBaseUrl:u,merchantId:h},a),q(60),C.current=setInterval(()=>{q(e=>e<=1?(clearInterval(C.current),0):e-1)},1e3),x(0)}catch(e){_(e instanceof Error?e.message:"Failed to resend code.")}finally{N(!1)}}},[g,w,u,h,a])
|
|
294
|
-
return e("div",{className:"qr-auth-step",children:[r("button",{type:"button",className:"qr-back-btn qr-back-btn--auth",onClick:c,disabled:f,children:r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M19 12H5M12 5l-7 7 7 7"})})}),r("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:e("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r("rect",{x:"11",y:"15",width:"26",height:"18",rx:"3",stroke:"var(--qr-primary)",strokeWidth:"1.8",fill:"none"}),r("path",{d:"M11 18l13 9 13-9",stroke:"var(--qr-primary)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r("h3",{className:"qr-auth-step__title",children:"Check your email"}),r("p",{className:"qr-auth-step__sub",children:l?r(n,{children:"Use the code we sent earlier — it's still valid for your next checkout."}):e(n,{children:["6-digit code sent to ",r("strong",{children:
|
|
295
|
-
function
|
|
302
|
+
return e("div",{className:"qr-auth-step",children:[r("button",{type:"button",className:"qr-back-btn qr-back-btn--auth",onClick:c,disabled:f,children:r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M19 12H5M12 5l-7 7 7 7"})})}),r("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:e("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r("rect",{x:"11",y:"15",width:"26",height:"18",rx:"3",stroke:"var(--qr-primary)",strokeWidth:"1.8",fill:"none"}),r("path",{d:"M11 18l13 9 13-9",stroke:"var(--qr-primary)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r("h3",{className:"qr-auth-step__title",children:"Check your email"}),r("p",{className:"qr-auth-step__sub",children:l?r(n,{children:"Use the code we sent earlier — it's still valid for your next checkout."}):e(n,{children:["6-digit code sent to ",r("strong",{children:Ke(a)})]})}),r("div",{className:"qr-otp-boxes",role:"group","aria-label":"Enter verification code",children:m.map((e,n)=>r("input",{ref:e=>{k.current[n]=e},type:"text",inputMode:"numeric",maxLength:1,className:`qr-otp-box${e?" qr-otp-box--filled":""}${v?" qr-otp-box--error":""}`,value:e,onChange:e=>E(n,e.target.value),onKeyDown:e=>S(n,e),onPaste:L,onFocus:e=>e.target.select(),"aria-label":`Code digit ${n+1}`,disabled:f,autoComplete:0===n?"one-time-code":"off"},n))}),v&&r("p",{className:"qr-auth-step__error",role:"alert",children:v}),r("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:P,disabled:!I||f,children:f?r("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}):"Verify Code"}),r("p",{className:"qr-auth-step__resend",children:g>0?e("span",{children:["Resend code in ",g,"s"]}):r("button",{type:"button",className:"qr-link-btn",onClick:B,disabled:w,children:w?"Sending…":"Resend Code"})})]})}
|
|
303
|
+
function Qe(e){if("undefined"!=typeof window){const e=window.innerWidth
|
|
296
304
|
return e<768?"mobile":e<1024?"tablet":"desktop"}const r=(e??"").toLowerCase()
|
|
297
|
-
return/ipad|tablet/.test(r)?"tablet":/mobile|iphone|android/.test(r)?"mobile":"desktop"}function
|
|
298
|
-
return{deviceType:
|
|
299
|
-
function
|
|
300
|
-
for(const e of
|
|
301
|
-
a&&(n[e]=a.slice(0,256))}return n}catch{return{}}}function
|
|
302
|
-
const ee=S?"phone":j?"email":"none",ne="phone"===ee?"phone":"email"===ee?"email":"map",ae=Boolean(V&&J&&T),[te,ie]=t(ne),[le,se]=t(null),[he,pe]=t(null),[fe,ge]=t(null),[qe,we]=t(""),[Ne,ke]=t(!1),[Ce,xe]=t(!1),[Ee,Se]=t(null),[Le,
|
|
303
|
-
s(()=>{
|
|
304
|
-
const
|
|
305
|
-
if(A)try{A(r)}catch{}L&&T&&be(Qe,{event_type:r.type,step:r.step,buyer_id:r.buyerId,auth_channel:r.authChannel,device_type:r.deviceType,platform:r.platform,user_agent:r.userAgent,payment_method:r.paymentMethod,experiment_variant:r.experimentVariant},null==fe?void 0:fe.sessionToken).catch(()=>{})},[fe,ee,
|
|
305
|
+
return/ipad|tablet/.test(r)?"tablet":/mobile|iphone|android/.test(r)?"mobile":"desktop"}function Ze(){return"web"}function Ye(){const e=function(){if("undefined"!=typeof navigator&&navigator.userAgent)return navigator.userAgent.slice(0,512)}()
|
|
306
|
+
return{deviceType:Qe(e),platform:"web",userAgent:e}}const Xe=["utm_source","utm_medium","utm_campaign"]
|
|
307
|
+
function er(e){try{const r=new URL(e??("undefined"!=typeof window?window.location.href:"")),n={}
|
|
308
|
+
for(const e of Xe){const a=r.searchParams.get(e)
|
|
309
|
+
a&&(n[e]=a.slice(0,256))}return n}catch{return{}}}function rr(e){return Boolean(e.utm_source||e.utm_medium||e.utm_campaign)}const nr=({address:n,onEditAddress:a})=>e("div",{className:"qr-success",children:[r("div",{className:"qr-success__icon","aria-hidden":"true",children:e("svg",{viewBox:"0 0 52 52",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r("circle",{cx:"26",cy:"26",r:"26",fill:"var(--qr-success, #10b981)",opacity:"0.12"}),r("circle",{cx:"26",cy:"26",r:"20",fill:"var(--qr-success, #10b981)"}),r("path",{d:"M15 26l8 8 14-16",stroke:"white",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r("h3",{className:"qr-success__title",children:"Address Saved!"}),r("p",{className:"qr-success__address",children:n.formattedAddress}),r("div",{className:"qr-success__meta",children:e("span",{className:"qr-digipin-badge qr-digipin-badge--inline",children:[r("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r("span",{className:"qr-digipin-badge__code",children:n.digipin})]})}),r("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--sm",onClick:a,children:"Change Address"})]}),ar=({apiKey:l,apiBaseUrl:d="https://api.quantaroute.com",onComplete:u,onError:h,defaultLat:p,defaultLng:m,theme:y="light",className:f="",style:b,mapHeight:v="min(52dvh, 420px)",title:_="Add Delivery Address",mobilePresentation:g="auto",mobileStepLabels:q,indiaBoundaryUrl:w,enableSearch:N=!0,mapStyle:k,mapTheme:C,embedMode:x,mapsKey:E,enablePhoneAuth:S=!1,merchantId:L="",supabaseFunctionBaseUrl:T="https://ikfiewesidedxozotmrl.supabase.co/functions/v1",brandColor:I,logoUrl:P,headerBanner:B,onCheckoutEvent:A,enableCod:M=!1,enableServiceabilityCheck:O=!1,enableAddressIntelligence:D=!1,showIndiaPostDeliveryWarning:$=!1,serviceabilityBlockCheckout:R,codCartTotalPaise:U,codSessionToken:F="",enableEmailAuth:j=!1,variant:W,utmParams:z,enablePayment:V=!1,paymentAmountPaise:J,onPaymentComplete:H,enablePrepaidNudge:K=!1,prepaidNudgeCopy:G,prepaidNudgeCtaUrl:Q,registerController:Z,orderConfirmationUrl:Y})=>{var X
|
|
310
|
+
const ee=S?"phone":j?"email":"none",ne="phone"===ee?"phone":"email"===ee?"email":"map",ae=Boolean(V&&J&&T),[te,ie]=t(ne),[le,se]=t(null),[he,pe]=t(null),[fe,ge]=t(null),[qe,we]=t(""),[Ne,ke]=t(!1),[Ce,xe]=t(!1),[Ee,Se]=t(null),[Le,Pe]=t(null),[Ae,Me]=t(null),[Oe,De]=t(null),[$e,Re]=t("form"),Ue=o(te),ze=c(()=>z??er(),[z]),Ve=c(()=>Ye(),[]),Ke=c(()=>({utm_source:ze.utm_source,utm_medium:ze.utm_medium,utm_campaign:ze.utm_campaign,device_type:Ve.deviceType,platform:Ve.platform,user_agent:Ve.userAgent,experiment_variant:W}),[ze,Ve,W]),Qe=c(()=>({functionBaseUrl:T,merchantId:L}),[T,L]),Ze=(null==fe?void 0:fe.sessionToken)||F
|
|
311
|
+
s(()=>{Ue.current=te},[te])
|
|
312
|
+
const Xe=i(e=>{const r={...e,sessionId:e.sessionId??(null==fe?void 0:fe.sessionId),buyerId:e.buyerId??(null==fe?void 0:fe.buyerId),authChannel:e.authChannel??("phone"===ee?"phone":"email"===ee?"email":"none"),deviceType:e.deviceType??Ve.deviceType,platform:e.platform??Ve.platform,userAgent:e.userAgent??Ve.userAgent,experimentVariant:e.experimentVariant??W,timestamp:(new Date).toISOString()}
|
|
313
|
+
if(A)try{A(r)}catch{}L&&T&&be(Qe,{event_type:r.type,step:r.step,buyer_id:r.buyerId,auth_channel:r.authChannel,device_type:r.deviceType,platform:r.platform,user_agent:r.userAgent,payment_method:r.paymentMethod,experiment_variant:r.experimentVariant},null==fe?void 0:fe.sessionToken).catch(()=>{})},[fe,ee,Ve,W,A,L,T,Qe])
|
|
306
314
|
s(()=>{if(!L||!T)return
|
|
307
|
-
const e=()=>{"done"!==
|
|
308
|
-
return window.addEventListener("pagehide",e),()=>window.removeEventListener("pagehide",e)},[null==fe?void 0:fe.sessionToken,L,T,Qe,
|
|
309
|
-
const
|
|
310
|
-
s(()=>{if(xe(!1),!(ae&&
|
|
315
|
+
const e=()=>{"done"!==Ue.current&&(null==fe?void 0:fe.sessionToken)&&(ve(Qe,fe.sessionToken,Ue.current).catch(()=>{}),Xe({type:"session_abandoned",step:Ue.current}))}
|
|
316
|
+
return window.addEventListener("pagehide",e),()=>window.removeEventListener("pagehide",e)},[null==fe?void 0:fe.sessionToken,L,T,Qe,Xe]),s(()=>{(null==fe?void 0:fe.sessionToken)&&L&&T&&_e(Qe,fe.sessionToken).then(Se).catch(()=>Se(null))},[null==fe?void 0:fe.sessionToken,L,T,Qe])
|
|
317
|
+
const rr=null==he?void 0:he.pincode,ar=U??J
|
|
318
|
+
s(()=>{if(xe(!1),!(ae&&M&&L&&Ze&&rr))return
|
|
311
319
|
let e=!1
|
|
312
|
-
return me(Qe,
|
|
320
|
+
return me(Qe,Ze,rr,ar).then(r=>{e||xe(r.cod_allowed)}).catch(()=>{}),()=>{e=!0}},[ae,M,L,Ze,rr,ar,Qe])
|
|
313
321
|
const tr=c(()=>function(e,r){const n=null==r?void 0:r.trim()
|
|
314
322
|
if(!n)return e
|
|
315
323
|
const a={"--qr-primary":n,"--qr-primary-dark":n,"--qr-border-focus":n,"--qr-primary-light":`color-mix(in srgb, ${n} 18%, white)`}
|
|
316
|
-
return e?{...e,...a}:a}(b,
|
|
324
|
+
return e?{...e,...a}:a}(b,I),[b,I]),ir=()=>{Xe({type:"auth_skipped",step:"map"}),ie("map")},or=(e,r,n)=>{se({lat:e,lng:r,digipin:n}),Xe({type:"location_confirmed",step:"form",digipin:n,buyerId:null==fe?void 0:fe.buyerId}),ie("form")},lr=async(e,r)=>{var n
|
|
317
325
|
let a=e
|
|
318
326
|
if(pe(a),Re((null==r?void 0:r.paymentBackStep)??"form"),(null==fe?void 0:fe.sessionToken)&&(ue(Qe,fe.sessionToken,{pincode:e.pincode,digipin:e.digipin,state:e.state,district:e.district,locality:e.locality}).catch(()=>{}),!(null==r?void 0:r.skipCreate)&&!e.addressId))try{const r=await oe(Qe,fe.sessionToken,{digipin:e.digipin,lat:e.lat,lng:e.lng,state:e.state,district:e.district,locality:e.locality,pincode:e.pincode,delivery_status:e.delivery,flat_number:e.flatNumber,floor_number:e.floorNumber,building_name:e.buildingName,street_name:e.streetName,full_address_json:e,label:e.label??"home",label_text:"other"===e.label&&(null==(n=e.labelText)?void 0:n.trim())||null,is_default:!1})
|
|
319
|
-
a={...a,addressId:r.id},pe(a)}catch{}if(D&&L&&T&&
|
|
320
|
-
|
|
321
|
-
if(
|
|
322
|
-
else{if(ae&&!
|
|
323
|
-
ie("done"),u(a)}},sr=()=>"form"===te?(ie(
|
|
324
|
-
s(()=>{Z&&Z({goBack:()=>{const e=
|
|
325
|
-
return"form"===e?(ie(
|
|
326
|
-
e&&
|
|
327
|
+
a={...a,addressId:r.id},pe(a)}catch{}if(D&&L&&T&&Ze)try{const e=await ye(Qe,Ze,{address_id:a.addressId,digipin:a.digipin,lat:a.lat,lng:a.lng,state:a.state,district:a.district,locality:a.locality,pincode:a.pincode,delivery_status:a.delivery,flat_number:a.flatNumber,floor_number:a.floorNumber,building_name:a.buildingName,street_name:a.streetName})
|
|
328
|
+
Pe(e),a={...a,addressRisk:e},pe(a),Xe({type:"address_risk_scored",step:ae?"payment":"done",digipin:a.digipin,buyerId:null==fe?void 0:fe.buyerId,addressRiskLevel:e.level,addressRiskScore:e.score})}catch{Pe(null)}else Pe(null)
|
|
329
|
+
if(Xe({type:"address_completed",step:ae?"payment":"done",digipin:a.digipin,buyerId:null==fe?void 0:fe.buyerId}),ae&&Ze)ie("payment")
|
|
330
|
+
else{if(ae&&!Ze)return null==h||h(new Error("enablePayment requires phone/email auth or a codSessionToken prop.")),ie("done"),void u(a)
|
|
331
|
+
ie("done"),u(a)}},sr=()=>"form"===te?(ie(Oe?"verify-address":"map"),!0):"verify-address"===te?(De(null),se(null),ie("saved"),!0):"map"===te&&(null==fe?void 0:fe.sessionToken)?(ie("saved"),!0):"email-otp"===te?(ie("email"),!0):"otp"===te?(ie("phone"),!0):"payment"===te&&(ie($e),!0)
|
|
332
|
+
s(()=>{Z&&Z({goBack:()=>{const e=Ue.current
|
|
333
|
+
return"form"===e?(ie(Oe?"verify-address":"map"),!0):"verify-address"===e?(De(null),se(null),ie("saved"),!0):"map"===e&&(null==fe?void 0:fe.sessionToken)?(ie("saved"),!0):"email-otp"===e?(ie("email"),!0):"otp"===e?(ie("phone"),!0):"payment"===e&&(ie($e),!0)},getStep:()=>Ue.current})},[Z,null==fe?void 0:fe.sessionToken,Oe,$e]),s(()=>{const e={phone:"phone_step_viewed",email:"email_step_viewed",saved:"saved_addresses_viewed","verify-address":"verify_address_step_viewed",map:"map_step_viewed",form:"form_step_viewed",payment:"payment_step_viewed"}[te]
|
|
334
|
+
e&&Xe({type:e,step:te,buyerId:null==fe?void 0:fe.buyerId})},[te]),s(()=>{j&&"email"===ee&&(L&&T||null==h||h(new Error("enableEmailAuth requires merchantId and supabaseFunctionBaseUrl on CheckoutWidget.")))},[j,ee,L,T,h])
|
|
327
335
|
const dr=function(e,r,n){const a="verify-address"===e?"map":e
|
|
328
336
|
if("none"===r){if(n){const e=["map","form","payment","done"].indexOf(a)
|
|
329
337
|
return-1===e?0:e}return"map"===a?0:"form"===a?1:2}const t=("email"===r?n?["email","email-otp","saved","map","form","payment","done"]:["email","email-otp","saved","map","form","done"]:n?["phone","otp","saved","map","form","payment","done"]:["phone","otp","saved","map","form","done"]).indexOf(a)
|
|
330
338
|
return-1===t?0:t}(te,ee,ae),cr=function(e,r){return"none"===e?r?3:2:r?6:5}(ee,ae),ur="payment"===te?"payment":"phone"===te||"otp"===te||"email"===te||"email-otp"===te?"auth":"address",hr=(null==q?void 0:q.auth)??("email"===ee?"Email":"Mobile"),pr=[..."none"===ee?[]:[{id:"auth",label:hr,status:"auth"===ur?"active":"complete"}],{id:"address",label:(null==q?void 0:q.address)??"Address",status:"address"===ur?"active":"payment"===ur?"complete":"pending"},...ae?[{id:"payment",label:(null==q?void 0:q.payment)??"Pay",status:"payment"===ur?"active":"pending"}]:[]]
|
|
331
|
-
return e("div",{className:`qr-checkout qr-checkout--${y} qr-checkout--mobile-${g} ${f}`,style:tr,"data-testid":"quantaroute-checkout",children:["done"!==te&&e(n,{children:[e("div",{className:"qr-header",children:[e("div",{className:"qr-header__brand",children:[
|
|
332
|
-
return r("div",{className:"qr-progress",role:"progressbar","aria-valuenow":dr+1,"aria-valuemin":1,"aria-valuemax":cr+1,"aria-label":`Step ${dr+1} of ${cr+1}`,children:n.map(n=>e(a.Fragment,{children:[r("div",{className:"qr-progress__dot"+(dr>=n?" qr-progress__dot--active":"")}),n<cr&&r("div",{className:"qr-progress__line"+(dr>n?" qr-progress__line--active":"")})]},n))})})()})]}),r("div",{className:"qr-header__progress-mobile",children:r("div",{className:"qr-mobile-stepper",role:"list","aria-label":"Checkout progress",children:pr.map((n,t)=>e(a.Fragment,{children:[e("div",{className:`qr-mobile-stepper__item qr-mobile-stepper__item--${n.status}`,role:"listitem","aria-current":"active"===n.status?"step":void 0,children:[r("span",{className:"qr-mobile-stepper__mark","aria-hidden":"true",children:"complete"===n.status?"✓":t+1}),r("span",{className:"qr-mobile-stepper__label",children:n.label})]}),t<pr.length-1?r("span",{className:"qr-mobile-stepper__rail","aria-hidden":"true"}):null]},n.id))})}),B?r("div",{className:"qr-header-banner",role:"region","aria-label":"Merchant message",children:B}):null,Ee?e("div",{className:"qr-offer-banner",role:"region","aria-label":"Special offer",children:[Ee.banner_copy,Ee.banner_cta_url?e(n,{children:[" ",r("a",{href:Ee.banner_cta_url,target:"_blank",rel:"noopener noreferrer",children:"Learn more"})]}):null]}):null]}),"email"===te&&j&&r(
|
|
333
|
-
throw null==h||h(r),r}if(!e.digipin)return De(e),
|
|
334
|
-
|
|
335
|
-
return{digipin:e.digipin,lat:e.lat,lng:e.lng,state:e.state,district:e.district,division:"",locality:e.locality,pincode:e.pincode,delivery:e.delivery_status,country:"India",flatNumber:e.flat_number,floorNumber:e.floor_number,buildingName:e.building_name,streetName:e.street_name,formattedAddress:[e.flat_number,e.building_name,e.street_name,e.locality,e.district,e.state,e.pincode].filter(Boolean).join(", "),label:"work"===e.label||"other"===e.label?e.label:"home",labelText:(null==(r=e.label_text)?void 0:r.trim())||void 0,addressId:e.id}}(e),{skipCreate:!0,paymentBackStep:"saved"})}},onAddNew:()=>{De(null),se(null),ie("map")}}),"verify-address"===te&&
|
|
336
|
-
const r={...e,addressId:
|
|
337
|
-
De(null),await lr(r,{skipCreate:!0})}catch(e){null==h||h(e instanceof Error?e:new Error("Failed to verify delivery pin."))}else await lr(e)},onBack:sr,onError:h,theme:y,checkoutConfig:Qe,serviceabilitySessionToken:
|
|
338
|
-
|
|
339
|
-
function
|
|
340
|
-
try{return w(e,r)}catch{return null}},[e,r])}export{Te as AddressForm,H as CARTO_POSITRON_STYLE_URL,
|
|
339
|
+
return e("div",{className:`qr-checkout qr-checkout--${y} qr-checkout--mobile-${g} ${f}`,style:tr,"data-testid":"quantaroute-checkout",children:["done"!==te&&e(n,{children:[e("div",{className:"qr-header",children:[e("div",{className:"qr-header__brand",children:[P?r("img",{src:P,alt:"",className:"qr-header__logo-img",width:28,height:28,decoding:"async"}):e("svg",{className:"qr-header__logo","aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("path",{d:"M21 10c0 7-9 13-9 13S3 17 3 10a9 9 0 0118 0z"}),r("circle",{cx:"12",cy:"10",r:"3"})]}),r("span",{className:"qr-header__title",children:_})]}),r("div",{className:"qr-header__progress-desktop",children:(()=>{const n=Array.from({length:cr+1},(e,r)=>r)
|
|
340
|
+
return r("div",{className:"qr-progress",role:"progressbar","aria-valuenow":dr+1,"aria-valuemin":1,"aria-valuemax":cr+1,"aria-label":`Step ${dr+1} of ${cr+1}`,children:n.map(n=>e(a.Fragment,{children:[r("div",{className:"qr-progress__dot"+(dr>=n?" qr-progress__dot--active":"")}),n<cr&&r("div",{className:"qr-progress__line"+(dr>n?" qr-progress__line--active":"")})]},n))})})()})]}),r("div",{className:"qr-header__progress-mobile",children:r("div",{className:"qr-mobile-stepper",role:"list","aria-label":"Checkout progress",children:pr.map((n,t)=>e(a.Fragment,{children:[e("div",{className:`qr-mobile-stepper__item qr-mobile-stepper__item--${n.status}`,role:"listitem","aria-current":"active"===n.status?"step":void 0,children:[r("span",{className:"qr-mobile-stepper__mark","aria-hidden":"true",children:"complete"===n.status?"✓":t+1}),r("span",{className:"qr-mobile-stepper__label",children:n.label})]}),t<pr.length-1?r("span",{className:"qr-mobile-stepper__rail","aria-hidden":"true"}):null]},n.id))})}),B?r("div",{className:"qr-header-banner",role:"region","aria-label":"Merchant message",children:B}):null,Ee?e("div",{className:"qr-offer-banner",role:"region","aria-label":"Special offer",children:[Ee.banner_copy,Ee.banner_cta_url?e(n,{children:[" ",r("a",{href:Ee.banner_cta_url,target:"_blank",rel:"noopener noreferrer",children:"Learn more"})]}):null]}):null]}),"email"===te&&j&&r(He,{onOtpSent:(e,r)=>{we(e),ke(Boolean(null==r?void 0:r.reused)),Xe({type:"email_otp_sent",step:"email-otp",mobile:e}),ie("email-otp")},onSkip:ir,functionBaseUrl:T,merchantId:L}),"email-otp"===te&&j&&qe&&r(Ge,{email:qe,codeReused:Ne,onVerified:(e,r,n)=>{ge({mobile:qe,sessionToken:e,sessionId:n??"",buyerId:r}),Xe({type:"email_verified",step:"saved",buyerId:r,sessionId:n}),ie("saved")},onBack:sr,functionBaseUrl:T,merchantId:L,sessionContext:Ke}),"phone"===te&&S&&r(Ie,{onOtpSent:e=>{ge(r=>({mobile:e,sessionToken:"",sessionId:"",buyerId:(null==r?void 0:r.buyerId)??""})),Xe({type:"otp_sent",step:"otp",mobile:e}),ie("otp")},onSkip:ir,functionBaseUrl:T,merchantId:L}),"otp"===te&&fe&&r(Be,{mobile:fe.mobile,onVerified:(e,r,n)=>{ge({mobile:(null==fe?void 0:fe.mobile)??"",sessionToken:e,sessionId:n??"",buyerId:r}),Xe({type:"phone_verified",step:"saved",buyerId:r,sessionId:n}),ie("saved")},onBack:sr,functionBaseUrl:T,merchantId:L,sessionContext:Ke}),"saved"===te&&(null==fe?void 0:fe.sessionToken)&&r(Fe,{sessionToken:fe.sessionToken,functionBaseUrl:T,merchantId:L,onSelectAddress:async e=>{if(null==fe?void 0:fe.sessionToken){try{await de(Qe,fe.sessionToken,e.id)}catch(e){const r=e instanceof Error?e:new Error("Failed to select address.")
|
|
341
|
+
throw null==h||h(r),r}if(!e.digipin)return De(e),Xe({type:"saved_address_selected",step:"verify-address",buyerId:fe.buyerId}),void ie("verify-address")
|
|
342
|
+
Xe({type:"saved_address_selected",step:ae?"payment":"done",buyerId:fe.buyerId,digipin:e.digipin}),await lr(function(e){var r
|
|
343
|
+
return{digipin:e.digipin,lat:e.lat,lng:e.lng,state:e.state,district:e.district,division:"",locality:e.locality,pincode:e.pincode,delivery:e.delivery_status,country:"India",flatNumber:e.flat_number,floorNumber:e.floor_number,buildingName:e.building_name,streetName:e.street_name,formattedAddress:[e.flat_number,e.building_name,e.street_name,e.locality,e.district,e.state,e.pincode].filter(Boolean).join(", "),label:"work"===e.label||"other"===e.label?e.label:"home",labelText:(null==(r=e.label_text)?void 0:r.trim())||void 0,addressId:e.id}}(e),{skipCreate:!0,paymentBackStep:"saved"})}},onAddNew:()=>{De(null),se(null),ie("map")}}),"verify-address"===te&&Oe&&e(n,{children:[r("div",{className:"qr-order-lock-banner",role:"status",children:"Confirm your delivery pin to complete this order"}),r(re,{onLocationConfirm:or,defaultLat:Oe.lat??p,defaultLng:Oe.lng??m,mapHeight:v,theme:y,indiaBoundaryUrl:w,enableSearch:N,apiKey:l,apiBaseUrl:d,brandColor:I,mapStyle:k,mapTheme:C,embedMode:x,mapsKey:E??l})]}),"map"===te&&r(re,{onLocationConfirm:or,defaultLat:p,defaultLng:m,mapHeight:v,theme:y,indiaBoundaryUrl:w,enableSearch:N,apiKey:l,apiBaseUrl:d,brandColor:I,mapStyle:k,mapTheme:C,embedMode:x,mapsKey:E??l}),"form"===te&&le&&r(Te,{digipin:le.digipin,lat:le.lat,lng:le.lng,apiKey:l,apiBaseUrl:d,onAddressComplete:async e=>{if(Oe&&(null==fe?void 0:fe.sessionToken))try{await ce(Qe,fe.sessionToken,Oe.id,{digipin:e.digipin,lat:e.lat,lng:e.lng,state:e.state,district:e.district,locality:e.locality,pincode:e.pincode,delivery_status:e.delivery,flat_number:e.flatNumber,floor_number:e.floorNumber,building_name:e.buildingName,street_name:e.streetName})
|
|
344
|
+
const r={...e,addressId:Oe.id}
|
|
345
|
+
De(null),await lr(r,{skipCreate:!0})}catch(e){null==h||h(e instanceof Error?e:new Error("Failed to verify delivery pin."))}else await lr(e)},onBack:sr,onError:h,theme:y,checkoutConfig:Qe,serviceabilitySessionToken:Ze,enableServiceabilityCheck:O,showIndiaPostDeliveryWarning:$,serviceabilityBlockCheckout:R,initialValues:Oe?{flatNumber:Oe.flat_number,floorNumber:Oe.floor_number,buildingName:Oe.building_name,streetName:Oe.street_name,locality:Oe.locality,label:"work"===Oe.label||"other"===Oe.label?Oe.label:"home",labelText:(null==(X=Oe.label_text)?void 0:X.trim())||void 0}:void 0,submitLabel:Oe?"Confirm delivery pin":void 0}),"payment"===te&&ae&&Ze&&J&&r(Je,{checkoutConfig:Qe,sessionToken:Ze,sessionId:null==fe?void 0:fe.sessionId,amountPaise:J,enableCod:M,codAllowed:Ce&&!(null==Le?void 0:Le.interventions.includes("hide_cod")),addressRisk:Le,theme:y,onComplete:({paymentMethod:e,razorpayOrderId:r,razorpayPaymentId:n})=>{Me(e),Xe({type:"payment_method_selected",step:"done",paymentMethod:e}),ie("done"),he&&u(he),null==H||H({paymentMethod:e,sessionId:null==fe?void 0:fe.sessionId,razorpayOrderId:r,razorpayPaymentId:n})},onBack:sr,onEvent:(e,r)=>Xe({type:e,step:"payment",paymentMethod:r,buyerId:null==fe?void 0:fe.buyerId}),orderConfirmationUrl:Y}),"done"===te&&he&&e(n,{children:[r(nr,{address:he,onEditAddress:()=>{const e=null!==Ae,r=!e&&(null==fe?void 0:fe.sessionToken)?"saved":ne
|
|
346
|
+
Xe({type:"widget_reset",step:r}),e&&(ge(null),Se(null)),ie(r),se(null),pe(null),Pe(null),De(null),Me(null)}}),Ae?e("p",{className:"qr-cod-banner__text qr-cod-banner__text--ok",style:{textAlign:"center",margin:"8px 16px"},children:["Paid via ","cod"===Ae?"Cash on Delivery":"online payment"]}):null,M&&L&&T&&Ze?e(n,{children:[r(je,{checkoutConfig:Qe,sessionToken:Ze,pincode:he.pincode,cartTotalPaise:U??J,theme:y,onCodAllowedChange:xe}),K&&Ce?r(We,{copy:G??"Save more when you pay online — faster delivery & exclusive offers.",ctaUrl:Q,theme:y}):null]}):null]}),e("div",{className:"qr-footer",children:[r("span",{children:"Powered by"}),r("a",{href:"https://quantaroute.com",target:"_blank",rel:"noopener noreferrer",className:"qr-footer__link",children:"QuantaRoute"}),r("span",{className:"qr-footer__flag","aria-label":"Made in India",children:"🇮🇳"})]})]})}
|
|
347
|
+
function tr(e,r){return c(()=>{if(!C(e,r))return null
|
|
348
|
+
try{return w(e,r)}catch{return null}},[e,r])}export{Te as AddressForm,H as CARTO_POSITRON_STYLE_URL,ar as CheckoutWidget,je as CodAvailabilityBanner,J as DEFAULT_MAP_STYLE_URL,p as DIGIPIN_BOUNDS,Ge as EmailOtpStep,He as EmailStep,re as MapPinSelector,K as OPENFREEMAP_POSITRON_STYLE_URL,Be as OtpStep,Je as PaymentStep,Ie as PhoneStep,We as PrepaidNudge,V as QUANTAROUTE_INDIA_BOUNDARY_URL,R as QUANTAROUTE_MAP_STYLES,U as QUANTAROUTE_MAP_STYLES_CATALOG_URL,$ as QUANTAROUTE_MAP_STYLE_DARK_URL,D as QUANTAROUTE_MAP_STYLE_LIGHT_URL,O as QUANTAROUTE_MAP_STYLE_URL,Fe as SavedAddressStep,B as autocompleteAddress,er as captureUtmFromUrl,me as checkCodEligibility,fe as checkServiceability,P as couldBeDigiPinInput,oe as createAddress,ge as createPaymentOrder,ar as default,le as deleteAddress,Qe as detectDeviceType,Ze as detectPlatform,Ne as fetchPrepaidNudgeConfig,_e as fetchSessionOffer,g as formatDigiPin,w as getDigiPin,G as getExternalMapRuntime,N as getLatLngFromDigiPin,Ye as getWebDeviceContext,rr as hasUtmParams,q as isCompleteDigiPinInput,_ as isPotentialDigiPinInput,k as isValidDigiPin,C as isWithinIndia,ie as listAddresses,be as logFunnelEvent,I as looksLikeDigiPin,S as lookupLocation,z as mapsTransformRequest,v as normalizeDigiPinInput,ue as notifyAddressCompleted,ve as notifySessionAbandoned,T as pincodeHasDeliveryOffice,we as recordCodPayment,F as resolveQuantaRouteMapStyle,A as reverseGeocode,ye as scoreAddressRisk,de as selectAddress,he as sendEmailOtp,ne as sendOtp,se as setDefaultAddress,tr as useDigiPin,M as useGeolocation,L as validatePincode,ce as verifyDigipin,pe as verifyEmailOtp,ae as verifyOtp,qe as verifyPayment,Q as waitForExternalMapRuntime,W as withMapsKey}
|