@quantaroute/checkout 1.8.1 → 1.8.2
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 +7 -0
- package/dist/embed/quantaroute-checkout.js +1 -1
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/quantaroute-checkout.es.js +35 -33
- package/dist/lib/quantaroute-checkout.umd.js +11 -9
- package/package.json +1 -1
- package/src/components/CheckoutWidget.tsx +4 -2
- package/src/components/SavedAddressStep.tsx +39 -5
- package/src/core/types.ts +2 -1
package/dist/lib/index.d.ts
CHANGED
|
@@ -1014,7 +1014,8 @@ export declare interface SavedAddressStepProps {
|
|
|
1014
1014
|
sessionToken: string;
|
|
1015
1015
|
functionBaseUrl: string;
|
|
1016
1016
|
merchantId: string;
|
|
1017
|
-
|
|
1017
|
+
/** May return a promise; the step shows a spinner until it settles and an error if it rejects. */
|
|
1018
|
+
onSelectAddress: (address: SavedAddress) => void | Promise<void>;
|
|
1018
1019
|
onAddNew: () => void;
|
|
1019
1020
|
}
|
|
1020
1021
|
|
|
@@ -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 P(e){return q(e)}function I(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.")
|
|
@@ -98,9 +98,9 @@ ge(e,r),null==(n=E.current)||n.flyTo({center:[r,e],zoom:18,duration:900,essentia
|
|
|
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(P(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(I(a))return ie([]),ue(!1),void le(!1)
|
|
104
104
|
if(a.length<3)return ie([]),ue(!1),void le(!1)
|
|
105
105
|
le(!0),he.current=setTimeout(async()=>{try{const e=f??"",r=await B(a,e,b,5,M,$)
|
|
106
106
|
if(n!==pe.current)return
|
|
@@ -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"}),P=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,8 +197,8 @@ 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(()=>{P()},[P])
|
|
201
|
+
const I=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
|
|
@@ -206,12 +206,12 @@ if((null==(r=x.serviceabilityResult)?void 0:r.checked)&&!1===x.serviceabilityRes
|
|
|
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
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),O="ready"===x.status&&(null==(N=x.serviceabilityResult)?void 0:N.checked)&&!1===x.serviceabilityResult.serviceable,M="ready"===x.status&&!x.pincodeHasDelivery&&!0!==(null==(k=x.serviceabilityResult)?void 0:k.serviceable)&&!O&&((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:()=>{
|
|
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:()=>{P()},children:"Retry"})]}),"ready"===x.status&&e("form",{onSubmit:I,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})]})]})]}),O&&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.")})]})]}),M&&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"})})]})})]})]})]})},Pe=({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 Ie(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,21 +227,22 @@ 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 P=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:
|
|
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:Ie(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:P,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"})]}),Oe=()=>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"})]}),Me=()=>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
233
|
function De({label:e}){return r("home"===e?Ae:"work"===e?Oe:Me,{})}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)}function Re({address:a,onUse:t,onDelete:i,onSetDefault:o,deleting:l}){const
|
|
236
|
-
return e("div",{className:"qr-addr-card"+(a.is_default?" qr-addr-card--default":""),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,"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,"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:[
|
|
237
|
-
try{const e=await ie(
|
|
238
|
-
if(0===e.length)return void
|
|
239
|
-
|
|
240
|
-
s(()=>{
|
|
241
|
-
const
|
|
242
|
-
try{await le(
|
|
243
|
-
return 0===n.length&&
|
|
244
|
-
|
|
235
|
+
return"other"===e.label&&n?n:e.label.charAt(0).toUpperCase()+e.label.slice(1)}function Re({address:a,onUse:t,onDelete:i,onSetDefault:o,deleting:l,selecting:s,locked:d}){const c=[a.flat_number,a.building_name,a.street_name,a.locality,a.district,a.state,a.pincode].filter(Boolean),u=[a.flat_number,a.building_name,a.street_name].filter(Boolean).join(", "),h=[a.locality,a.district].filter(Boolean).join(", "),p=[a.state,a.pincode].filter(Boolean).join(" – "),m=c.length>0?void 0:a.locality||a.district||a.state
|
|
236
|
+
return e("div",{className:"qr-addr-card"+(a.is_default?" qr-addr-card--default":""),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:[m?r("p",{className:"qr-addr-card__line",children:m}):e(n,{children:[u&&r("p",{className:"qr-addr-card__line",children:u}),h&&r("p",{className:"qr-addr-card__line qr-addr-card__line--muted",children:h}),p&&r("p",{className:"qr-addr-card__line qr-addr-card__line--muted",children:p})]}),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]})]})]}),r("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full qr-btn--sm",onClick:t,disabled:d,"aria-busy":s,children:s?e(n,{children:[r("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}),"Confirming…"]}):"Deliver here"})]})}const Ue=({sessionToken:n,functionBaseUrl:a,merchantId:l,onSelectAddress:d,onAddNew:c})=>{const[u,h]=t([]),[p,m]=t(!0),[y,f]=t(null),[b,v]=t(null),[_,g]=t(null),q=o(!1),w={functionBaseUrl:a,merchantId:l},N=i(async()=>{m(!0),f(null)
|
|
237
|
+
try{const e=await ie(w,n)
|
|
238
|
+
if(0===e.length)return void c()
|
|
239
|
+
h(e)}catch(e){f(e instanceof Error?e.message:"Failed to load addresses.")}finally{m(!1)}},[n])
|
|
240
|
+
s(()=>{N()},[N])
|
|
241
|
+
const k=i(async e=>{v(e)
|
|
242
|
+
try{await le(w,n,e),h(r=>{const n=r.filter(r=>r.id!==e)
|
|
243
|
+
return 0===n.length&&c(),n})}catch(e){f(e instanceof Error?e.message:"Failed to delete address.")}finally{v(null)}},[n,c]),C=i(async e=>{try{await se(w,n,e),h(r=>r.map(r=>({...r,is_default:r.id===e})))}catch(e){f(e instanceof Error?e.message:"Failed to set default.")}},[n]),x=i(async e=>{if(!q.current){q.current=!0,g(e.id),f(null)
|
|
244
|
+
try{await d(e)}catch(e){f(e instanceof Error?e.message:"Could not use this address. Please try again."),q.current=!1,g(null)}}},[d])
|
|
245
|
+
return p?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"})})}):y&&0===u.length?e("div",{className:"qr-saved-step",children:[r("p",{className:"qr-auth-step__error",role:"alert",children:y}),r("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--full",onClick:N,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"})]})]}),y&&r("p",{className:"qr-auth-step__error",role:"alert",children:y}),r("div",{className:"qr-saved-step__list",children:u.map(e=>r(Re,{address:e,onUse:()=>{x(e)},onDelete:()=>k(e.id),onSetDefault:()=>C(e.id),deleting:b===e.id,selecting:_===e.id,locked:null!==_},e.id))}),e("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--full",onClick:c,disabled:null!==_,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"]})]})},Fe=({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()
|
|
245
246
|
return s(()=>{let e=!1
|
|
246
247
|
return u("loading"),(async()=>{try{const r=await me(n,a,i,o)
|
|
247
248
|
if(e)return
|
|
@@ -284,21 +285,21 @@ return n[e-1]="",n}),x(e-1)):"ArrowLeft"===r.key&&e>0?x(e-1):"ArrowRight"===r.ke
|
|
|
284
285
|
const r=e.clipboardData.getData("text").replace(/\D/g,"").slice(0,6)
|
|
285
286
|
if(!r)return
|
|
286
287
|
const n=Array(6).fill("")
|
|
287
|
-
r.split("").forEach((e,r)=>{n[r]=e}),y(n),_(null),x(Math.min(r.length,5))},[]),T=m.join(""),
|
|
288
|
+
r.split("").forEach((e,r)=>{n[r]=e}),y(n),_(null),x(Math.min(r.length,5))},[]),T=m.join(""),P=6===T.length&&!m.includes(""),I=i(async()=>{if(P){b(!0),_(null)
|
|
288
289
|
try{const e=await pe({functionBaseUrl:u,merchantId:h},a,T,p)
|
|
289
|
-
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)}}},[
|
|
290
|
-
s(()=>{
|
|
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)}}},[P,T,a,u,h,d,p])
|
|
291
|
+
s(()=>{P&&!f&&I()},[P])
|
|
291
292
|
const B=i(async()=>{if(!(g>0||w)){N(!0),_(null),y(Array(6).fill(""))
|
|
292
293
|
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])
|
|
293
|
-
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:He(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:
|
|
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:He(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:I,disabled:!P||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"})})]})}
|
|
294
295
|
function Ge(e){if("undefined"!=typeof window){const e=window.innerWidth
|
|
295
296
|
return e<768?"mobile":e<1024?"tablet":"desktop"}const r=(e??"").toLowerCase()
|
|
296
297
|
return/ipad|tablet/.test(r)?"tablet":/mobile|iphone|android/.test(r)?"mobile":"desktop"}function Qe(){return"web"}function Ze(){const e=function(){if("undefined"!=typeof navigator&&navigator.userAgent)return navigator.userAgent.slice(0,512)}()
|
|
297
298
|
return{deviceType:Ge(e),platform:"web",userAgent:e}}const Ye=["utm_source","utm_medium","utm_campaign"]
|
|
298
299
|
function Xe(e){try{const r=new URL(e??("undefined"!=typeof window?window.location.href:"")),n={}
|
|
299
300
|
for(const e of Ye){const a=r.searchParams.get(e)
|
|
300
|
-
a&&(n[e]=a.slice(0,256))}return n}catch{return{}}}function er(e){return Boolean(e.utm_source||e.utm_medium||e.utm_campaign)}const rr=({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"})]}),nr=({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:
|
|
301
|
-
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,
|
|
301
|
+
a&&(n[e]=a.slice(0,256))}return n}catch{return{}}}function er(e){return Boolean(e.utm_source||e.utm_medium||e.utm_campaign)}const rr=({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"})]}),nr=({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:P,logoUrl:I,headerBanner:B,onCheckoutEvent:A,enableCod:O=!1,enableServiceabilityCheck:M=!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
|
|
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,Ie]=t(null),[Ae,Oe]=t(null),[Me,De]=t(null),[$e,Re]=t("form"),We=o(te),ze=c(()=>z??Xe(),[z]),He=c(()=>Ze(),[]),Ge=c(()=>({utm_source:ze.utm_source,utm_medium:ze.utm_medium,utm_campaign:ze.utm_campaign,device_type:He.deviceType,platform:He.platform,user_agent:He.userAgent,experiment_variant:W}),[ze,He,W]),Qe=c(()=>({functionBaseUrl:T,merchantId:L}),[T,L]),Ye=(null==fe?void 0:fe.sessionToken)||F
|
|
302
303
|
s(()=>{We.current=te},[te])
|
|
303
304
|
const er=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??He.deviceType,platform:e.platform??He.platform,userAgent:e.userAgent??He.userAgent,experimentVariant:e.experimentVariant??W,timestamp:(new Date).toISOString()}
|
|
304
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,He,W,A,L,T,Qe])
|
|
@@ -312,11 +313,11 @@ return me(Qe,Ye,nr,ar).then(r=>{e||xe(r.cod_allowed)}).catch(()=>{}),()=>{e=!0}}
|
|
|
312
313
|
const tr=c(()=>function(e,r){const n=null==r?void 0:r.trim()
|
|
313
314
|
if(!n)return e
|
|
314
315
|
const a={"--qr-primary":n,"--qr-primary-dark":n,"--qr-border-focus":n,"--qr-primary-light":`color-mix(in srgb, ${n} 18%, white)`}
|
|
315
|
-
return e?{...e,...a}:a}(b,
|
|
316
|
+
return e?{...e,...a}:a}(b,P),[b,P]),ir=()=>{er({type:"auth_skipped",step:"map"}),ie("map")},or=(e,r,n)=>{se({lat:e,lng:r,digipin:n}),er({type:"location_confirmed",step:"form",digipin:n,buyerId:null==fe?void 0:fe.buyerId}),ie("form")},lr=async(e,r)=>{var n
|
|
316
317
|
let a=e
|
|
317
318
|
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})
|
|
318
319
|
a={...a,addressId:r.id},pe(a)}catch{}if(D&&L&&T&&Ye)try{const e=await ye(Qe,Ye,{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})
|
|
319
|
-
|
|
320
|
+
Ie(e),a={...a,addressRisk:e},pe(a),er({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{Ie(null)}else Ie(null)
|
|
320
321
|
if(er({type:"address_completed",step:ae?"payment":"done",digipin:a.digipin,buyerId:null==fe?void 0:fe.buyerId}),ae&&Ye)ie("payment")
|
|
321
322
|
else{if(ae&&!Ye)return null==h||h(new Error("enablePayment requires phone/email auth or a codSessionToken prop.")),ie("done"),void u(a)
|
|
322
323
|
ie("done"),u(a)}},sr=()=>"form"===te?(ie(Me?"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)
|
|
@@ -327,12 +328,13 @@ const dr=function(e,r,n){const a="verify-address"===e?"map":e
|
|
|
327
328
|
if("none"===r){if(n){const e=["map","form","payment","done"].indexOf(a)
|
|
328
329
|
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)
|
|
329
330
|
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"}]:[]]
|
|
330
|
-
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:[
|
|
331
|
-
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(Je,{onOtpSent:(e,r)=>{we(e),ke(Boolean(null==r?void 0:r.reused)),er({type:"email_otp_sent",step:"email-otp",mobile:e}),ie("email-otp")},onSkip:ir,functionBaseUrl:T,merchantId:L}),"email-otp"===te&&j&&qe&&r(Ke,{email:qe,codeReused:Ne,onVerified:(e,r,n)=>{ge({mobile:qe,sessionToken:e,sessionId:n??"",buyerId:r}),er({type:"email_verified",step:"saved",buyerId:r,sessionId:n}),ie("saved")},onBack:sr,functionBaseUrl:T,merchantId:L,sessionContext:Ge}),"phone"===te&&S&&r(
|
|
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:[I?r("img",{src:I,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)
|
|
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(Je,{onOtpSent:(e,r)=>{we(e),ke(Boolean(null==r?void 0:r.reused)),er({type:"email_otp_sent",step:"email-otp",mobile:e}),ie("email-otp")},onSkip:ir,functionBaseUrl:T,merchantId:L}),"email-otp"===te&&j&&qe&&r(Ke,{email:qe,codeReused:Ne,onVerified:(e,r,n)=>{ge({mobile:qe,sessionToken:e,sessionId:n??"",buyerId:r}),er({type:"email_verified",step:"saved",buyerId:r,sessionId:n}),ie("saved")},onBack:sr,functionBaseUrl:T,merchantId:L,sessionContext:Ge}),"phone"===te&&S&&r(Pe,{onOtpSent:e=>{ge(r=>({mobile:e,sessionToken:"",sessionId:"",buyerId:(null==r?void 0:r.buyerId)??""})),er({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}),er({type:"phone_verified",step:"saved",buyerId:r,sessionId:n}),ie("saved")},onBack:sr,functionBaseUrl:T,merchantId:L,sessionContext:Ge}),"saved"===te&&(null==fe?void 0:fe.sessionToken)&&r(Ue,{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.")
|
|
333
|
+
throw null==h||h(r),r}if(!e.digipin)return De(e),er({type:"saved_address_selected",step:"verify-address",buyerId:fe.buyerId}),void ie("verify-address")
|
|
332
334
|
er({type:"saved_address_selected",step:ae?"payment":"done",buyerId:fe.buyerId,digipin:e.digipin}),await lr(function(e){var r
|
|
333
|
-
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&&Me&&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:Me.lat??p,defaultLng:Me.lng??m,mapHeight:v,theme:y,indiaBoundaryUrl:w,enableSearch:N,apiKey:l,apiBaseUrl:d,brandColor:
|
|
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&&Me&&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:Me.lat??p,defaultLng:Me.lng??m,mapHeight:v,theme:y,indiaBoundaryUrl:w,enableSearch:N,apiKey:l,apiBaseUrl:d,brandColor:P,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:P,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(Me&&(null==fe?void 0:fe.sessionToken))try{await ce(Qe,fe.sessionToken,Me.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})
|
|
334
336
|
const r={...e,addressId:Me.id}
|
|
335
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:Ye,enableServiceabilityCheck:M,showIndiaPostDeliveryWarning:$,serviceabilityBlockCheckout:R,initialValues:Me?{flatNumber:Me.flat_number,floorNumber:Me.floor_number,buildingName:Me.building_name,streetName:Me.street_name,locality:Me.locality,label:"work"===Me.label||"other"===Me.label?Me.label:"home",labelText:(null==(X=Me.label_text)?void 0:X.trim())||void 0}:void 0,submitLabel:Me?"Confirm delivery pin":void 0}),"payment"===te&&ae&&Ye&&J&&r(Ve,{checkoutConfig:Qe,sessionToken:Ye,sessionId:null==fe?void 0:fe.sessionId,amountPaise:J,enableCod:O,codAllowed:Ce&&!(null==Le?void 0:Le.interventions.includes("hide_cod")),addressRisk:Le,theme:y,onComplete:({paymentMethod:e,razorpayOrderId:r,razorpayPaymentId:n})=>{Oe(e),er({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)=>er({type:e,step:"payment",paymentMethod:r,buyerId:null==fe?void 0:fe.buyerId}),orderConfirmationUrl:Y}),"done"===te&&he&&e(n,{children:[r(rr,{address:he,onEditAddress:()=>{const e=null!==Ae,r=!e&&(null==fe?void 0:fe.sessionToken)?"saved":ne
|
|
336
|
-
er({type:"widget_reset",step:r}),e&&(ge(null),Se(null)),ie(r),se(null),pe(null),
|
|
338
|
+
er({type:"widget_reset",step:r}),e&&(ge(null),Se(null)),ie(r),se(null),pe(null),Ie(null),De(null),Oe(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,O&&L&&T&&Ye?e(n,{children:[r(Fe,{checkoutConfig:Qe,sessionToken:Ye,pincode:he.pincode,cartTotalPaise:U??J,theme:y,onCodAllowedChange:xe}),K&&Ce?r(je,{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:"🇮🇳"})]})]})}
|
|
337
339
|
function ar(e,r){return c(()=>{if(!C(e,r))return null
|
|
338
|
-
try{return w(e,r)}catch{return null}},[e,r])}export{Te as AddressForm,H as CARTO_POSITRON_STYLE_URL,nr as CheckoutWidget,Fe as CodAvailabilityBanner,J as DEFAULT_MAP_STYLE_URL,p as DIGIPIN_BOUNDS,Ke as EmailOtpStep,Je as EmailStep,re as MapPinSelector,K as OPENFREEMAP_POSITRON_STYLE_URL,Be as OtpStep,Ve as PaymentStep,
|
|
340
|
+
try{return w(e,r)}catch{return null}},[e,r])}export{Te as AddressForm,H as CARTO_POSITRON_STYLE_URL,nr as CheckoutWidget,Fe as CodAvailabilityBanner,J as DEFAULT_MAP_STYLE_URL,p as DIGIPIN_BOUNDS,Ke as EmailOtpStep,Je as EmailStep,re as MapPinSelector,K as OPENFREEMAP_POSITRON_STYLE_URL,Be as OtpStep,Ve as PaymentStep,Pe as PhoneStep,je 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,M as QUANTAROUTE_MAP_STYLE_URL,Ue as SavedAddressStep,B as autocompleteAddress,Xe as captureUtmFromUrl,me as checkCodEligibility,fe as checkServiceability,I as couldBeDigiPinInput,oe as createAddress,ge as createPaymentOrder,nr as default,le as deleteAddress,Ge as detectDeviceType,Qe as detectPlatform,Ne as fetchPrepaidNudgeConfig,_e as fetchSessionOffer,g as formatDigiPin,w as getDigiPin,G as getExternalMapRuntime,N as getLatLngFromDigiPin,Ze as getWebDeviceContext,er as hasUtmParams,q as isCompleteDigiPinInput,_ as isPotentialDigiPinInput,k as isValidDigiPin,C as isWithinIndia,ie as listAddresses,be as logFunnelEvent,P 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,ar as useDigiPin,O as useGeolocation,L as validatePincode,ce as verifyDigipin,pe as verifyEmailOtp,ae as verifyOtp,qe as verifyPayment,Q as waitForExternalMapRuntime,W as withMapsKey}
|
|
@@ -227,16 +227,17 @@ 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)}function Ce({address:e,onUse:n,onDelete:a,onSetDefault:t,deleting:i}){const
|
|
231
|
-
return r.jsxs("div",{className:"qr-addr-card"+(e.is_default?" qr-addr-card--default":""),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,"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,"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:[
|
|
232
|
-
try{const r=await J(
|
|
230
|
+
return"other"===e.label&&n?n:e.label.charAt(0).toUpperCase()+e.label.slice(1)}function Ce({address:e,onUse:n,onDelete:a,onSetDefault:t,deleting:i,selecting:o,locked:l}){const s=[e.flat_number,e.building_name,e.street_name,e.locality,e.district,e.state,e.pincode].filter(Boolean),d=[e.flat_number,e.building_name,e.street_name].filter(Boolean).join(", "),c=[e.locality,e.district].filter(Boolean).join(", "),u=[e.state,e.pincode].filter(Boolean).join(" – "),h=s.length>0?void 0:e.locality||e.district||e.state
|
|
231
|
+
return r.jsxs("div",{className:"qr-addr-card"+(e.is_default?" qr-addr-card--default":""),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:[h?r.jsx("p",{className:"qr-addr-card__line",children:h}):r.jsxs(r.Fragment,{children:[d&&r.jsx("p",{className:"qr-addr-card__line",children:d}),c&&r.jsx("p",{className:"qr-addr-card__line qr-addr-card__line--muted",children:c}),u&&r.jsx("p",{className:"qr-addr-card__line qr-addr-card__line--muted",children:u})]}),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]})]})]}),r.jsx("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full qr-btn--sm",onClick:n,disabled:l,"aria-busy":o,children:o?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}),"Confirming…"]}):"Deliver here"})]})}const xe=({sessionToken:e,functionBaseUrl:a,merchantId:t,onSelectAddress:i,onAddNew:o})=>{const[l,s]=n.useState([]),[d,c]=n.useState(!0),[u,h]=n.useState(null),[p,m]=n.useState(null),[y,f]=n.useState(null),b=n.useRef(!1),v={functionBaseUrl:a,merchantId:t},_=n.useCallback(async()=>{c(!0),h(null)
|
|
232
|
+
try{const r=await J(v,e)
|
|
233
233
|
if(0===r.length)return void o()
|
|
234
234
|
s(r)}catch(e){h(e instanceof Error?e.message:"Failed to load addresses.")}finally{c(!1)}},[e])
|
|
235
|
-
n.useEffect(()=>{
|
|
236
|
-
const
|
|
237
|
-
try{await K(
|
|
238
|
-
return 0===n.length&&o(),n})}catch(e){h(e instanceof Error?e.message:"Failed to delete address.")}finally{m(null)}},[e,o]),
|
|
239
|
-
|
|
235
|
+
n.useEffect(()=>{_()},[_])
|
|
236
|
+
const g=n.useCallback(async r=>{m(r)
|
|
237
|
+
try{await K(v,e,r),s(e=>{const n=e.filter(e=>e.id!==r)
|
|
238
|
+
return 0===n.length&&o(),n})}catch(e){h(e instanceof Error?e.message:"Failed to delete address.")}finally{m(null)}},[e,o]),q=n.useCallback(async r=>{try{await G(v,e,r),s(e=>e.map(e=>({...e,is_default:e.id===r})))}catch(e){h(e instanceof Error?e.message:"Failed to set default.")}},[e]),w=n.useCallback(async e=>{if(!b.current){b.current=!0,f(e.id),h(null)
|
|
239
|
+
try{await i(e)}catch(e){h(e instanceof Error?e.message:"Could not use this address. Please try again."),b.current=!1,f(null)}}},[i])
|
|
240
|
+
return d?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"})})}):u&&0===l.length?r.jsxs("div",{className:"qr-saved-step",children:[r.jsx("p",{className:"qr-auth-step__error",role:"alert",children:u}),r.jsx("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--full",onClick:_,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"})]})]}),u&&r.jsx("p",{className:"qr-auth-step__error",role:"alert",children:u}),r.jsx("div",{className:"qr-saved-step__list",children:l.map(e=>r.jsx(Ce,{address:e,onUse:()=>{w(e)},onDelete:()=>g(e.id),onSetDefault:()=>q(e.id),deleting:p===e.id,selecting:y===e.id,locked:null!==y},e.id))}),r.jsxs("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--full",onClick:o,disabled:null!==y,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"]})]})},Ee=({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
241
|
n.useEffect(()=>{let r=!1
|
|
241
242
|
return d("loading"),(async()=>{try{const n=await re(e,a,t,i)
|
|
242
243
|
if(r)return
|
|
@@ -326,7 +327,8 @@ if("none"===r){if(n){const e=["map","form","payment","done"].indexOf(a)
|
|
|
326
327
|
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
328
|
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
329
|
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&&O&&r.jsx(Ie,{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&&O&&me&&r.jsx(Ae,{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(xe,{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){
|
|
330
|
+
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&&O&&r.jsx(Ie,{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&&O&&me&&r.jsx(Ae,{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(xe,{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.")
|
|
331
|
+
throw null==i||i(r),r}if(!e.digipin)return $e(e),Ke({type:"saved_address_selected",step:"verify-address",buyerId:he.buyerId}),void le("verify-address")
|
|
330
332
|
Ke({type:"saved_address_selected",step:ee?"payment":"done",buyerId:he.buyerId,digipin:e.digipin}),await er(function(e){var r
|
|
331
333
|
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:()=>{$e(null),de(null),le("map")}}),"verify-address"===ae&&Oe&&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:Oe.lat??o,defaultLng:Oe.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(Oe&&(null==he?void 0:he.sessionToken))try{await Z(Je,he.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})
|
|
332
334
|
const r={...e,addressId:Oe.id}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quantaroute/checkout",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"description": "Verified-address checkout step for Indian e-commerce: DigiPin, map pin, shopper sign-in and funnel events. Script tag for any website, React, and Expo (iOS/Android).",
|
|
5
5
|
"main": "./dist/lib/quantaroute-checkout.umd.js",
|
|
6
6
|
"module": "./dist/lib/quantaroute-checkout.es.js",
|
|
@@ -446,8 +446,10 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
446
446
|
try {
|
|
447
447
|
await selectAddress(checkoutConfig, auth.sessionToken, saved.id);
|
|
448
448
|
} catch (err: unknown) {
|
|
449
|
-
|
|
450
|
-
|
|
449
|
+
const error = err instanceof Error ? err : new Error('Failed to select address.');
|
|
450
|
+
onError?.(error);
|
|
451
|
+
// Rethrow so the saved-address step shows the error and re-enables the button.
|
|
452
|
+
throw error;
|
|
451
453
|
}
|
|
452
454
|
|
|
453
455
|
if (!saved.digipin) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useEffect, useCallback } from 'react';
|
|
1
|
+
import React, { useState, useEffect, useCallback, useRef } from 'react';
|
|
2
2
|
import { listAddresses, deleteAddress, setDefaultAddress } from '../core/checkout-api';
|
|
3
3
|
import type { SavedAddress } from '../core/checkout-api';
|
|
4
4
|
import type { SavedAddressStepProps } from '../core/types';
|
|
@@ -46,9 +46,13 @@ interface AddressCardProps {
|
|
|
46
46
|
onDelete: () => void;
|
|
47
47
|
onSetDefault: () => void;
|
|
48
48
|
deleting: boolean;
|
|
49
|
+
/** This card's "Deliver here" is in progress. */
|
|
50
|
+
selecting: boolean;
|
|
51
|
+
/** Another card is being selected: block every action. */
|
|
52
|
+
locked: boolean;
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
function AddressCard({ address, onUse, onDelete, onSetDefault, deleting }: AddressCardProps) {
|
|
55
|
+
function AddressCard({ address, onUse, onDelete, onSetDefault, deleting, selecting, locked }: AddressCardProps) {
|
|
52
56
|
const parts = [
|
|
53
57
|
address.flat_number,
|
|
54
58
|
address.building_name,
|
|
@@ -82,6 +86,7 @@ function AddressCard({ address, onUse, onDelete, onSetDefault, deleting }: Addre
|
|
|
82
86
|
className="qr-icon-btn"
|
|
83
87
|
title="Set as default"
|
|
84
88
|
onClick={onSetDefault}
|
|
89
|
+
disabled={locked}
|
|
85
90
|
aria-label="Set as default address"
|
|
86
91
|
>
|
|
87
92
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
|
|
@@ -94,7 +99,7 @@ function AddressCard({ address, onUse, onDelete, onSetDefault, deleting }: Addre
|
|
|
94
99
|
className="qr-icon-btn qr-icon-btn--danger"
|
|
95
100
|
title="Delete address"
|
|
96
101
|
onClick={onDelete}
|
|
97
|
-
disabled={deleting}
|
|
102
|
+
disabled={deleting || locked}
|
|
98
103
|
aria-label="Delete address"
|
|
99
104
|
>
|
|
100
105
|
{deleting ? (
|
|
@@ -145,8 +150,15 @@ function AddressCard({ address, onUse, onDelete, onSetDefault, deleting }: Addre
|
|
|
145
150
|
type="button"
|
|
146
151
|
className="qr-btn qr-btn--primary qr-btn--full qr-btn--sm"
|
|
147
152
|
onClick={onUse}
|
|
153
|
+
disabled={locked}
|
|
154
|
+
aria-busy={selecting}
|
|
148
155
|
>
|
|
149
|
-
|
|
156
|
+
{selecting ? (
|
|
157
|
+
<>
|
|
158
|
+
<span className="qr-spinner qr-spinner--sm" aria-hidden="true" />
|
|
159
|
+
Confirming…
|
|
160
|
+
</>
|
|
161
|
+
) : 'Deliver here'}
|
|
150
162
|
</button>
|
|
151
163
|
</div>
|
|
152
164
|
);
|
|
@@ -165,6 +177,9 @@ const SavedAddressStep: React.FC<SavedAddressStepProps> = ({
|
|
|
165
177
|
const [loadingList, setLoadingList] = useState(true);
|
|
166
178
|
const [listError, setListError] = useState<string | null>(null);
|
|
167
179
|
const [deletingId, setDeletingId] = useState<string | null>(null);
|
|
180
|
+
const [selectingId, setSelectingId] = useState<string | null>(null);
|
|
181
|
+
// A ref, not state, so a second click in the same frame is still ignored.
|
|
182
|
+
const selectingRef = useRef(false);
|
|
168
183
|
|
|
169
184
|
const config = { functionBaseUrl, merchantId };
|
|
170
185
|
|
|
@@ -216,6 +231,22 @@ const SavedAddressStep: React.FC<SavedAddressStepProps> = ({
|
|
|
216
231
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
217
232
|
}, [sessionToken]);
|
|
218
233
|
|
|
234
|
+
const handleUse = useCallback(async (address: SavedAddress) => {
|
|
235
|
+
if (selectingRef.current) return;
|
|
236
|
+
selectingRef.current = true;
|
|
237
|
+
setSelectingId(address.id);
|
|
238
|
+
setListError(null);
|
|
239
|
+
try {
|
|
240
|
+
await onSelectAddress(address);
|
|
241
|
+
// On success the widget moves to the next step and this one unmounts;
|
|
242
|
+
// keep the spinner until then.
|
|
243
|
+
} catch (err: unknown) {
|
|
244
|
+
setListError(err instanceof Error ? err.message : 'Could not use this address. Please try again.');
|
|
245
|
+
selectingRef.current = false;
|
|
246
|
+
setSelectingId(null);
|
|
247
|
+
}
|
|
248
|
+
}, [onSelectAddress]);
|
|
249
|
+
|
|
219
250
|
// ── Loading ──────────────────────────────────────────────────────────────────
|
|
220
251
|
if (loadingList) {
|
|
221
252
|
return (
|
|
@@ -266,10 +297,12 @@ const SavedAddressStep: React.FC<SavedAddressStepProps> = ({
|
|
|
266
297
|
<AddressCard
|
|
267
298
|
key={addr.id}
|
|
268
299
|
address={addr}
|
|
269
|
-
onUse={() =>
|
|
300
|
+
onUse={() => { void handleUse(addr); }}
|
|
270
301
|
onDelete={() => handleDelete(addr.id)}
|
|
271
302
|
onSetDefault={() => handleSetDefault(addr.id)}
|
|
272
303
|
deleting={deletingId === addr.id}
|
|
304
|
+
selecting={selectingId === addr.id}
|
|
305
|
+
locked={selectingId !== null}
|
|
273
306
|
/>
|
|
274
307
|
))}
|
|
275
308
|
</div>
|
|
@@ -278,6 +311,7 @@ const SavedAddressStep: React.FC<SavedAddressStepProps> = ({
|
|
|
278
311
|
type="button"
|
|
279
312
|
className="qr-btn qr-btn--ghost qr-btn--full"
|
|
280
313
|
onClick={onAddNew}
|
|
314
|
+
disabled={selectingId !== null}
|
|
281
315
|
>
|
|
282
316
|
<svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
|
|
283
317
|
<path d="M12 5v14M5 12h14" />
|