@quantaroute/checkout 1.8.1 → 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 +18 -0
- package/dist/embed/quantaroute-checkout.css +1 -1
- package/dist/embed/quantaroute-checkout.js +1 -1
- package/dist/lib/index.d.ts +12 -1
- package/dist/lib/quantaroute-checkout.es.js +77 -67
- package/dist/lib/quantaroute-checkout.umd.js +59 -49
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/CheckoutWidget.tsx +4 -2
- package/src/components/SavedAddressStep.tsx +134 -7
- package/src/core/types.ts +12 -1
- package/src/styles/checkout.css +61 -0
|
@@ -77,19 +77,19 @@ e.code===e.PERMISSION_DENIED?n="Location permission denied. Please enable it in
|
|
|
77
77
|
function P(e,r){return e||(r?T[r]:E)}const I="https://maps.quantaroute.com"
|
|
78
78
|
function B(e,r){if(!r||!e.startsWith(I))return e
|
|
79
79
|
try{const n=new URL(e)
|
|
80
|
-
return n.searchParams.set("key",r),n.toString()}catch{return e}}function A(e){if(e)return r=>r.startsWith(I)?{url:B(r,e)}:{url:r}}const
|
|
81
|
-
function
|
|
80
|
+
return n.searchParams.set("key",r),n.toString()}catch{return e}}function A(e){if(e)return r=>r.startsWith(I)?{url:B(r,e)}:{url:r}}const M=E
|
|
81
|
+
function O(){if("undefined"==typeof window)return null
|
|
82
82
|
const e=window.maplibregl
|
|
83
83
|
return e&&"function"==typeof e.Map&&"function"==typeof e.Marker?e:null}function $(e,r,n=8e3,a=100){const t=Date.now()
|
|
84
84
|
let i=null,o=!1
|
|
85
85
|
const l=()=>{if(o)return
|
|
86
|
-
const s=
|
|
86
|
+
const s=O()
|
|
87
87
|
s?e(s):Date.now()-t>=n?r():i=window.setTimeout(l,a)}
|
|
88
88
|
return l(),()=>{o=!0,null!==i&&window.clearTimeout(i)}}function D(e,r){if(!f(e,r))return null
|
|
89
89
|
try{return m(e,r)}catch{return null}}const R="#0ea5e9"
|
|
90
90
|
function U(e=R){const r=document.createElement("div")
|
|
91
91
|
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 F(e){const r=null==e?void 0:e.querySelector(".maplibregl-ctrl-attrib")
|
|
92
|
-
r instanceof HTMLElement&&(r.classList.add("maplibregl-compact"),r.classList.remove("maplibregl-compact-show"),r.removeAttribute("open"))}const j=({onLocationConfirm:e,defaultLat:t,defaultLng:i,mapHeight:o="380px",theme:l="light",indiaBoundaryUrl:s,enableSearch:d=!0,apiKey:c,apiBaseUrl:u,brandColor:p=R,mapStyle:m,mapTheme:f,embedMode:b="bundled",mapsKey:v})=>{const _=P(m,f),g=n.useRef(null),q=n.useRef(null),C=n.useRef(null),E=t??13.00427,S=i??77.589291,L=void 0!==t&&void 0!==i,[T,I]=n.useState(E),[O
|
|
92
|
+
r instanceof HTMLElement&&(r.classList.add("maplibregl-compact"),r.classList.remove("maplibregl-compact-show"),r.removeAttribute("open"))}const j=({onLocationConfirm:e,defaultLat:t,defaultLng:i,mapHeight:o="380px",theme:l="light",indiaBoundaryUrl:s,enableSearch:d=!0,apiKey:c,apiBaseUrl:u,brandColor:p=R,mapStyle:m,mapTheme:f,embedMode:b="bundled",mapsKey:v})=>{const _=P(m,f),g=n.useRef(null),q=n.useRef(null),C=n.useRef(null),E=t??13.00427,S=i??77.589291,L=void 0!==t&&void 0!==i,[T,I]=n.useState(E),[M,O]=n.useState(S),[j,W]=n.useState(()=>D(E,S)),[z,V]=n.useState(!1),[J,H]=n.useState("loading"),[K,G]=n.useState(null),[Q,Z]=n.useState(""),[Y,X]=n.useState([]),[ee,re]=n.useState(!1),[ne,ae]=n.useState(null),[te,ie]=n.useState(!1),oe=n.useRef(null),le=n.useRef(0),se=n.useRef(null),de=n.useId(),{loading:ce,error:ue,locate:he,clearError:pe}=x(),me=n.useCallback((e,r)=>{I(e),O(r),W(D(e,r))},[]),ye=n.useCallback((e,r)=>{var n,a
|
|
93
93
|
me(e,r),null==(n=q.current)||n.flyTo({center:[r,e],zoom:18,duration:900,essential:!0}),null==(a=C.current)||a.setLngLat([r,e])},[me]),fe=n.useCallback(e=>{const r=e.target.value
|
|
94
94
|
Z(r),ae(null),oe.current&&clearTimeout(oe.current)
|
|
95
95
|
const n=++le.current,a=r.trim()
|
|
@@ -98,10 +98,10 @@ if(w(a)){re(!1)
|
|
|
98
98
|
try{const e=y(a),r=parseFloat(e.latitude),n=parseFloat(e.longitude)
|
|
99
99
|
ye(r,n),X([]),ie(!1),Z(h(a))}catch{ae("Invalid DigiPin code")}}else{if(N(a))return X([]),ie(!1),void re(!1)
|
|
100
100
|
if(a.length<3)return X([]),ie(!1),void re(!1)
|
|
101
|
-
re(!0),oe.current=setTimeout(async()=>{try{const e=c??"",r=await k(a,e,u,5,T,
|
|
101
|
+
re(!0),oe.current=setTimeout(async()=>{try{const e=c??"",r=await k(a,e,u,5,T,M)
|
|
102
102
|
if(n!==le.current)return
|
|
103
103
|
X(r),ie(r.length>0)}catch(e){if(n!==le.current)return
|
|
104
|
-
ae(e instanceof Error?e.message:"Search failed"),X([]),ie(!1)}finally{n===le.current&&re(!1)}},400)}},[c,u,ye,T,
|
|
104
|
+
ae(e instanceof Error?e.message:"Search failed"),X([]),ie(!1)}finally{n===le.current&&re(!1)}},400)}},[c,u,ye,T,M]),be=n.useCallback(e=>{var r
|
|
105
105
|
ye(e.coordinates.latitude,e.coordinates.longitude),oe.current&&clearTimeout(oe.current),le.current+=1,re(!1),Z(""),X([]),ie(!1),null==(r=se.current)||r.blur()},[ye]),ve=n.useCallback(e=>{"Escape"===e.key&&(oe.current&&clearTimeout(oe.current),le.current+=1,re(!1),X([]),ie(!1),Z(""))},[])
|
|
106
106
|
n.useEffect(()=>{if(!g.current)return
|
|
107
107
|
let e=!1,r=null,n=null
|
|
@@ -119,8 +119,8 @@ null==f||f.setLngLat([r.lng,r.lat]),u(r.lat,r.lng),y.easeTo({center:[r.lng,r.lat
|
|
|
119
119
|
q.current=a,n=o}catch(e){H("error"),G(e instanceof Error?e.message:"Map failed to initialize.")}}
|
|
120
120
|
return"external"===b?r=$(o,()=>{e||(H("unavailable"),G("Map could not load. Check your connection and try again."))}):o(a),()=>{e=!0,null==r||r(),oe.current&&clearTimeout(oe.current),C.current=null,q.current=null,null==n||n()}},[p,b,L,s,E,S,v,_,me])
|
|
121
121
|
const _e=n.useCallback(()=>{pe(),he((e,r)=>{var n,a
|
|
122
|
-
me(e,r),null==(n=q.current)||n.flyTo({center:[r,e],zoom:18,duration:1400,essential:!0}),null==(a=C.current)||a.setLngLat([r,e])})},[he,pe,me]),ge=n.useCallback(()=>{j&&e(T,
|
|
123
|
-
return r.jsxs("div",{className:"qr-map-wrapper",children:[r.jsxs("div",{className:"qr-step-header",children:[r.jsx("div",{className:"qr-step-badge",children:"1"}),r.jsxs("div",{className:"qr-step-text",children:[r.jsx("span",{className:"qr-step-title",children:"Pin Your Location"}),r.jsx("span",{className:"qr-step-sub",children:"Tap the map or drag the pin to your exact home / office"})]})]}),d&&r.jsxs("div",{className:"qr-search-bar",role:"search",children:[r.jsxs("div",{className:"qr-search-bar__input-wrap",children:[r.jsxs("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.jsx("circle",{cx:"11",cy:"11",r:"8"}),r.jsx("path",{d:"M21 21l-4.35-4.35"})]}),r.jsx("input",{ref:se,type:"search",className:"qr-search-bar__input",placeholder:"Search address, 'pharmacy near me', or DigiPin…",value:Q,onChange:fe,onKeyDown:ve,autoComplete:"off",autoCorrect:"off",autoCapitalize:"characters",spellCheck:!1,"aria-label":"Search address or DigiPin","aria-autocomplete":"list","aria-controls":te?de:void 0,"aria-expanded":te}),ee&&r.jsx("span",{className:"qr-search-bar__spinner qr-spinner qr-spinner--sm","aria-hidden":"true"}),Q&&!ee&&r.jsx("button",{type:"button",className:"qr-search-bar__clear",onClick:()=>{Z(""),X([]),ie(!1),ae(null)},"aria-label":"Clear search",tabIndex:-1,children:"×"})]}),ne&&r.jsx("p",{className:"qr-search-bar__error",role:"alert",children:ne}),te&&Y.length>0&&r.jsx("ul",{id:de,className:"qr-search-bar__dropdown",role:"listbox","aria-label":"Address suggestions",children:Y.map((e,n)=>r.jsxs("li",{className:"qr-search-bar__suggestion",role:"option","aria-selected":"false",onMouseDown:r=>{r.preventDefault(),be(e)},children:[r.jsxs("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.jsx("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.jsx("circle",{cx:"12",cy:"9",r:"2.5"})]}),r.jsxs("div",{className:"qr-search-bar__suggestion-text",children:[r.jsx("span",{className:"qr-search-bar__suggestion-name",children:e.displayName}),e.address&&e.address!==e.displayName&&r.jsx("span",{className:"qr-search-bar__suggestion-sub",children:e.address})]})]},n))}),r.jsxs("p",{className:"qr-search-bar__hint",children:[r.jsx("span",{className:"qr-search-bar__hint-chip",children:"DigiPin"}),"Type your DigiPin code for instant offline lookup — no API call"]})]}),r.jsxs("div",{className:"qr-map-outer",style:{height:o},children:[r.jsx("div",{ref:g,className:"qr-map-canvas"}),Ne&&r.jsx("div",{className:"qr-map-notice",role:"loading"===J?"status":"alert",children:"loading"===J?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}),r.jsx("span",{children:"Loading map…"})]}):K??"Map is unavailable. Please try again."}),j&&r.jsxs("div",{className:"qr-digipin-badge","aria-live":"polite","aria-label":`DigiPin: ${j}`,children:[r.jsx("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r.jsx("span",{className:"qr-digipin-badge__code",children:j})]}),!qe&&z&&r.jsx("div",{className:"qr-map-notice",role:"status",children:"Move map to India to get a DigiPin"}),r.jsx("button",{className:"qr-locate-btn"+(ce?" qr-locate-btn--loading":""),onClick:_e,disabled:ce||"ready"!==J,title:"Use my current location","aria-label":"Use my current location",type:"button",children:ce?r.jsx("span",{className:"qr-spinner","aria-hidden":"true"}):r.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("circle",{cx:"12",cy:"12",r:"3",fill:"currentColor",stroke:"none"}),r.jsx("circle",{cx:"12",cy:"12",r:"7"}),r.jsx("path",{d:"M12 2v3M12 19v3M2 12h3M19 12h3"})]})}),ue&&r.jsxs("div",{className:"qr-geo-error",role:"alert",children:[r.jsx("span",{children:ue}),r.jsx("button",{type:"button",className:"qr-geo-error__dismiss",onClick:pe,"aria-label":"Dismiss error",children:"×"})]})]}),z&&r.jsxs("div",{className:"qr-coords-strip","aria-label":"Current pin coordinates",children:[r.jsxs("span",{children:[T.toFixed(5),"° N"]}),r.jsx("span",{className:"qr-coords-sep",children:"·"}),r.jsxs("span",{children:[
|
|
122
|
+
me(e,r),null==(n=q.current)||n.flyTo({center:[r,e],zoom:18,duration:1400,essential:!0}),null==(a=C.current)||a.setLngLat([r,e])})},[he,pe,me]),ge=n.useCallback(()=>{j&&e(T,M,j)},[T,M,j,e]),qe=null!==j,we=qe&&z&&"ready"===J,Ne="ready"!==J
|
|
123
|
+
return r.jsxs("div",{className:"qr-map-wrapper",children:[r.jsxs("div",{className:"qr-step-header",children:[r.jsx("div",{className:"qr-step-badge",children:"1"}),r.jsxs("div",{className:"qr-step-text",children:[r.jsx("span",{className:"qr-step-title",children:"Pin Your Location"}),r.jsx("span",{className:"qr-step-sub",children:"Tap the map or drag the pin to your exact home / office"})]})]}),d&&r.jsxs("div",{className:"qr-search-bar",role:"search",children:[r.jsxs("div",{className:"qr-search-bar__input-wrap",children:[r.jsxs("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.jsx("circle",{cx:"11",cy:"11",r:"8"}),r.jsx("path",{d:"M21 21l-4.35-4.35"})]}),r.jsx("input",{ref:se,type:"search",className:"qr-search-bar__input",placeholder:"Search address, 'pharmacy near me', or DigiPin…",value:Q,onChange:fe,onKeyDown:ve,autoComplete:"off",autoCorrect:"off",autoCapitalize:"characters",spellCheck:!1,"aria-label":"Search address or DigiPin","aria-autocomplete":"list","aria-controls":te?de:void 0,"aria-expanded":te}),ee&&r.jsx("span",{className:"qr-search-bar__spinner qr-spinner qr-spinner--sm","aria-hidden":"true"}),Q&&!ee&&r.jsx("button",{type:"button",className:"qr-search-bar__clear",onClick:()=>{Z(""),X([]),ie(!1),ae(null)},"aria-label":"Clear search",tabIndex:-1,children:"×"})]}),ne&&r.jsx("p",{className:"qr-search-bar__error",role:"alert",children:ne}),te&&Y.length>0&&r.jsx("ul",{id:de,className:"qr-search-bar__dropdown",role:"listbox","aria-label":"Address suggestions",children:Y.map((e,n)=>r.jsxs("li",{className:"qr-search-bar__suggestion",role:"option","aria-selected":"false",onMouseDown:r=>{r.preventDefault(),be(e)},children:[r.jsxs("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.jsx("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.jsx("circle",{cx:"12",cy:"9",r:"2.5"})]}),r.jsxs("div",{className:"qr-search-bar__suggestion-text",children:[r.jsx("span",{className:"qr-search-bar__suggestion-name",children:e.displayName}),e.address&&e.address!==e.displayName&&r.jsx("span",{className:"qr-search-bar__suggestion-sub",children:e.address})]})]},n))}),r.jsxs("p",{className:"qr-search-bar__hint",children:[r.jsx("span",{className:"qr-search-bar__hint-chip",children:"DigiPin"}),"Type your DigiPin code for instant offline lookup — no API call"]})]}),r.jsxs("div",{className:"qr-map-outer",style:{height:o},children:[r.jsx("div",{ref:g,className:"qr-map-canvas"}),Ne&&r.jsx("div",{className:"qr-map-notice",role:"loading"===J?"status":"alert",children:"loading"===J?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}),r.jsx("span",{children:"Loading map…"})]}):K??"Map is unavailable. Please try again."}),j&&r.jsxs("div",{className:"qr-digipin-badge","aria-live":"polite","aria-label":`DigiPin: ${j}`,children:[r.jsx("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r.jsx("span",{className:"qr-digipin-badge__code",children:j})]}),!qe&&z&&r.jsx("div",{className:"qr-map-notice",role:"status",children:"Move map to India to get a DigiPin"}),r.jsx("button",{className:"qr-locate-btn"+(ce?" qr-locate-btn--loading":""),onClick:_e,disabled:ce||"ready"!==J,title:"Use my current location","aria-label":"Use my current location",type:"button",children:ce?r.jsx("span",{className:"qr-spinner","aria-hidden":"true"}):r.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("circle",{cx:"12",cy:"12",r:"3",fill:"currentColor",stroke:"none"}),r.jsx("circle",{cx:"12",cy:"12",r:"7"}),r.jsx("path",{d:"M12 2v3M12 19v3M2 12h3M19 12h3"})]})}),ue&&r.jsxs("div",{className:"qr-geo-error",role:"alert",children:[r.jsx("span",{children:ue}),r.jsx("button",{type:"button",className:"qr-geo-error__dismiss",onClick:pe,"aria-label":"Dismiss error",children:"×"})]})]}),z&&r.jsxs("div",{className:"qr-coords-strip","aria-label":"Current pin coordinates",children:[r.jsxs("span",{children:[T.toFixed(5),"° N"]}),r.jsx("span",{className:"qr-coords-sep",children:"·"}),r.jsxs("span",{children:[M.toFixed(5),"° E"]})]}),r.jsxs("div",{className:"qr-map-actions",children:[r.jsxs("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:ge,disabled:!we,children:["Confirm Location",r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M5 12h14M12 5l7 7-7 7"})})]}),!qe&&z&&r.jsx("p",{className:"qr-map-hint",children:"Move the pin to a location in India to continue"}),"ready"!==J&&r.jsx("p",{className:"qr-map-hint",children:"loading"===J?"Loading the map before location confirmation.":"Map is unavailable, so location confirmation is paused."})]})]})}
|
|
124
124
|
async function W(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(()=>({}))
|
|
125
125
|
if(!n.ok||!a.success)throw new Error(a.error??"Failed to send OTP. Please try again.")}async function z(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(()=>({}))
|
|
126
126
|
if(!t.ok||!i.success)throw new Error(i.error??"Invalid or expired OTP.")
|
|
@@ -227,16 +227,25 @@ try{await W({functionBaseUrl:i,merchantId:o},e),y(30),_.current=setInterval(()=>
|
|
|
227
227
|
return r.jsxs("div",{className:"qr-auth-step",children:[r.jsx("button",{type:"button",className:"qr-back-btn qr-back-btn--auth",onClick:t,disabled:c,children:r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M19 12H5M12 5l-7 7 7 7"})})}),r.jsx("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:r.jsxs("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r.jsx("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r.jsx("rect",{x:"13",y:"16",width:"22",height:"16",rx:"2",stroke:"var(--qr-primary)",strokeWidth:"1.8",fill:"none"}),r.jsx("path",{d:"M13 22h22",stroke:"var(--qr-primary)",strokeWidth:"1.8"}),r.jsx("circle",{cx:"18",cy:"29",r:"1.5",fill:"var(--qr-primary)"}),r.jsx("circle",{cx:"24",cy:"29",r:"1.5",fill:"var(--qr-primary)"}),r.jsx("circle",{cx:"30",cy:"29",r:"1.5",fill:"var(--qr-primary)"})]})}),r.jsx("h3",{className:"qr-auth-step__title",children:"Enter OTP"}),r.jsxs("p",{className:"qr-auth-step__sub",children:["Sent to ",r.jsx("strong",{children:ve(e)})]}),r.jsx("div",{className:"qr-otp-boxes",role:"group","aria-label":"Enter one-time password",children:s.map((e,n)=>r.jsx("input",{ref:e=>{v.current[n]=e},type:"text",inputMode:"numeric",maxLength:1,className:`qr-otp-box${e?" qr-otp-box--filled":""}${h?" qr-otp-box--error":""}`,value:e,onChange:e=>q(n,e.target.value),onKeyDown:e=>w(n,e),onPaste:N,onFocus:e=>e.target.select(),"aria-label":`OTP digit ${n+1}`,disabled:c,autoComplete:0===n?"one-time-code":"off"},n))}),h&&r.jsx("p",{className:"qr-auth-step__error",role:"alert",children:h}),r.jsx("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:x,disabled:!C||c,children:c?r.jsx("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}):"Verify OTP"}),r.jsx("p",{className:"qr-auth-step__resend",children:m>0?r.jsxs("span",{children:["Resend OTP in ",m,"s"]}):r.jsx("button",{type:"button",className:"qr-link-btn",onClick:E,disabled:f,children:f?"Sending…":"Resend OTP"})})]})},ge=()=>r.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M3 9.5L12 3l9 6.5V20a1 1 0 01-1 1H4a1 1 0 01-1-1V9.5z"}),r.jsx("path",{d:"M9 21V12h6v9"})]}),qe=()=>r.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("rect",{x:"2",y:"7",width:"20",height:"14",rx:"2"}),r.jsx("path",{d:"M16 7V5a2 2 0 00-2-2h-4a2 2 0 00-2 2v2"})]}),we=()=>r.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("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.jsx("circle",{cx:"12",cy:"9",r:"2.5"})]})
|
|
228
228
|
function Ne({label:e}){return"home"===e?r.jsx(ge,{}):"work"===e?r.jsx(qe,{}):r.jsx(we,{})}function ke(e){var r
|
|
229
229
|
const n=null==(r=e.label_text)?void 0:r.trim()
|
|
230
|
-
return"other"===e.label&&n?n:e.label.charAt(0).toUpperCase()+e.label.slice(1)}
|
|
231
|
-
|
|
232
|
-
|
|
230
|
+
return"other"===e.label&&n?n:e.label.charAt(0).toUpperCase()+e.label.slice(1)}const Ce=()=>r.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("circle",{cx:"12",cy:"12",r:"9"}),r.jsx("path",{d:"M12 7.5v5.5M12 16.5h.01"})]})
|
|
231
|
+
function xe({address:e,onUse:n,onDelete:a,onSetDefault:t,deleting:i,selecting:o,locked:l,unavailableReason:s,error:d}){const c=`qr-addr-note-${e.id}`,u=`qr-addr-error-${e.id}`,h=Boolean(s),p=[e.flat_number,e.building_name,e.street_name,e.locality,e.district,e.state,e.pincode].filter(Boolean),m=[e.flat_number,e.building_name,e.street_name].filter(Boolean).join(", "),y=[e.locality,e.district].filter(Boolean).join(", "),f=[e.state,e.pincode].filter(Boolean).join(" – "),b=p.length>0?void 0:e.locality||e.district||e.state
|
|
232
|
+
return r.jsxs("div",{className:`qr-addr-card${e.is_default&&!h?" qr-addr-card--default":""}${h?" qr-addr-card--unavailable":""}`,children:[r.jsxs("div",{className:"qr-addr-card__header",children:[r.jsx("div",{className:"qr-addr-card__label-icon",children:r.jsx(Ne,{label:e.label})}),r.jsx("span",{className:"qr-addr-card__label",children:ke(e)}),e.is_default&&r.jsx("span",{className:"qr-addr-card__default-badge",children:"Default"}),r.jsxs("div",{className:"qr-addr-card__actions",children:[!e.is_default&&r.jsx("button",{type:"button",className:"qr-icon-btn",title:"Set as default",onClick:t,disabled:l,"aria-label":"Set as default address",children:r.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("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.jsx("button",{type:"button",className:"qr-icon-btn qr-icon-btn--danger",title:"Delete address",onClick:a,disabled:i||l,"aria-label":"Delete address",children:i?r.jsx("span",{className:"qr-spinner qr-spinner--xs","aria-hidden":"true"}):r.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("polyline",{points:"3 6 5 6 21 6"}),r.jsx("path",{d:"M19 6l-1 14a2 2 0 01-2 2H8a2 2 0 01-2-2L5 6"}),r.jsx("path",{d:"M10 11v6M14 11v6"}),r.jsx("path",{d:"M9 6V4a1 1 0 011-1h4a1 1 0 011 1v2"})]})})]})]}),r.jsxs("div",{className:"qr-addr-card__body",children:[b?r.jsx("p",{className:"qr-addr-card__line",children:b}):r.jsxs(r.Fragment,{children:[m&&r.jsx("p",{className:"qr-addr-card__line",children:m}),y&&r.jsx("p",{className:"qr-addr-card__line qr-addr-card__line--muted",children:y}),f&&r.jsx("p",{className:"qr-addr-card__line qr-addr-card__line--muted",children:f})]}),r.jsxs("div",{className:"qr-addr-card__meta",children:[e.digipin?r.jsxs("span",{className:"qr-digipin-badge qr-digipin-badge--inline qr-digipin-badge--sm",children:[r.jsx("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r.jsx("span",{className:"qr-digipin-badge__code",children:e.digipin})]}):r.jsx("span",{className:"qr-addr-card__pending-pin",children:"Pin confirmation needed"}),e.saved_at_brand&&r.jsxs("span",{className:"qr-addr-card__brand-chip",title:`First saved at ${e.saved_at_brand}`,children:[r.jsx("svg",{viewBox:"0 0 12 12",fill:"currentColor","aria-hidden":"true",children:r.jsx("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"})}),e.saved_at_brand]})]})]}),h&&r.jsxs("div",{className:"qr-addr-card__unavailable",id:c,children:[r.jsx(Ce,{}),r.jsxs("div",{children:[r.jsxs("p",{className:"qr-addr-card__unavailable-title",children:["Not deliverable",e.pincode?` to ${e.pincode}`:""]}),r.jsx("p",{className:"qr-addr-card__unavailable-text",children:s})]})]}),r.jsx("button",{type:"button",className:"qr-btn qr-btn--full qr-btn--sm "+(h?"qr-btn--ghost":"qr-btn--primary"),onClick:n,disabled:l||h,"aria-busy":o,"aria-describedby":h?c:d?u:void 0,children:o?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}),"Confirming…"]}):h?"Can't deliver here":"Deliver here"}),d&&!h&&r.jsxs("p",{className:"qr-addr-card__error",id:u,role:"alert",children:[r.jsx(Ce,{}),d]})]})}const Ee=({sessionToken:e,functionBaseUrl:a,merchantId:t,onSelectAddress:i,onAddNew:o,checkDeliverable:l})=>{const[s,d]=n.useState([]),[c,u]=n.useState(!0),[h,p]=n.useState(null),[m,y]=n.useState(null),[f,b]=n.useState(null),[v,_]=n.useState({}),[g,q]=n.useState({}),w=n.useRef(!1),N={functionBaseUrl:a,merchantId:t},k=n.useCallback(async()=>{u(!0),p(null)
|
|
233
|
+
try{const r=await J(N,e)
|
|
233
234
|
if(0===r.length)return void o()
|
|
234
|
-
|
|
235
|
-
n.useEffect(()=>{
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
235
|
+
d(r)}catch(e){p(e instanceof Error?e.message:"Failed to load addresses.")}finally{u(!1)}},[e])
|
|
236
|
+
n.useEffect(()=>{k()},[k]),n.useEffect(()=>{if(!l||0===s.length)return
|
|
237
|
+
let e=!1
|
|
238
|
+
const r=new Map
|
|
239
|
+
for(const e of s){const n=e.pincode||e.id
|
|
240
|
+
r.set(n,[...r.get(n)??[],e])}return r.forEach(r=>{l(r[0]).then(n=>{!e&&n&&_(e=>{const a={...e}
|
|
241
|
+
return r.forEach(e=>{a[e.id]=n}),a})}).catch(()=>{})}),()=>{e=!0}},[s,l])
|
|
242
|
+
const C=n.useCallback(async r=>{y(r)
|
|
243
|
+
try{await K(N,e,r),d(e=>{const n=e.filter(e=>e.id!==r)
|
|
244
|
+
return 0===n.length&&o(),n})}catch(e){p(e instanceof Error?e.message:"Failed to delete address.")}finally{y(null)}},[e,o]),x=n.useCallback(async r=>{try{await G(N,e,r),d(e=>e.map(e=>({...e,is_default:e.id===r})))}catch(e){p(e instanceof Error?e.message:"Failed to set default.")}},[e]),E=n.useCallback(async e=>{if(!w.current){w.current=!0,b(e.id),q(r=>{const{[e.id]:n,...a}=r
|
|
245
|
+
return a})
|
|
246
|
+
try{await i(e)}catch(r){const n=r instanceof Error?r.message:"Could not use this address. Please try again."
|
|
247
|
+
"ADDRESS_UNDELIVERABLE"===(null==r?void 0:r.code)?_(r=>({...r,[e.id]:n})):q(r=>({...r,[e.id]:n})),w.current=!1,b(null)}}},[i])
|
|
248
|
+
return c?r.jsx("div",{className:"qr-saved-step",children:r.jsx("div",{className:"qr-saved-step__loading","aria-live":"polite",children:r.jsx("span",{className:"qr-spinner","aria-label":"Loading addresses"})})}):h&&0===s.length?r.jsxs("div",{className:"qr-saved-step",children:[r.jsx("p",{className:"qr-auth-step__error",role:"alert",children:h}),r.jsx("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--full",onClick:k,children:"Retry"}),r.jsx("button",{type:"button",className:"qr-auth-step__skip",onClick:o,children:"Enter address manually"})]}):r.jsxs("div",{className:"qr-saved-step",children:[r.jsxs("div",{className:"qr-step-header",children:[r.jsx("div",{className:"qr-step-badge qr-step-badge--saved",children:r.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("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.jsx("circle",{cx:"12",cy:"9",r:"2.5"})]})}),r.jsxs("div",{className:"qr-step-text",children:[r.jsx("span",{className:"qr-step-title",children:"Saved Addresses"}),r.jsx("span",{className:"qr-step-sub",children:"Pick one or add a new location"})]})]}),h&&r.jsx("p",{className:"qr-auth-step__error",role:"alert",children:h}),r.jsx("div",{className:"qr-saved-step__list",children:s.map(e=>r.jsx(xe,{address:e,onUse:()=>{E(e)},onDelete:()=>C(e.id),onSetDefault:()=>x(e.id),deleting:m===e.id,selecting:f===e.id,locked:null!==f,unavailableReason:v[e.id],error:g[e.id]},e.id))}),s.length>0&&s.every(e=>v[e.id])&&r.jsx("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."}),r.jsxs("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--full",onClick:o,disabled:null!==f,children:[r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M12 5v14M5 12h14"})}),"Add new address"]})]})},Se=({checkoutConfig:e,sessionToken:a,pincode:t,cartTotalPaise:i,theme:o="light",onCodAllowedChange:l})=>{const[s,d]=n.useState("loading"),[c,u]=n.useState(!1),[h,p]=n.useState()
|
|
240
249
|
n.useEffect(()=>{let r=!1
|
|
241
250
|
return d("loading"),(async()=>{try{const n=await re(e,a,t,i)
|
|
242
251
|
if(r)return
|
|
@@ -246,32 +255,32 @@ case"cart_value_exceeded":return"COD is not available for this order value."
|
|
|
246
255
|
case"invalid_pincode":return"Enter a valid pincode to check COD."
|
|
247
256
|
default:return"COD is not available."}}(n.reason):void 0),d("ready")}catch{r||(d("error"),u(!1),p("Could not verify COD. Try again."))}})(),()=>{r=!0}},[e,a,t,i])
|
|
248
257
|
const m="dark"===o
|
|
249
|
-
return r.jsxs("div",{className:"qr-cod-banner"+(m?" qr-cod-banner--dark":""),role:"status","aria-live":"polite",children:[r.jsx("div",{className:"qr-cod-banner__title",children:"Cash on Delivery"}),"loading"===s&&r.jsx("p",{className:"qr-cod-banner__text qr-cod-banner__text--muted",children:"Checking availability…"}),"error"===s&&r.jsx("p",{className:"qr-cod-banner__text qr-cod-banner__text--warn",children:h}),"ready"===s&&c&&r.jsx("p",{className:"qr-cod-banner__text qr-cod-banner__text--ok",children:"Available for this address."}),"ready"===s&&!c&&h&&r.jsx("p",{className:"qr-cod-banner__text qr-cod-banner__text--muted",children:h})]})},
|
|
250
|
-
return r.jsxs("div",{className:"qr-prepaid-nudge"+(t?" qr-prepaid-nudge--dark":""),role:"complementary","aria-label":"Prepaid offer",children:[r.jsx("p",{className:"qr-prepaid-nudge__copy",children:e}),n?r.jsx("a",{href:n,className:"qr-btn qr-btn--primary qr-btn--sm qr-prepaid-nudge__cta",target:"_blank",rel:"noopener noreferrer",children:"Pay online instead"}):null]})},
|
|
251
|
-
let
|
|
252
|
-
const
|
|
258
|
+
return r.jsxs("div",{className:"qr-cod-banner"+(m?" qr-cod-banner--dark":""),role:"status","aria-live":"polite",children:[r.jsx("div",{className:"qr-cod-banner__title",children:"Cash on Delivery"}),"loading"===s&&r.jsx("p",{className:"qr-cod-banner__text qr-cod-banner__text--muted",children:"Checking availability…"}),"error"===s&&r.jsx("p",{className:"qr-cod-banner__text qr-cod-banner__text--warn",children:h}),"ready"===s&&c&&r.jsx("p",{className:"qr-cod-banner__text qr-cod-banner__text--ok",children:"Available for this address."}),"ready"===s&&!c&&h&&r.jsx("p",{className:"qr-cod-banner__text qr-cod-banner__text--muted",children:h})]})},Le=({copy:e,ctaUrl:n,theme:a="light"})=>{const t="dark"===a
|
|
259
|
+
return r.jsxs("div",{className:"qr-prepaid-nudge"+(t?" qr-prepaid-nudge--dark":""),role:"complementary","aria-label":"Prepaid offer",children:[r.jsx("p",{className:"qr-prepaid-nudge__copy",children:e}),n?r.jsx("a",{href:n,className:"qr-btn qr-btn--primary qr-btn--sm qr-prepaid-nudge__cta",target:"_blank",rel:"noopener noreferrer",children:"Pay online instead"}):null]})},Te="https://checkout.razorpay.com/v1/checkout.js"
|
|
260
|
+
let Pe=null
|
|
261
|
+
const Ie=({checkoutConfig:e,sessionToken:a,sessionId:t,amountPaise:i,enableCod:o=!1,codAllowed:l=!1,addressRisk:s,theme:d="light",onComplete:c,onBack:u,onEvent:h,orderConfirmationUrl:p})=>{const[m,y]=n.useState(!1),[f,b]=n.useState(null),v="dark"===d
|
|
253
262
|
n.useEffect(()=>{null==h||h("payment_step_viewed")},[h])
|
|
254
263
|
const _=`₹${(i/100).toLocaleString("en-IN")}`,g=(null==s?void 0:s.interventions.includes("hide_cod"))??!1,q="high"===(null==s?void 0:s.level)?"high":"medium"===(null==s?void 0:s.level)?"medium":"low"
|
|
255
264
|
return r.jsxs("div",{className:"qr-payment-step"+(v?" qr-payment-step--dark":""),children:[u?r.jsx("button",{type:"button",className:"qr-back-btn qr-back-btn--auth",onClick:u,disabled:m,children:"← Back"}):null,r.jsx("h3",{className:"qr-auth-step__title",children:"Choose payment"}),r.jsxs("p",{className:"qr-auth-step__sub",children:["Order total: ",r.jsx("strong",{children:_})]}),f?r.jsx("p",{className:"qr-auth-step__error",role:"alert",children:f}):null,s&&"low"!==s.level?r.jsxs("div",{className:`qr-risk-banner qr-risk-banner--${q}`,role:"status",children:[r.jsx("strong",{children:"high"===s.level?"Address needs extra confirmation":"Address confidence check"}),r.jsx("span",{children:s.reasons[0]}),g?r.jsx("span",{children:"Cash on Delivery is disabled for this order. Online payment is still available."}):null]}):null,r.jsxs("button",{type:"button",className:"qr-payment-option qr-payment-option--primary",onClick:async()=>{y(!0),b(null)
|
|
256
|
-
try{await(window.Razorpay?Promise.resolve():
|
|
257
|
-
null==(n=document.querySelector(`script[src="${
|
|
265
|
+
try{await(window.Razorpay?Promise.resolve():Pe||(Pe=new Promise((e,r)=>{var n
|
|
266
|
+
null==(n=document.querySelector(`script[src="${Te}"]`))||n.remove()
|
|
258
267
|
const a=document.createElement("script")
|
|
259
|
-
a.src=
|
|
260
|
-
const t=e=>{window.clearTimeout(i),a.remove(),
|
|
261
|
-
a.onload=()=>{window.clearTimeout(i),window.Razorpay?e():t("Razorpay unavailable")},a.onerror=()=>t("Failed to load Razorpay"),document.body.appendChild(a)}),
|
|
268
|
+
a.src=Te,a.async=!0
|
|
269
|
+
const t=e=>{window.clearTimeout(i),a.remove(),Pe=null,r(new Error(e))},i=window.setTimeout(()=>t("Razorpay took too long to load"),15e3)
|
|
270
|
+
a.onload=()=>{window.clearTimeout(i),window.Razorpay?e():t("Razorpay unavailable")},a.onerror=()=>t("Failed to load Razorpay"),document.body.appendChild(a)}),Pe))
|
|
262
271
|
const r=await le(e,a,i)
|
|
263
272
|
await new Promise((n,i)=>{window.Razorpay?new window.Razorpay({key:r.razorpay_key_id,amount:r.amount_paise,currency:r.currency,order_id:r.razorpay_order_id,name:"Checkout",handler:async r=>{try{const i=await se(e,a,{razorpay_order_id:r.razorpay_order_id,razorpay_payment_id:r.razorpay_payment_id,razorpay_signature:r.razorpay_signature,payment_method:"prepaid"})
|
|
264
273
|
if(null==h||h("payment_method_selected",i.payment_method),c({paymentMethod:i.payment_method,razorpayOrderId:i.razorpay_order_id,razorpayPaymentId:i.razorpay_payment_id}),p){const e=p.replace("{{sessionId}}",t??"")
|
|
265
274
|
window.location.href=e}n()}catch(e){i(e)}},modal:{ondismiss:()=>i(new Error("Payment cancelled"))}}).open():i(new Error("Razorpay unavailable"))})}catch(e){b(e instanceof Error?e.message:"Payment failed")}finally{y(!1)}},disabled:m,children:[r.jsx("span",{className:"qr-payment-option__icon","aria-hidden":"true",children:"UPI"}),r.jsxs("span",{className:"qr-payment-option__copy",children:[r.jsx("span",{className:"qr-payment-option__title",children:m?"Processing...":"Pay online"}),r.jsx("span",{className:"qr-payment-option__sub",children:"UPI, cards, wallets"})]}),r.jsx("strong",{className:"qr-payment-option__amount",children:_})]}),o&&l&&!g?r.jsxs("button",{type:"button",className:"qr-payment-option qr-payment-option--secondary",onClick:async()=>{y(!0),b(null)
|
|
266
275
|
try{const r=await de(e,a)
|
|
267
|
-
null==h||h("payment_method_selected",r.payment_method),c({paymentMethod:r.payment_method})}catch(e){b(e instanceof Error?e.message:"Failed to select COD")}finally{y(!1)}},disabled:m,children:[r.jsx("span",{className:"qr-payment-option__icon","aria-hidden":"true",children:"₹"}),r.jsxs("span",{className:"qr-payment-option__copy",children:[r.jsx("span",{className:"qr-payment-option__title",children:"Cash on Delivery"}),r.jsx("span",{className:"qr-payment-option__sub",children:"Pay when the order arrives"})]})]}):null,t?r.jsxs("p",{className:"qr-payment-step__meta",children:["Session ",t.slice(0,8),"…"]}):null]})},
|
|
276
|
+
null==h||h("payment_method_selected",r.payment_method),c({paymentMethod:r.payment_method})}catch(e){b(e instanceof Error?e.message:"Failed to select COD")}finally{y(!1)}},disabled:m,children:[r.jsx("span",{className:"qr-payment-option__icon","aria-hidden":"true",children:"₹"}),r.jsxs("span",{className:"qr-payment-option__copy",children:[r.jsx("span",{className:"qr-payment-option__title",children:"Cash on Delivery"}),r.jsx("span",{className:"qr-payment-option__sub",children:"Pay when the order arrives"})]})]}):null,t?r.jsxs("p",{className:"qr-payment-step__meta",children:["Session ",t.slice(0,8),"…"]}):null]})},Be=({onOtpSent:e,onSkip:a,functionBaseUrl:t,merchantId:i})=>{const[o,l]=n.useState(""),[s,d]=n.useState(!1),[c,u]=n.useState(null),h=n.useRef(null),p=n.useCallback(e=>{l(e.target.value.trim()),u(null)},[]),m=n.useCallback(async r=>{var n
|
|
268
277
|
if(r.preventDefault(),!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(o))return u("Enter a valid email address."),void(null==(n=h.current)||n.focus())
|
|
269
278
|
d(!0),u(null)
|
|
270
279
|
try{const{reused:r}=await X({functionBaseUrl:t,merchantId:i},o)
|
|
271
280
|
e(o.toLowerCase(),{reused:r})}catch(e){u(e instanceof Error?e.message:"Failed to send code. Please try again.")}finally{d(!1)}},[o,t,i,e])
|
|
272
281
|
return r.jsxs("div",{className:"qr-auth-step",children:[r.jsx("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:r.jsxs("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r.jsx("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r.jsx("rect",{x:"11",y:"15",width:"26",height:"18",rx:"3",stroke:"var(--qr-primary)",strokeWidth:"1.8",fill:"none"}),r.jsx("path",{d:"M11 18l13 9 13-9",stroke:"var(--qr-primary)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("h3",{className:"qr-auth-step__title",children:"Faster checkout"}),r.jsx("p",{className:"qr-auth-step__sub",children:"Enter your email to load saved addresses"}),r.jsxs("form",{onSubmit:m,noValidate:!0,children:[r.jsx("div",{className:"qr-email-field"+(c?" qr-email-field--error":""),children:r.jsx("input",{ref:h,type:"email",inputMode:"email",className:"qr-email-field__input",placeholder:"you@example.com",value:o,onChange:p,autoComplete:"email","aria-label":"Email address","aria-describedby":c?"qr-email-error":void 0,"aria-invalid":!!c,disabled:s})}),c&&r.jsx("p",{id:"qr-email-error",className:"qr-auth-step__error",role:"alert",children:c}),r.jsx("button",{type:"submit",className:"qr-btn qr-btn--primary qr-btn--full",disabled:s||o.length<5,children:s?r.jsx("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}):r.jsxs(r.Fragment,{children:["Send Code",r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M5 12h14M12 5l7 7-7 7"})})]})})]}),r.jsx("button",{type:"button",className:"qr-auth-step__skip",onClick:a,disabled:s,children:"Skip, enter address manually"})]})}
|
|
273
|
-
function
|
|
274
|
-
return!n||r.length<=1?e:`${r[0]}***@${n}`}const
|
|
282
|
+
function Ae(e){const[r,n]=e.split("@")
|
|
283
|
+
return!n||r.length<=1?e:`${r[0]}***@${n}`}const Me=({email:e,codeReused:a=!1,onVerified:t,onBack:i,functionBaseUrl:o,merchantId:l,sessionContext:s})=>{const[d,c]=n.useState(Array(6).fill("")),[u,h]=n.useState(!1),[p,m]=n.useState(null),[y,f]=n.useState(60),[b,v]=n.useState(!1),_=n.useRef([]),g=n.useRef(null)
|
|
275
284
|
n.useEffect(()=>(g.current=setInterval(()=>{f(e=>e<=1?(clearInterval(g.current),0):e-1)},1e3),()=>{g.current&&clearInterval(g.current)}),[])
|
|
276
285
|
const q=e=>{var r
|
|
277
286
|
return null==(r=_.current[e])?void 0:r.focus()},w=n.useCallback((e,r)=>{const n=r.replace(/\D/g,"").slice(-1)
|
|
@@ -288,18 +297,18 @@ t(r.session_token,r.buyer_id,r.session_id)}catch(e){m(e instanceof Error?e.messa
|
|
|
288
297
|
n.useEffect(()=>{x&&!u&&E()},[x])
|
|
289
298
|
const S=n.useCallback(async()=>{if(!(y>0||b)){v(!0),m(null),c(Array(6).fill(""))
|
|
290
299
|
try{await X({functionBaseUrl:o,merchantId:l},e),f(60),g.current=setInterval(()=>{f(e=>e<=1?(clearInterval(g.current),0):e-1)},1e3),q(0)}catch(e){m(e instanceof Error?e.message:"Failed to resend code.")}finally{v(!1)}}},[y,b,o,l,e])
|
|
291
|
-
return r.jsxs("div",{className:"qr-auth-step",children:[r.jsx("button",{type:"button",className:"qr-back-btn qr-back-btn--auth",onClick:i,disabled:u,children:r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M19 12H5M12 5l-7 7 7 7"})})}),r.jsx("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:r.jsxs("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r.jsx("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r.jsx("rect",{x:"11",y:"15",width:"26",height:"18",rx:"3",stroke:"var(--qr-primary)",strokeWidth:"1.8",fill:"none"}),r.jsx("path",{d:"M11 18l13 9 13-9",stroke:"var(--qr-primary)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("h3",{className:"qr-auth-step__title",children:"Check your email"}),r.jsx("p",{className:"qr-auth-step__sub",children:a?r.jsx(r.Fragment,{children:"Use the code we sent earlier — it's still valid for your next checkout."}):r.jsxs(r.Fragment,{children:["6-digit code sent to ",r.jsx("strong",{children:
|
|
300
|
+
return r.jsxs("div",{className:"qr-auth-step",children:[r.jsx("button",{type:"button",className:"qr-back-btn qr-back-btn--auth",onClick:i,disabled:u,children:r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M19 12H5M12 5l-7 7 7 7"})})}),r.jsx("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:r.jsxs("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r.jsx("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r.jsx("rect",{x:"11",y:"15",width:"26",height:"18",rx:"3",stroke:"var(--qr-primary)",strokeWidth:"1.8",fill:"none"}),r.jsx("path",{d:"M11 18l13 9 13-9",stroke:"var(--qr-primary)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("h3",{className:"qr-auth-step__title",children:"Check your email"}),r.jsx("p",{className:"qr-auth-step__sub",children:a?r.jsx(r.Fragment,{children:"Use the code we sent earlier — it's still valid for your next checkout."}):r.jsxs(r.Fragment,{children:["6-digit code sent to ",r.jsx("strong",{children:Ae(e)})]})}),r.jsx("div",{className:"qr-otp-boxes",role:"group","aria-label":"Enter verification code",children:d.map((e,n)=>r.jsx("input",{ref:e=>{_.current[n]=e},type:"text",inputMode:"numeric",maxLength:1,className:`qr-otp-box${e?" qr-otp-box--filled":""}${p?" qr-otp-box--error":""}`,value:e,onChange:e=>w(n,e.target.value),onKeyDown:e=>N(n,e),onPaste:k,onFocus:e=>e.target.select(),"aria-label":`Code digit ${n+1}`,disabled:u,autoComplete:0===n?"one-time-code":"off"},n))}),p&&r.jsx("p",{className:"qr-auth-step__error",role:"alert",children:p}),r.jsx("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:E,disabled:!x||u,children:u?r.jsx("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}):"Verify Code"}),r.jsx("p",{className:"qr-auth-step__resend",children:y>0?r.jsxs("span",{children:["Resend code in ",y,"s"]}):r.jsx("button",{type:"button",className:"qr-link-btn",onClick:S,disabled:b,children:b?"Sending…":"Resend Code"})})]})}
|
|
292
301
|
function Oe(e){if("undefined"!=typeof window){const e=window.innerWidth
|
|
293
302
|
return e<768?"mobile":e<1024?"tablet":"desktop"}const r=(e??"").toLowerCase()
|
|
294
|
-
return/ipad|tablet/.test(r)?"tablet":/mobile|iphone|android/.test(r)?"mobile":"desktop"}function
|
|
295
|
-
return{deviceType:Oe(e),platform:"web",userAgent:e}}const
|
|
296
|
-
function
|
|
297
|
-
for(const e of
|
|
298
|
-
a&&(n[e]=a.slice(0,256))}return n}catch{return{}}}const
|
|
299
|
-
const G=q?"phone":
|
|
303
|
+
return/ipad|tablet/.test(r)?"tablet":/mobile|iphone|android/.test(r)?"mobile":"desktop"}function $e(){const e=function(){if("undefined"!=typeof navigator&&navigator.userAgent)return navigator.userAgent.slice(0,512)}()
|
|
304
|
+
return{deviceType:Oe(e),platform:"web",userAgent:e}}const De=["utm_source","utm_medium","utm_campaign"]
|
|
305
|
+
function Re(e){try{const r=new URL(e??("undefined"!=typeof window?window.location.href:"")),n={}
|
|
306
|
+
for(const e of De){const a=r.searchParams.get(e)
|
|
307
|
+
a&&(n[e]=a.slice(0,256))}return n}catch{return{}}}const Ue=({address:e,onEditAddress:n})=>r.jsxs("div",{className:"qr-success",children:[r.jsx("div",{className:"qr-success__icon","aria-hidden":"true",children:r.jsxs("svg",{viewBox:"0 0 52 52",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r.jsx("circle",{cx:"26",cy:"26",r:"26",fill:"var(--qr-success, #10b981)",opacity:"0.12"}),r.jsx("circle",{cx:"26",cy:"26",r:"20",fill:"var(--qr-success, #10b981)"}),r.jsx("path",{d:"M15 26l8 8 14-16",stroke:"white",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("h3",{className:"qr-success__title",children:"Address Saved!"}),r.jsx("p",{className:"qr-success__address",children:e.formattedAddress}),r.jsx("div",{className:"qr-success__meta",children:r.jsxs("span",{className:"qr-digipin-badge qr-digipin-badge--inline",children:[r.jsx("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r.jsx("span",{className:"qr-digipin-badge__code",children:e.digipin})]})}),r.jsx("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--sm",onClick:n,children:"Change Address"})]}),Fe=({apiKey:e,apiBaseUrl:a="https://api.quantaroute.com",onComplete:t,onError:i,defaultLat:o,defaultLng:l,theme:s="light",className:d="",style:c,mapHeight:u="min(52dvh, 420px)",title:h="Add Delivery Address",mobilePresentation:p="auto",mobileStepLabels:m,indiaBoundaryUrl:y,enableSearch:f=!0,mapStyle:b,mapTheme:v,embedMode:_,mapsKey:g,enablePhoneAuth:q=!1,merchantId:w="",supabaseFunctionBaseUrl:N="https://ikfiewesidedxozotmrl.supabase.co/functions/v1",brandColor:k,logoUrl:C,headerBanner:x,onCheckoutEvent:E,enableCod:S=!1,enableServiceabilityCheck:L=!1,enableAddressIntelligence:T=!1,showIndiaPostDeliveryWarning:P=!1,serviceabilityBlockCheckout:I,codCartTotalPaise:B,codSessionToken:A="",enableEmailAuth:M=!1,variant:O,utmParams:$,enablePayment:D=!1,paymentAmountPaise:R,onPaymentComplete:U,enablePrepaidNudge:F=!1,prepaidNudgeCopy:W,prepaidNudgeCtaUrl:z,registerController:V,orderConfirmationUrl:J})=>{var K
|
|
308
|
+
const G=q?"phone":M?"email":"none",X="phone"===G?"phone":"email"===G?"email":"map",ee=Boolean(D&&R&&N),[ae,le]=n.useState(X),[se,de]=n.useState(null),[ce,ue]=n.useState(null),[he,pe]=n.useState(null),[me,ye]=n.useState(""),[ve,ge]=n.useState(!1),[qe,we]=n.useState(!1),[Ne,ke]=n.useState(null),[Ce,xe]=n.useState(null),[Te,Pe]=n.useState(null),[Ae,Oe]=n.useState(null),[De,Fe]=n.useState("form"),je=n.useRef(ae),We=n.useMemo(()=>$??Re(),[$]),ze=n.useMemo(()=>$e(),[]),Ve=n.useMemo(()=>({utm_source:We.utm_source,utm_medium:We.utm_medium,utm_campaign:We.utm_campaign,device_type:ze.deviceType,platform:ze.platform,user_agent:ze.userAgent,experiment_variant:O}),[We,ze,O]),Je=n.useMemo(()=>({functionBaseUrl:N,merchantId:w}),[N,w]),He=(null==he?void 0:he.sessionToken)||A
|
|
300
309
|
n.useEffect(()=>{je.current=ae},[ae])
|
|
301
|
-
const Ke=n.useCallback(e=>{const r={...e,sessionId:e.sessionId??(null==he?void 0:he.sessionId),buyerId:e.buyerId??(null==he?void 0:he.buyerId),authChannel:e.authChannel??("phone"===G?"phone":"email"===G?"email":"none"),deviceType:e.deviceType??ze.deviceType,platform:e.platform??ze.platform,userAgent:e.userAgent??ze.userAgent,experimentVariant:e.experimentVariant??
|
|
302
|
-
if(E)try{E(r)}catch{}w&&N&&te(Je,{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==he?void 0:he.sessionToken).catch(()=>{})},[he,G,ze,
|
|
310
|
+
const Ke=n.useCallback(e=>{const r={...e,sessionId:e.sessionId??(null==he?void 0:he.sessionId),buyerId:e.buyerId??(null==he?void 0:he.buyerId),authChannel:e.authChannel??("phone"===G?"phone":"email"===G?"email":"none"),deviceType:e.deviceType??ze.deviceType,platform:e.platform??ze.platform,userAgent:e.userAgent??ze.userAgent,experimentVariant:e.experimentVariant??O,timestamp:(new Date).toISOString()}
|
|
311
|
+
if(E)try{E(r)}catch{}w&&N&&te(Je,{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==he?void 0:he.sessionToken).catch(()=>{})},[he,G,ze,O,E,w,N,Je])
|
|
303
312
|
n.useEffect(()=>{if(!w||!N)return
|
|
304
313
|
const e=()=>{"done"!==je.current&&(null==he?void 0:he.sessionToken)&&(ie(Je,he.sessionToken,je.current).catch(()=>{}),Ke({type:"session_abandoned",step:je.current}))}
|
|
305
314
|
return window.addEventListener("pagehide",e),()=>window.removeEventListener("pagehide",e)},[null==he?void 0:he.sessionToken,w,N,Je,Ke]),n.useEffect(()=>{(null==he?void 0:he.sessionToken)&&w&&N&&oe(Je,he.sessionToken).then(ke).catch(()=>ke(null))},[null==he?void 0:he.sessionToken,w,N,Je])
|
|
@@ -314,26 +323,27 @@ return e?{...e,...a}:a}(c,k),[c,k]),Ye=()=>{Ke({type:"auth_skipped",step:"map"})
|
|
|
314
323
|
let a=e
|
|
315
324
|
if(ue(a),Fe((null==r?void 0:r.paymentBackStep)??"form"),(null==he?void 0:he.sessionToken)&&(Y(Je,he.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 H(Je,he.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})
|
|
316
325
|
a={...a,addressId:r.id},ue(a)}catch{}if(T&&w&&N&&He)try{const e=await ne(Je,He,{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})
|
|
317
|
-
|
|
326
|
+
xe(e),a={...a,addressRisk:e},ue(a),Ke({type:"address_risk_scored",step:ee?"payment":"done",digipin:a.digipin,buyerId:null==he?void 0:he.buyerId,addressRiskLevel:e.level,addressRiskScore:e.score})}catch{xe(null)}else xe(null)
|
|
318
327
|
if(Ke({type:"address_completed",step:ee?"payment":"done",digipin:a.digipin,buyerId:null==he?void 0:he.buyerId}),ee&&He)le("payment")
|
|
319
328
|
else{if(ee&&!He)return null==i||i(new Error("enablePayment requires phone/email auth or a codSessionToken prop.")),le("done"),void t(a)
|
|
320
|
-
le("done"),t(a)}},rr=()=>"form"===ae?(le(
|
|
329
|
+
le("done"),t(a)}},rr=()=>"form"===ae?(le(Ae?"verify-address":"map"),!0):"verify-address"===ae?(Oe(null),de(null),le("saved"),!0):"map"===ae&&(null==he?void 0:he.sessionToken)?(le("saved"),!0):"email-otp"===ae?(le("email"),!0):"otp"===ae?(le("phone"),!0):"payment"===ae&&(le(De),!0)
|
|
321
330
|
n.useEffect(()=>{V&&V({goBack:()=>{const e=je.current
|
|
322
|
-
return"form"===e?(le(
|
|
323
|
-
e&&Ke({type:e,step:ae,buyerId:null==he?void 0:he.buyerId})},[ae]),n.useEffect(()=>{
|
|
331
|
+
return"form"===e?(le(Ae?"verify-address":"map"),!0):"verify-address"===e?(Oe(null),de(null),le("saved"),!0):"map"===e&&(null==he?void 0:he.sessionToken)?(le("saved"),!0):"email-otp"===e?(le("email"),!0):"otp"===e?(le("phone"),!0):"payment"===e&&(le(De),!0)},getStep:()=>je.current})},[V,null==he?void 0:he.sessionToken,Ae,De]),n.useEffect(()=>{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"}[ae]
|
|
332
|
+
e&&Ke({type:e,step:ae,buyerId:null==he?void 0:he.buyerId})},[ae]),n.useEffect(()=>{M&&"email"===G&&(w&&N||null==i||i(new Error("enableEmailAuth requires merchantId and supabaseFunctionBaseUrl on CheckoutWidget.")))},[M,G,w,N,i])
|
|
324
333
|
const nr=function(e,r,n){const a="verify-address"===e?"map":e
|
|
325
334
|
if("none"===r){if(n){const e=["map","form","payment","done"].indexOf(a)
|
|
326
335
|
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)
|
|
327
336
|
return-1===t?0:t}(ae,G,ee),ar=function(e,r){return"none"===e?r?3:2:r?6:5}(G,ee),tr="payment"===ae?"payment":"phone"===ae||"otp"===ae||"email"===ae||"email-otp"===ae?"auth":"address",ir=(null==m?void 0:m.auth)??("email"===G?"Email":"Mobile"),or=[..."none"===G?[]:[{id:"auth",label:ir,status:"auth"===tr?"active":"complete"}],{id:"address",label:(null==m?void 0:m.address)??"Address",status:"address"===tr?"active":"payment"===tr?"complete":"pending"},...ee?[{id:"payment",label:(null==m?void 0:m.payment)??"Pay",status:"payment"===tr?"active":"pending"}]:[]]
|
|
328
337
|
return r.jsxs("div",{className:`qr-checkout qr-checkout--${s} qr-checkout--mobile-${p} ${d}`,style:Ze,"data-testid":"quantaroute-checkout",children:["done"!==ae&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"qr-header",children:[r.jsxs("div",{className:"qr-header__brand",children:[C?r.jsx("img",{src:C,alt:"",className:"qr-header__logo-img",width:28,height:28,decoding:"async"}):r.jsxs("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.jsx("path",{d:"M21 10c0 7-9 13-9 13S3 17 3 10a9 9 0 0118 0z"}),r.jsx("circle",{cx:"12",cy:"10",r:"3"})]}),r.jsx("span",{className:"qr-header__title",children:h})]}),r.jsx("div",{className:"qr-header__progress-desktop",children:(()=>{const e=Array.from({length:ar+1},(e,r)=>r)
|
|
329
|
-
return r.jsx("div",{className:"qr-progress",role:"progressbar","aria-valuenow":nr+1,"aria-valuemin":1,"aria-valuemax":ar+1,"aria-label":`Step ${nr+1} of ${ar+1}`,children:e.map(e=>r.jsxs(n.Fragment,{children:[r.jsx("div",{className:"qr-progress__dot"+(nr>=e?" qr-progress__dot--active":"")}),e<ar&&r.jsx("div",{className:"qr-progress__line"+(nr>e?" qr-progress__line--active":"")})]},e))})})()})]}),r.jsx("div",{className:"qr-header__progress-mobile",children:r.jsx("div",{className:"qr-mobile-stepper",role:"list","aria-label":"Checkout progress",children:or.map((e,a)=>r.jsxs(n.Fragment,{children:[r.jsxs("div",{className:`qr-mobile-stepper__item qr-mobile-stepper__item--${e.status}`,role:"listitem","aria-current":"active"===e.status?"step":void 0,children:[r.jsx("span",{className:"qr-mobile-stepper__mark","aria-hidden":"true",children:"complete"===e.status?"✓":a+1}),r.jsx("span",{className:"qr-mobile-stepper__label",children:e.label})]}),a<or.length-1?r.jsx("span",{className:"qr-mobile-stepper__rail","aria-hidden":"true"}):null]},e.id))})}),x?r.jsx("div",{className:"qr-header-banner",role:"region","aria-label":"Merchant message",children:x}):null,Ne?r.jsxs("div",{className:"qr-offer-banner",role:"region","aria-label":"Special offer",children:[Ne.banner_copy,Ne.banner_cta_url?r.jsxs(r.Fragment,{children:[" ",r.jsx("a",{href:Ne.banner_cta_url,target:"_blank",rel:"noopener noreferrer",children:"Learn more"})]}):null]}):null]}),"email"===ae&&
|
|
338
|
+
return r.jsx("div",{className:"qr-progress",role:"progressbar","aria-valuenow":nr+1,"aria-valuemin":1,"aria-valuemax":ar+1,"aria-label":`Step ${nr+1} of ${ar+1}`,children:e.map(e=>r.jsxs(n.Fragment,{children:[r.jsx("div",{className:"qr-progress__dot"+(nr>=e?" qr-progress__dot--active":"")}),e<ar&&r.jsx("div",{className:"qr-progress__line"+(nr>e?" qr-progress__line--active":"")})]},e))})})()})]}),r.jsx("div",{className:"qr-header__progress-mobile",children:r.jsx("div",{className:"qr-mobile-stepper",role:"list","aria-label":"Checkout progress",children:or.map((e,a)=>r.jsxs(n.Fragment,{children:[r.jsxs("div",{className:`qr-mobile-stepper__item qr-mobile-stepper__item--${e.status}`,role:"listitem","aria-current":"active"===e.status?"step":void 0,children:[r.jsx("span",{className:"qr-mobile-stepper__mark","aria-hidden":"true",children:"complete"===e.status?"✓":a+1}),r.jsx("span",{className:"qr-mobile-stepper__label",children:e.label})]}),a<or.length-1?r.jsx("span",{className:"qr-mobile-stepper__rail","aria-hidden":"true"}):null]},e.id))})}),x?r.jsx("div",{className:"qr-header-banner",role:"region","aria-label":"Merchant message",children:x}):null,Ne?r.jsxs("div",{className:"qr-offer-banner",role:"region","aria-label":"Special offer",children:[Ne.banner_copy,Ne.banner_cta_url?r.jsxs(r.Fragment,{children:[" ",r.jsx("a",{href:Ne.banner_cta_url,target:"_blank",rel:"noopener noreferrer",children:"Learn more"})]}):null]}):null]}),"email"===ae&&M&&r.jsx(Be,{onOtpSent:(e,r)=>{ye(e),ge(Boolean(null==r?void 0:r.reused)),Ke({type:"email_otp_sent",step:"email-otp",mobile:e}),le("email-otp")},onSkip:Ye,functionBaseUrl:N,merchantId:w}),"email-otp"===ae&&M&&me&&r.jsx(Me,{email:me,codeReused:ve,onVerified:(e,r,n)=>{pe({mobile:me,sessionToken:e,sessionId:n??"",buyerId:r}),Ke({type:"email_verified",step:"saved",buyerId:r,sessionId:n}),le("saved")},onBack:rr,functionBaseUrl:N,merchantId:w,sessionContext:Ve}),"phone"===ae&&q&&r.jsx(be,{onOtpSent:e=>{pe(r=>({mobile:e,sessionToken:"",sessionId:"",buyerId:(null==r?void 0:r.buyerId)??""})),Ke({type:"otp_sent",step:"otp",mobile:e}),le("otp")},onSkip:Ye,functionBaseUrl:N,merchantId:w}),"otp"===ae&&he&&r.jsx(_e,{mobile:he.mobile,onVerified:(e,r,n)=>{pe({mobile:(null==he?void 0:he.mobile)??"",sessionToken:e,sessionId:n??"",buyerId:r}),Ke({type:"phone_verified",step:"saved",buyerId:r,sessionId:n}),le("saved")},onBack:rr,functionBaseUrl:N,merchantId:w,sessionContext:Ve}),"saved"===ae&&(null==he?void 0:he.sessionToken)&&r.jsx(Ee,{sessionToken:he.sessionToken,functionBaseUrl:N,merchantId:w,onSelectAddress:async e=>{if(null==he?void 0:he.sessionToken){try{await Q(Je,he.sessionToken,e.id)}catch(e){const r=e instanceof Error?e:new Error("Failed to select address.")
|
|
339
|
+
throw null==i||i(r),r}if(!e.digipin)return Oe(e),Ke({type:"saved_address_selected",step:"verify-address",buyerId:he.buyerId}),void le("verify-address")
|
|
330
340
|
Ke({type:"saved_address_selected",step:ee?"payment":"done",buyerId:he.buyerId,digipin:e.digipin}),await er(function(e){var r
|
|
331
|
-
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:()=>{
|
|
332
|
-
const r={...e,addressId:
|
|
333
|
-
|
|
334
|
-
Ke({type:"widget_reset",step:r}),e&&(pe(null),ke(null)),le(r),de(null),ue(null),
|
|
335
|
-
e.AddressForm=fe,e.CARTO_POSITRON_STYLE_URL="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",e.CheckoutWidget=
|
|
336
|
-
return n.ok&&a.success?{prepaid_nudge_copy:a.data.prepaid_nudge_copy,prepaid_nudge_cta_url:a.data.prepaid_nudge_cta_url}:null},e.fetchSessionOffer=oe,e.formatDigiPin=h,e.getDigiPin=m,e.getExternalMapRuntime=
|
|
341
|
+
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:()=>{Oe(null),de(null),le("map")}}),"verify-address"===ae&&Ae&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"qr-order-lock-banner",role:"status",children:"Confirm your delivery pin to complete this order"}),r.jsx(j,{onLocationConfirm:Xe,defaultLat:Ae.lat??o,defaultLng:Ae.lng??l,mapHeight:u,theme:s,indiaBoundaryUrl:y,enableSearch:f,apiKey:e,apiBaseUrl:a,brandColor:k,mapStyle:b,mapTheme:v,embedMode:_,mapsKey:g??e})]}),"map"===ae&&r.jsx(j,{onLocationConfirm:Xe,defaultLat:o,defaultLng:l,mapHeight:u,theme:s,indiaBoundaryUrl:y,enableSearch:f,apiKey:e,apiBaseUrl:a,brandColor:k,mapStyle:b,mapTheme:v,embedMode:_,mapsKey:g??e}),"form"===ae&&se&&r.jsx(fe,{digipin:se.digipin,lat:se.lat,lng:se.lng,apiKey:e,apiBaseUrl:a,onAddressComplete:async e=>{if(Ae&&(null==he?void 0:he.sessionToken))try{await Z(Je,he.sessionToken,Ae.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})
|
|
342
|
+
const r={...e,addressId:Ae.id}
|
|
343
|
+
Oe(null),await er(r,{skipCreate:!0})}catch(e){null==i||i(e instanceof Error?e:new Error("Failed to verify delivery pin."))}else await er(e)},onBack:rr,onError:i,theme:s,checkoutConfig:Je,serviceabilitySessionToken:He,enableServiceabilityCheck:L,showIndiaPostDeliveryWarning:P,serviceabilityBlockCheckout:I,initialValues:Ae?{flatNumber:Ae.flat_number,floorNumber:Ae.floor_number,buildingName:Ae.building_name,streetName:Ae.street_name,locality:Ae.locality,label:"work"===Ae.label||"other"===Ae.label?Ae.label:"home",labelText:(null==(K=Ae.label_text)?void 0:K.trim())||void 0}:void 0,submitLabel:Ae?"Confirm delivery pin":void 0}),"payment"===ae&&ee&&He&&R&&r.jsx(Ie,{checkoutConfig:Je,sessionToken:He,sessionId:null==he?void 0:he.sessionId,amountPaise:R,enableCod:S,codAllowed:qe&&!(null==Ce?void 0:Ce.interventions.includes("hide_cod")),addressRisk:Ce,theme:s,onComplete:({paymentMethod:e,razorpayOrderId:r,razorpayPaymentId:n})=>{Pe(e),Ke({type:"payment_method_selected",step:"done",paymentMethod:e}),le("done"),ce&&t(ce),null==U||U({paymentMethod:e,sessionId:null==he?void 0:he.sessionId,razorpayOrderId:r,razorpayPaymentId:n})},onBack:rr,onEvent:(e,r)=>Ke({type:e,step:"payment",paymentMethod:r,buyerId:null==he?void 0:he.buyerId}),orderConfirmationUrl:J}),"done"===ae&&ce&&r.jsxs(r.Fragment,{children:[r.jsx(Ue,{address:ce,onEditAddress:()=>{const e=null!==Te,r=!e&&(null==he?void 0:he.sessionToken)?"saved":X
|
|
344
|
+
Ke({type:"widget_reset",step:r}),e&&(pe(null),ke(null)),le(r),de(null),ue(null),xe(null),Oe(null),Pe(null)}}),Te?r.jsxs("p",{className:"qr-cod-banner__text qr-cod-banner__text--ok",style:{textAlign:"center",margin:"8px 16px"},children:["Paid via ","cod"===Te?"Cash on Delivery":"online payment"]}):null,S&&w&&N&&He?r.jsxs(r.Fragment,{children:[r.jsx(Se,{checkoutConfig:Je,sessionToken:He,pincode:ce.pincode,cartTotalPaise:B??R,theme:s,onCodAllowedChange:we}),F&&qe?r.jsx(Le,{copy:W??"Save more when you pay online — faster delivery & exclusive offers.",ctaUrl:z,theme:s}):null]}):null]}),r.jsxs("div",{className:"qr-footer",children:[r.jsx("span",{children:"Powered by"}),r.jsx("a",{href:"https://quantaroute.com",target:"_blank",rel:"noopener noreferrer",className:"qr-footer__link",children:"QuantaRoute"}),r.jsx("span",{className:"qr-footer__flag","aria-label":"Made in India",children:"🇮🇳"})]})]})}
|
|
345
|
+
e.AddressForm=fe,e.CARTO_POSITRON_STYLE_URL="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",e.CheckoutWidget=Fe,e.CodAvailabilityBanner=Se,e.DEFAULT_MAP_STYLE_URL=M,e.DIGIPIN_BOUNDS=i,e.EmailOtpStep=Me,e.EmailStep=Be,e.MapPinSelector=j,e.OPENFREEMAP_POSITRON_STYLE_URL="https://tiles.openfreemap.org/styles/positron",e.OtpStep=_e,e.PaymentStep=Ie,e.PhoneStep=be,e.PrepaidNudge=Le,e.QUANTAROUTE_INDIA_BOUNDARY_URL="https://maps.quantaroute.com/geojson/india.geojson",e.QUANTAROUTE_MAP_STYLES=T,e.QUANTAROUTE_MAP_STYLES_CATALOG_URL="https://maps.quantaroute.com/styles.json",e.QUANTAROUTE_MAP_STYLE_DARK_URL=L,e.QUANTAROUTE_MAP_STYLE_LIGHT_URL=S,e.QUANTAROUTE_MAP_STYLE_URL=E,e.SavedAddressStep=Ee,e.autocompleteAddress=k,e.captureUtmFromUrl=Re,e.checkCodEligibility=re,e.checkServiceability=ae,e.couldBeDigiPinInput=N,e.createAddress=H,e.createPaymentOrder=le,e.default=Fe,e.deleteAddress=K,e.detectDeviceType=Oe,e.detectPlatform=function(){return"web"},e.fetchPrepaidNudgeConfig=async function(e,r){const n=await fetch(`${e}/checkout-admin?action=cod_config`,{headers:{"x-api-key":r}}),a=await n.json().catch(()=>({}))
|
|
346
|
+
return n.ok&&a.success?{prepaid_nudge_copy:a.data.prepaid_nudge_copy,prepaid_nudge_cta_url:a.data.prepaid_nudge_cta_url}:null},e.fetchSessionOffer=oe,e.formatDigiPin=h,e.getDigiPin=m,e.getExternalMapRuntime=O,e.getLatLngFromDigiPin=y,e.getWebDeviceContext=$e,e.hasUtmParams=function(e){return Boolean(e.utm_source||e.utm_medium||e.utm_campaign)},e.isCompleteDigiPinInput=p,e.isPotentialDigiPinInput=u,e.isValidDigiPin=function(e){if(!e||"string"!=typeof e)return!1
|
|
337
347
|
if(!p(e))return!1
|
|
338
348
|
try{return y(e),!0}catch{return!1}},e.isWithinIndia=f,e.listAddresses=J,e.logFunnelEvent=te,e.looksLikeDigiPin=w,e.lookupLocation=_,e.mapsTransformRequest=A,e.normalizeDigiPinInput=c,e.notifyAddressCompleted=Y,e.notifySessionAbandoned=ie,e.pincodeHasDeliveryOffice=q,e.recordCodPayment=de,e.resolveQuantaRouteMapStyle=P,e.reverseGeocode=C,e.scoreAddressRisk=ne,e.selectAddress=Q,e.sendEmailOtp=X,e.sendOtp=W,e.setDefaultAddress=G,e.useDigiPin=function(e,r){return n.useMemo(()=>{if(!f(e,r))return null
|
|
339
349
|
try{return m(e,r)}catch{return null}},[e,r])},e.useGeolocation=x,e.validatePincode=g,e.verifyDigipin=Z,e.verifyEmailOtp=ee,e.verifyOtp=z,e.verifyPayment=se,e.waitForExternalMapRuntime=$,e.withMapsKey=B,Object.defineProperties(e,{t:{value:!0},[Symbol.toStringTag]:{value:"Module"}})})
|