@quantaroute/checkout 1.4.1 → 1.4.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 +12 -0
- package/README.md +9 -0
- package/dist/lib/index.d.ts +7 -0
- package/dist/lib/quantaroute-checkout.es.js +18 -17
- package/dist/lib/quantaroute-checkout.umd.js +43 -42
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/AddressForm.native.tsx +55 -1
- package/src/components/AddressForm.tsx +39 -1
- package/src/components/CheckoutWidget.tsx +4 -1
- package/src/core/types.ts +9 -0
- package/src/index.ts +2 -0
- package/src/styles/checkout.css +42 -0
- package/src/styles/checkout.native.ts +48 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,18 @@ All notable changes to `@quantaroute/checkout` are documented here.
|
|
|
5
5
|
Format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
6
6
|
Release dates are from git history where available; earlier versions are estimated from the first public commit.
|
|
7
7
|
|
|
8
|
+
## [1.4.2](https://github.com/quantaroute/checkout/compare/v1.4.1...v1.4.2) — 2026-06-16
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **Home / Work / Other address label picker** on the address details step (web + native)
|
|
13
|
+
- `AddressLabel` type and `ADDRESS_LABELS` export (`'home' | 'work' | 'other'`)
|
|
14
|
+
- `CompleteAddress.label` — chosen label is passed to `createAddress()` instead of hardcoded `'home'`
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Saved addresses from the picker retain their stored label when re-selected
|
|
19
|
+
|
|
8
20
|
## [1.4.1](https://github.com/quantaroute/checkout/compare/v1.4.0...v1.4.1) — 2026-06-13
|
|
9
21
|
|
|
10
22
|
### Added
|
package/README.md
CHANGED
|
@@ -326,6 +326,8 @@ As India Post promotes DigiPin nationally, buyers can paste their 10-character c
|
|
|
326
326
|
|
|
327
327
|
When `enablePhoneAuth` is true the widget starts with a phone-entry step. Returning buyers can pick a previously saved address from any brand in the network instead of dropping the pin again.
|
|
328
328
|
|
|
329
|
+
On the address details step, buyers choose a **Home / Work / Other** label before saving. The label is stored in the checkout-addresses API and returned on `CompleteAddress.label`.
|
|
330
|
+
|
|
329
331
|
**Requires:**
|
|
330
332
|
|
|
331
333
|
1. A merchant account — sign up at [developers.quantaroute.com/onboarding](https://developers.quantaroute.com/onboarding/merchant) to get your `merchantId` and `supabaseFunctionBaseUrl`.
|
|
@@ -534,9 +536,16 @@ interface CompleteAddress {
|
|
|
534
536
|
streetName: string; // "MG Road, Action Area" (OSM pre-filled)
|
|
535
537
|
|
|
536
538
|
formattedAddress: string; // "4B, 3rd Floor, Sunshine Apartments, MG Road, ..."
|
|
539
|
+
label?: 'home' | 'work' | 'other'; // chosen on address form; defaults to home
|
|
537
540
|
}
|
|
538
541
|
```
|
|
539
542
|
|
|
543
|
+
When `enablePhoneAuth` or `enableEmailAuth` is on, the widget persists the address via `createAddress()` using this label.
|
|
544
|
+
|
|
545
|
+
```ts
|
|
546
|
+
type AddressLabel = 'home' | 'work' | 'other';
|
|
547
|
+
```
|
|
548
|
+
|
|
540
549
|
---
|
|
541
550
|
|
|
542
551
|
## Advanced usage
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { default as default_2 } from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
|
+
export declare const ADDRESS_LABELS: AddressLabel[];
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* Address components from Nominatim/OpenStreetMap (via reverse geocoding).
|
|
6
8
|
*/
|
|
@@ -36,6 +38,9 @@ export declare interface AddressFormProps {
|
|
|
36
38
|
theme?: 'light' | 'dark';
|
|
37
39
|
}
|
|
38
40
|
|
|
41
|
+
/** Label for a saved buyer address — stored in checkout-addresses API. */
|
|
42
|
+
export declare type AddressLabel = 'home' | 'work' | 'other';
|
|
43
|
+
|
|
39
44
|
export declare interface AdministrativeInfo {
|
|
40
45
|
country?: string;
|
|
41
46
|
state: string;
|
|
@@ -349,6 +354,8 @@ export declare interface CompleteAddress {
|
|
|
349
354
|
streetName: string;
|
|
350
355
|
/** Combined formatted address string */
|
|
351
356
|
formattedAddress: string;
|
|
357
|
+
/** Buyer-chosen label for saved-address book (defaults to home) */
|
|
358
|
+
label?: AddressLabel;
|
|
352
359
|
}
|
|
353
360
|
|
|
354
361
|
export declare interface Coordinates {
|
|
@@ -75,7 +75,7 @@ if(!i.success)throw new Error(i.message??"Reverse geocoding failed")
|
|
|
75
75
|
return i}function E(){const[e,r]=t({loading:!1,error:null})
|
|
76
76
|
return{...e,locate:i(e=>{navigator.geolocation?(r({loading:!0,error:null}),navigator.geolocation.getCurrentPosition(({coords:n})=>{r({loading:!1,error:null}),e(n.latitude,n.longitude)},e=>{let n="Unable to get location."
|
|
77
77
|
e.code===e.PERMISSION_DENIED?n="Location permission denied. Please enable it in browser settings.":e.code===e.POSITION_UNAVAILABLE?n="Location unavailable. Try again or place the pin manually.":e.code===e.TIMEOUT&&(n="Location request timed out. Try again."),r({loading:!1,error:n})},{enableHighAccuracy:!0,timeout:12e3,maximumAge:0})):r({loading:!1,error:"Geolocation is not supported by your browser."})},[]),clearError:i(()=>{r(e=>({...e,error:null}))},[])}}function S(e,r){if(!b(e,r))return null
|
|
78
|
-
try{return m(e,r)}catch{return null}}const L="#0ea5e9",I=({onLocationConfirm:n,defaultLat:a,defaultLng:d,mapHeight:c="380px",theme:h="light",indiaBoundaryUrl:p,enableSearch:m=!0,apiKey:y,apiBaseUrl:b,brandColor:v=L})=>{const _=o(null),g=o(null),q=o(null),w=a??13.00427,N=d??77.589291,x=void 0!==a&&void 0!==d,[I,P]=t(w),[T,A]=t(N),[B,D]=t(()=>S(w,N)),[M
|
|
78
|
+
try{return m(e,r)}catch{return null}}const L="#0ea5e9",I=({onLocationConfirm:n,defaultLat:a,defaultLng:d,mapHeight:c="380px",theme:h="light",indiaBoundaryUrl:p,enableSearch:m=!0,apiKey:y,apiBaseUrl:b,brandColor:v=L})=>{const _=o(null),g=o(null),q=o(null),w=a??13.00427,N=d??77.589291,x=void 0!==a&&void 0!==d,[I,P]=t(w),[T,A]=t(N),[B,D]=t(()=>S(w,N)),[M,O]=t(!1),[$,U]=t(""),[F,R]=t([]),[j,W]=t(!1),[J,z]=t(null),[V,H]=t(!1),K=o(null),G=o(null),Z=l(),{loading:Y,error:Q,locate:X,clearError:ee}=E(),re=i((e,r)=>{D(S(e,r))},[]),ne=i((e,r)=>{var n
|
|
79
79
|
P(e),A(r),re(e,r),g.current&&g.current.flyTo({center:[r,e],zoom:18,duration:900,essential:!0}),null==(n=q.current)||n.setLngLat([r,e])},[re]),ae=i(e=>{const r=e.target.value
|
|
80
80
|
U(r),z(null),K.current&&clearTimeout(K.current)
|
|
81
81
|
const n=r.trim()
|
|
@@ -87,7 +87,7 @@ R(r),H(r.length>0)}catch(e){z(e instanceof Error?e.message:"Search failed"),R([]
|
|
|
87
87
|
ne(e.coordinates.latitude,e.coordinates.longitude),U(""),R([]),H(!1),null==(r=G.current)||r.blur()},[ne]),ie=i(e=>{"Escape"===e.key&&(R([]),H(!1),U(""))},[])
|
|
88
88
|
s(()=>{if(!_.current)return
|
|
89
89
|
const e=p?fetch(p).then(e=>e.ok?e.json():null).catch(()=>null):Promise.resolve(null),r=x?18:9,n=new u.Map({container:_.current,style:"https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",center:[N,w],zoom:r,minZoom:6,attributionControl:!1,touchZoomRotate:!0})
|
|
90
|
-
return n.addControl(new u.AttributionControl({compact:!0,customAttribution:'© <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">OpenStreetMap</a> contributors © <a href="https://carto.com/attributions" target="_blank" rel="noopener">CARTO</a>'}),"bottom-right"),n.addControl(new u.NavigationControl({showCompass:!1}),"top-right"),n.on("load",()=>{
|
|
90
|
+
return n.addControl(new u.AttributionControl({compact:!0,customAttribution:'© <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">OpenStreetMap</a> contributors © <a href="https://carto.com/attributions" target="_blank" rel="noopener">CARTO</a>'}),"bottom-right"),n.addControl(new u.NavigationControl({showCompass:!1}),"top-right"),n.on("load",()=>{O(!0),e.then(e=>{if(e&&n.isStyleLoaded())try{n.addSource("india-boundary",{type:"geojson",data:e}),n.addLayer({id:"india-boundary-line",type:"line",source:"india-boundary",paint:{"line-color":"#94a3b8","line-width":1.5,"line-opacity":.65}})}catch{}})
|
|
91
91
|
const r=function(e=L){const r=document.createElement("div")
|
|
92
92
|
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}(v),a=new u.Marker({element:r,draggable:!0,anchor:"bottom"}).setLngLat([N,w]).addTo(n)
|
|
93
93
|
a.on("drag",()=>{const e=a.getLngLat()
|
|
@@ -97,15 +97,16 @@ const a=e.lngLat
|
|
|
97
97
|
null==(r=q.current)||r.setLngLat([a.lng,a.lat]),P(a.lat),A(a.lng),re(a.lat,a.lng),n.easeTo({center:[a.lng,a.lat],duration:200})}),g.current=n,()=>{n.remove(),g.current=null,q.current=null}},[])
|
|
98
98
|
const oe=i(()=>{ee(),X((e,r)=>{var n
|
|
99
99
|
P(e),A(r),re(e,r),g.current&&g.current.flyTo({center:[r,e],zoom:18,duration:1400,essential:!0}),null==(n=q.current)||n.setLngLat([r,e])})},[X,ee,re]),le=i(()=>{B&&n(I,T,B)},[I,T,B,n]),se=null!==B,de=se&&M
|
|
100
|
-
return e("div",{className:"qr-map-wrapper",children:[e("div",{className:"qr-step-header",children:[r("div",{className:"qr-step-badge",children:"1"}),e("div",{className:"qr-step-text",children:[r("span",{className:"qr-step-title",children:"Pin Your Location"}),r("span",{className:"qr-step-sub",children:"Tap the map or drag the pin to your exact home / office"})]})]}),m&&e("div",{className:"qr-search-bar",role:"search",children:[e("div",{className:"qr-search-bar__input-wrap",children:[e("svg",{className:"qr-search-bar__icon","aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("circle",{cx:"11",cy:"11",r:"8"}),r("path",{d:"M21 21l-4.35-4.35"})]}),r("input",{ref:G,type:"search",className:"qr-search-bar__input",placeholder:"Search address, 'pharmacy near me', or DigiPin…",value
|
|
100
|
+
return e("div",{className:"qr-map-wrapper",children:[e("div",{className:"qr-step-header",children:[r("div",{className:"qr-step-badge",children:"1"}),e("div",{className:"qr-step-text",children:[r("span",{className:"qr-step-title",children:"Pin Your Location"}),r("span",{className:"qr-step-sub",children:"Tap the map or drag the pin to your exact home / office"})]})]}),m&&e("div",{className:"qr-search-bar",role:"search",children:[e("div",{className:"qr-search-bar__input-wrap",children:[e("svg",{className:"qr-search-bar__icon","aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("circle",{cx:"11",cy:"11",r:"8"}),r("path",{d:"M21 21l-4.35-4.35"})]}),r("input",{ref:G,type:"search",className:"qr-search-bar__input",placeholder:"Search address, 'pharmacy near me', or DigiPin…",value:$,onChange:ae,onKeyDown:ie,autoComplete:"off",autoCorrect:"off",autoCapitalize:"characters",spellCheck:!1,"aria-label":"Search address or DigiPin","aria-autocomplete":"list","aria-controls":V?Z:void 0,"aria-expanded":V}),j&&r("span",{className:"qr-search-bar__spinner qr-spinner qr-spinner--sm","aria-hidden":"true"}),$&&!j&&r("button",{type:"button",className:"qr-search-bar__clear",onClick:()=>{U(""),R([]),H(!1),z(null)},"aria-label":"Clear search",tabIndex:-1,children:"×"})]}),J&&r("p",{className:"qr-search-bar__error",role:"alert",children:J}),V&&F.length>0&&r("ul",{id:Z,className:"qr-search-bar__dropdown",role:"listbox","aria-label":"Address suggestions",children:F.map((n,a)=>e("li",{className:"qr-search-bar__suggestion",role:"option","aria-selected":"false",onMouseDown:e=>{e.preventDefault(),te(n)},children:[e("svg",{className:"qr-search-bar__suggestion-icon","aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r("path",{d:"M12 2C8.134 2 5 5.134 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.866-3.134-7-7-7z"}),r("circle",{cx:"12",cy:"9",r:"2.5"})]}),e("div",{className:"qr-search-bar__suggestion-text",children:[r("span",{className:"qr-search-bar__suggestion-name",children:n.displayName}),n.address&&n.address!==n.displayName&&r("span",{className:"qr-search-bar__suggestion-sub",children:n.address})]})]},a))}),e("p",{className:"qr-search-bar__hint",children:[r("span",{className:"qr-search-bar__hint-chip",children:"DigiPin"}),"Type your DigiPin code for instant offline lookup — no API call"]})]}),e("div",{className:"qr-map-outer",style:{height:c},children:[r("div",{ref:_,className:"qr-map-canvas"}),B&&e("div",{className:"qr-digipin-badge","aria-live":"polite","aria-label":`DigiPin: ${B}`,children:[r("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r("span",{className:"qr-digipin-badge__code",children:B})]}),!se&&M&&r("div",{className:"qr-map-notice",role:"status",children:"Move map to India to get a DigiPin"}),r("button",{className:"qr-locate-btn"+(Y?" qr-locate-btn--loading":""),onClick:oe,disabled:Y,title:"Use my current location","aria-label":"Use my current location",type:"button",children:Y?r("span",{className:"qr-spinner","aria-hidden":"true"}):e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("circle",{cx:"12",cy:"12",r:"3",fill:"currentColor",stroke:"none"}),r("circle",{cx:"12",cy:"12",r:"7"}),r("path",{d:"M12 2v3M12 19v3M2 12h3M19 12h3"})]})}),Q&&e("div",{className:"qr-geo-error",role:"alert",children:[r("span",{children:Q}),r("button",{type:"button",className:"qr-geo-error__dismiss",onClick:ee,"aria-label":"Dismiss error",children:"×"})]})]}),M&&e("div",{className:"qr-coords-strip","aria-label":"Current pin coordinates",children:[e("span",{children:[I.toFixed(5),"° N"]}),r("span",{className:"qr-coords-sep",children:"·"}),e("span",{children:[T.toFixed(5),"° E"]})]}),e("div",{className:"qr-map-actions",children:[e("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:le,disabled:!de,children:["Confirm Location",r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M5 12h14M12 5l7 7-7 7"})})]}),!se&&M&&r("p",{className:"qr-map-hint",children:"Move the pin to a location in India to continue"})]})]})},P={flatNumber:"",floorNumber:"",buildingName:"",streetName:""}
|
|
101
101
|
function T(e,r){switch(r.type){case"LOAD_START":return{status:"loading"}
|
|
102
102
|
case"LOAD_SUCCESS":{const e=function(e){const r={}
|
|
103
103
|
e.name?r.buildingName=e.name:e.building_name?r.buildingName=e.building_name:e.addr_housename&&(r.buildingName=e.addr_housename)
|
|
104
104
|
const n=[]
|
|
105
105
|
return e.road&&n.push(e.road),e.suburb&&n.push(e.suburb),n.length>0&&(r.streetName=n.join(", ")),r}(r.addressComponents)
|
|
106
|
-
return{status:"ready",adminInfo:r.adminInfo,alternatives:r.alternatives||[],selectedLocality:r.adminInfo.locality,fields:{...P,...e},submitting:!1,pincodeHasDelivery:r.pincodeHasDelivery}}case"LOAD_ERROR":return{status:"error",message:r.message}
|
|
106
|
+
return{status:"ready",adminInfo:r.adminInfo,alternatives:r.alternatives||[],selectedLocality:r.adminInfo.locality,selectedLabel:"home",fields:{...P,...e},submitting:!1,pincodeHasDelivery:r.pincodeHasDelivery}}case"LOAD_ERROR":return{status:"error",message:r.message}
|
|
107
107
|
case"SET_FIELD":return"ready"!==e.status?e:{...e,fields:{...e.fields,[r.key]:r.value}}
|
|
108
108
|
case"SET_LOCALITY":return"ready"!==e.status?e:{...e,selectedLocality:r.locality}
|
|
109
|
+
case"SET_LABEL":return"ready"!==e.status?e:{...e,selectedLabel:r.label}
|
|
109
110
|
case"SUBMIT_START":return"ready"!==e.status?e:{...e,submitting:!0}
|
|
110
111
|
case"SUBMIT_END":return"ready"!==e.status?e:{...e,submitting:!1}
|
|
111
112
|
default:return e}}const A=({digipin:a,lat:t,lng:o,apiKey:l,apiBaseUrl:c,onAddressComplete:u,onBack:h,onError:p})=>{const[m,f]=d(T,{status:"loading"}),y=i(async()=>{var e
|
|
@@ -119,16 +120,16 @@ f({type:"LOAD_SUCCESS",adminInfo:r.data.administrative_info,alternatives:r.data.
|
|
|
119
120
|
f({type:"LOAD_ERROR",message:r}),null==p||p(e instanceof Error?e:new Error(r))}},[a,t,o,l,c,p])
|
|
120
121
|
s(()=>{y()},[y])
|
|
121
122
|
const b=i(e=>{if(e.preventDefault(),"ready"!==m.status)return
|
|
122
|
-
const{adminInfo:r,selectedLocality:n,fields:
|
|
123
|
+
const{adminInfo:r,selectedLocality:n,selectedLabel:i,fields:l}=m,s=[l.flatNumber,l.floorNumber?`Floor ${l.floorNumber}`:"",l.buildingName,l.streetName,n,r.district,r.state,r.pincode].filter(Boolean),d={digipin:a,lat:t,lng:o,state:r.state,district:r.district,division:r.division,locality:n,pincode:r.pincode,delivery:r.delivery,country:r.country??"India",...l,formattedAddress:s.join(", "),label:i}
|
|
123
124
|
f({type:"SUBMIT_START"})
|
|
124
|
-
try{u(
|
|
125
|
-
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"===m.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"===m.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:m.message}),r("button",{type:"button",className:"qr-btn qr-btn--secondary qr-btn--sm",onClick:()=>{y()},children:"Retry"})]}),"ready"===m.status&&e("form",{onSubmit:b,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 pin"]}),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:m.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:m.adminInfo.district})]}),e("div",{className:"qr-auto-row qr-auto-row--full",children:[r("span",{className:"qr-auto-row__label",children:"Locality"}),m.alternatives.length>0?e("select",{className:"qr-auto-row__select",value:m.selectedLocality,onChange:e=>f({type:"SET_LOCALITY",locality:e.target.value}),"aria-label":"Select locality",children:[r("option",{value:m.adminInfo.locality,children:m.adminInfo.locality}),m.alternatives.map((e,n)=>r("option",{value:e.name,children:e.name},n))]}):r("span",{className:"qr-auto-row__value",children:m.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:m.adminInfo.pincode})]})]})]}),!m.pincodeHasDelivery&&e("div",{className:"qr-pincode-banner qr-pincode-banner--warning",role:"status","aria-live":"polite",children:[r("span",{className:"qr-pincode-banner__icon","aria-hidden":"true",children:"⚠"}),e("div",{className:"qr-pincode-banner__text",children:[r("strong",{children:"Non-delivery area"}),r("span",{children:"This pincode has no India Post home-delivery office. Courier delivery may be limited — confirm with your seller before placing the order."})]})]}),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:m.fields.flatNumber,onChange:e=>f({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:m.fields.floorNumber,onChange:e=>f({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:m.fields.buildingName,onChange:e=>f({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:m.fields.streetName,onChange:e=>f({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:m.submitting||!m.fields.flatNumber.trim(),children:m.submitting?e(n,{children:[r("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}),"Saving…"]}):e(n,{children:["Save Address",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"})})]})})]})]})]})}
|
|
125
|
+
try{u(d)}finally{f({type:"SUBMIT_END"})}},[m,a,t,o,u])
|
|
126
|
+
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"===m.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"===m.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:m.message}),r("button",{type:"button",className:"qr-btn qr-btn--secondary qr-btn--sm",onClick:()=>{y()},children:"Retry"})]}),"ready"===m.status&&e("form",{onSubmit:b,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 pin"]}),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:m.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:m.adminInfo.district})]}),e("div",{className:"qr-auto-row qr-auto-row--full",children:[r("span",{className:"qr-auto-row__label",children:"Locality"}),m.alternatives.length>0?e("select",{className:"qr-auto-row__select",value:m.selectedLocality,onChange:e=>f({type:"SET_LOCALITY",locality:e.target.value}),"aria-label":"Select locality",children:[r("option",{value:m.adminInfo.locality,children:m.adminInfo.locality}),m.alternatives.map((e,n)=>r("option",{value:e.name,children:e.name},n))]}):r("span",{className:"qr-auto-row__value",children:m.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:m.adminInfo.pincode})]})]})]}),!m.pincodeHasDelivery&&e("div",{className:"qr-pincode-banner qr-pincode-banner--warning",role:"status","aria-live":"polite",children:[r("span",{className:"qr-pincode-banner__icon","aria-hidden":"true",children:"⚠"}),e("div",{className:"qr-pincode-banner__text",children:[r("strong",{children:"Non-delivery area"}),r("span",{children:"This pincode has no India Post home-delivery office. Courier delivery may be limited — confirm with your seller before placing the order."})]})]}),e("fieldset",{className:"qr-fieldset",children:[r("legend",{className:"qr-fieldset__legend",children:"Save as"}),r("div",{className:"qr-label-picker",role:"radiogroup","aria-label":"Address label",children:[{value:"home",title:"Home",icon:"🏠"},{value:"work",title:"Work",icon:"💼"},{value:"other",title:"Other",icon:"📍"}].map(({value:n,title:a,icon:t})=>e("button",{type:"button",role:"radio","aria-checked":m.selectedLabel===n,className:"qr-label-picker__option"+(m.selectedLabel===n?" qr-label-picker__option--active":""),onClick:()=>f({type:"SET_LABEL",label:n}),children:[r("span",{className:"qr-label-picker__icon","aria-hidden":"true",children:t}),r("span",{children:a})]},n))})]}),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:m.fields.flatNumber,onChange:e=>f({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:m.fields.floorNumber,onChange:e=>f({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:m.fields.buildingName,onChange:e=>f({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:m.fields.streetName,onChange:e=>f({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:m.submitting||!m.fields.flatNumber.trim(),children:m.submitting?e(n,{children:[r("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}),"Saving…"]}):e(n,{children:["Save Address",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"})})]})})]})]})]})}
|
|
126
127
|
async function B(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(()=>({}))
|
|
127
128
|
if(!n.ok||!a.success)throw new Error(a.error??"Failed to send OTP. Please try again.")}async function D(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(()=>({}))
|
|
128
129
|
if(!t.ok||!i.success)throw new Error(i.error??"Invalid or expired OTP.")
|
|
129
|
-
return i}function M(e){return{"Content-Type":"application/json","x-session-token":e}}async function
|
|
130
|
+
return i}function M(e){return{"Content-Type":"application/json","x-session-token":e}}async function O(e,r){const n=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:M(r),body:JSON.stringify({action:"list"})}),a=await n.json().catch(()=>({}))
|
|
130
131
|
if(!n.ok||!a.success)throw new Error(a.error??"Failed to load saved addresses.")
|
|
131
|
-
return a.data??[]}async function
|
|
132
|
+
return a.data??[]}async function $(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:M(r),body:JSON.stringify({action:"create",address:n})}),t=await a.json().catch(()=>({}))
|
|
132
133
|
if(!a.ok||!t.success)throw new Error(t.error??"Failed to save address.")
|
|
133
134
|
return t.data}async function U(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:M(r),body:JSON.stringify({action:"delete",address_id:n})}),t=await a.json().catch(()=>({}))
|
|
134
135
|
if(!a.ok||!t.success)throw new Error(t.error??"Failed to delete address.")}async function F(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:M(r),body:JSON.stringify({action:"set_default",address_id:n})}),t=await a.json().catch(()=>({}))
|
|
@@ -176,7 +177,7 @@ try{await B({functionBaseUrl:d,merchantId:c},n),_(30),N.current=setInterval(()=>
|
|
|
176
177
|
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:X(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":""}${y?" 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))}),y&&r("p",{className:"qr-auth-step__error",role:"alert",children:y}),r("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:I,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"})})]})},re=()=>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"})]}),ne=()=>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"})]}),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:"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"})]})
|
|
177
178
|
function te({label:e}){return r("home"===e?re:"work"===e?ne:ae,{})}function ie({address:a,onUse:t,onDelete:i,onSetDefault:o,deleting:l}){const s=[a.flat_number,a.building_name,a.street_name,a.locality,a.district,a.state,a.pincode].filter(Boolean),d=[a.flat_number,a.building_name,a.street_name].filter(Boolean).join(", "),c=[a.locality,a.district].filter(Boolean).join(", "),u=[a.state,a.pincode].filter(Boolean).join(" – "),h=s.length>0?void 0:a.locality||a.district||a.state
|
|
178
179
|
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(te,{label:a.label})}),r("span",{className:"qr-addr-card__label",children:a.label.charAt(0).toUpperCase()+a.label.slice(1)}),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:[h?r("p",{className:"qr-addr-card__line",children:h}):e(n,{children:[d&&r("p",{className:"qr-addr-card__line",children:d}),c&&r("p",{className:"qr-addr-card__line qr-addr-card__line--muted",children:c}),u&&r("p",{className:"qr-addr-card__line qr-addr-card__line--muted",children:u})]}),e("div",{className:"qr-addr-card__meta",children:[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})]}),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,children:"Deliver here"})]})}const oe=({sessionToken:n,functionBaseUrl:a,merchantId:o,onSelectAddress:l,onAddNew:d})=>{const[c,u]=t([]),[h,p]=t(!0),[m,f]=t(null),[y,b]=t(null),v={functionBaseUrl:a,merchantId:o},_=i(async()=>{p(!0),f(null)
|
|
179
|
-
try{const e=await
|
|
180
|
+
try{const e=await O(v,n)
|
|
180
181
|
if(0===e.length)return void d()
|
|
181
182
|
u(e)}catch(e){f(e instanceof Error?e.message:"Failed to load addresses.")}finally{p(!1)}},[n])
|
|
182
183
|
s(()=>{_()},[_])
|
|
@@ -234,7 +235,7 @@ return/ipad|tablet/.test(r)?"tablet":/mobile|iphone|android/.test(r)?"mobile":"d
|
|
|
234
235
|
return{deviceType:me(e),platform:"web",userAgent:e}}const be=["utm_source","utm_medium","utm_campaign"]
|
|
235
236
|
function ve(e){try{const r=new URL(e??("undefined"!=typeof window?window.location.href:"")),n={}
|
|
236
237
|
for(const e of be){const a=r.searchParams.get(e)
|
|
237
|
-
a&&(n[e]=a.slice(0,256))}return n}catch{return{}}}function _e(e){return Boolean(e.utm_source||e.utm_medium||e.utm_campaign)}const ge=({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"})]}),qe=({apiKey:l,apiBaseUrl:d="https://api.quantaroute.com",onComplete:u,onError:h,defaultLat:p,defaultLng:m,theme:f="light",className:y="",style:b,mapHeight:v="380px",title:_="Add Delivery Address",indiaBoundaryUrl:g,enableSearch:q=!0,enablePhoneAuth:w=!1,merchantId:N="",supabaseFunctionBaseUrl:k="",brandColor:C,logoUrl:x,headerBanner:E,onCheckoutEvent:S,enableCod:L=!1,codCartTotalPaise:P,codSessionToken:T="",enableEmailAuth:B=!1,variant:D,utmParams:M,enablePayment
|
|
238
|
+
a&&(n[e]=a.slice(0,256))}return n}catch{return{}}}function _e(e){return Boolean(e.utm_source||e.utm_medium||e.utm_campaign)}const ge=({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"})]}),qe=({apiKey:l,apiBaseUrl:d="https://api.quantaroute.com",onComplete:u,onError:h,defaultLat:p,defaultLng:m,theme:f="light",className:y="",style:b,mapHeight:v="380px",title:_="Add Delivery Address",indiaBoundaryUrl:g,enableSearch:q=!0,enablePhoneAuth:w=!1,merchantId:N="",supabaseFunctionBaseUrl:k="",brandColor:C,logoUrl:x,headerBanner:E,onCheckoutEvent:S,enableCod:L=!1,codCartTotalPaise:P,codSessionToken:T="",enableEmailAuth:B=!1,variant:D,utmParams:M,enablePayment:O=!1,paymentAmountPaise:U,onPaymentComplete:F,enablePrepaidNudge:j=!1,prepaidNudgeCopy:W,prepaidNudgeCtaUrl:J})=>{const K=w?"phone":B?"email":"none",G="phone"===K?"phone":"email"===K?"email":"map",Z=Boolean(O&&U&&k),[Y,X]=t(G),[re,ne]=t(null),[ae,te]=t(null),[ie,de]=t(null),[he,me]=t(""),[fe,be]=t(!1),[_e,qe]=t(!1),[we,Ne]=t(null),[ke,Ce]=t(null),xe=o(Y),Ee=c(()=>M??ve(),[M]),Se=c(()=>ye(),[]),Le=c(()=>({utm_source:Ee.utm_source,utm_medium:Ee.utm_medium,utm_campaign:Ee.utm_campaign,device_type:Se.deviceType,platform:Se.platform,user_agent:Se.userAgent,experiment_variant:D}),[Ee,Se,D]),Ie={functionBaseUrl:k,merchantId:N},Pe=(null==ie?void 0:ie.sessionToken)||T
|
|
238
239
|
s(()=>{xe.current=Y},[Y])
|
|
239
240
|
const Te=i(e=>{const r={...e,sessionId:e.sessionId??(null==ie?void 0:ie.sessionId),buyerId:e.buyerId??(null==ie?void 0:ie.buyerId),authChannel:e.authChannel??("phone"===K?"phone":"email"===K?"email":"none"),deviceType:e.deviceType??Se.deviceType,platform:e.platform??Se.platform,userAgent:e.userAgent??Se.userAgent,experimentVariant:e.experimentVariant??D,timestamp:(new Date).toISOString()}
|
|
240
241
|
if(S)try{S(r)}catch{}N&&k&&z(Ie,{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==ie?void 0:ie.sessionToken).catch(()=>{})},[ie,K,Se,D,S,N,k,Ie])
|
|
@@ -245,15 +246,15 @@ const Ae=c(()=>function(e,r){const n=null==r?void 0:r.trim()
|
|
|
245
246
|
if(!n)return e
|
|
246
247
|
const a={"--qr-primary":n,"--qr-primary-dark":n,"--qr-border-focus":n,"--qr-primary-light":`color-mix(in srgb, ${n} 18%, white)`}
|
|
247
248
|
return e?{...e,...a}:a}(b,C),[b,C]),Be=()=>{Te({type:"auth_skipped",step:"map"}),X("map")},De=async e=>{if(te(e),Te({type:"address_completed",step:Z?"payment":"done",digipin:e.digipin,buyerId:null==ie?void 0:ie.buyerId}),null==ie?void 0:ie.sessionToken){R(Ie,ie.sessionToken,{pincode:e.pincode,digipin:e.digipin,state:e.state,district:e.district,locality:e.locality}).catch(()=>{})
|
|
248
|
-
try{await
|
|
249
|
+
try{await $(Ie,ie.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",is_default:!0})}catch{}}Z&&Pe?X("payment"):(X("done"),u(e))}
|
|
249
250
|
s(()=>{const e={phone:"phone_step_viewed",email:"email_step_viewed",saved:"saved_addresses_viewed",map:"map_step_viewed",form:"form_step_viewed",payment:"payment_step_viewed"}[Y]
|
|
250
251
|
e&&Te({type:e,step:Y,buyerId:null==ie?void 0:ie.buyerId})},[Y]),s(()=>{B&&"email"===K&&(N&&k||null==h||h(new Error("enableEmailAuth requires merchantId and supabaseFunctionBaseUrl on CheckoutWidget.")))},[B,K,N,k,h])
|
|
251
252
|
const Me=function(e,r,n){if("none"===r){if(n){const r=["map","form","payment","done"].indexOf(e)
|
|
252
253
|
return-1===r?0:r}return"map"===e?0:"form"===e?1:2}const a=("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(e)
|
|
253
|
-
return-1===a?0:a}(Y,K,Z)
|
|
254
|
-
return e("div",{className:`qr-checkout qr-checkout--${f} ${y}`,style:Ae,"data-testid":"quantaroute-checkout",children:["done"!==Y&&e(n,{children:[e("div",{className:"qr-header",children:[e("div",{className:"qr-header__brand",children:[x?r("img",{src:x,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:_})]}),(()=>{const n=Array.from({length
|
|
255
|
-
return r("div",{className:"qr-progress",role:"progressbar","aria-valuenow":Me+1,"aria-valuemin":1,"aria-valuemax"
|
|
256
|
-
const r={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(", ")}
|
|
254
|
+
return-1===a?0:a}(Y,K,Z),Oe=function(e,r){return"none"===e?r?3:2:r?6:5}(K,Z)
|
|
255
|
+
return e("div",{className:`qr-checkout qr-checkout--${f} ${y}`,style:Ae,"data-testid":"quantaroute-checkout",children:["done"!==Y&&e(n,{children:[e("div",{className:"qr-header",children:[e("div",{className:"qr-header__brand",children:[x?r("img",{src:x,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:_})]}),(()=>{const n=Array.from({length:Oe+1},(e,r)=>r)
|
|
256
|
+
return r("div",{className:"qr-progress",role:"progressbar","aria-valuenow":Me+1,"aria-valuemin":1,"aria-valuemax":Oe+1,"aria-label":`Step ${Me+1} of ${Oe+1}`,children:n.map(n=>e(a.Fragment,{children:[r("div",{className:"qr-progress__dot"+(Me>=n?" qr-progress__dot--active":"")}),n<Oe&&r("div",{className:"qr-progress__line"+(Me>n?" qr-progress__line--active":"")})]},n))})})()]}),E?r("div",{className:"qr-header-banner",role:"region","aria-label":"Merchant message",children:E}):null,we?e("div",{className:"qr-offer-banner",role:"region","aria-label":"Special offer",children:[we.banner_copy,we.banner_cta_url?e(n,{children:[" ",r("a",{href:we.banner_cta_url,target:"_blank",rel:"noopener noreferrer",children:"Learn more"})]}):null]}):null]}),"email"===Y&&B&&r(ue,{onOtpSent:(e,r)=>{me(e),be(Boolean(null==r?void 0:r.reused)),Te({type:"email_otp_sent",step:"email-otp",mobile:e}),X("email-otp")},onSkip:Be,functionBaseUrl:k,merchantId:N}),"email-otp"===Y&&B&&he&&r(pe,{email:he,codeReused:fe,onVerified:(e,r,n)=>{de({mobile:he,sessionToken:e,sessionId:n??"",buyerId:r}),Te({type:"email_verified",step:"saved",buyerId:r,sessionId:n}),X("saved")},onBack:()=>X("email"),functionBaseUrl:k,merchantId:N,sessionContext:Le}),"phone"===Y&&w&&r(Q,{onOtpSent:e=>{de(r=>({mobile:e,sessionToken:"",sessionId:"",buyerId:(null==r?void 0:r.buyerId)??""})),Te({type:"otp_sent",step:"otp",mobile:e}),X("otp")},onSkip:Be,functionBaseUrl:k,merchantId:N}),"otp"===Y&&ie&&r(ee,{mobile:ie.mobile,onVerified:(e,r,n)=>{de({mobile:(null==ie?void 0:ie.mobile)??"",sessionToken:e,sessionId:n??"",buyerId:r}),Te({type:"phone_verified",step:"saved",buyerId:r,sessionId:n}),X("saved")},onBack:()=>X("phone"),functionBaseUrl:k,merchantId:N,sessionContext:Le}),"saved"===Y&&(null==ie?void 0:ie.sessionToken)&&r(oe,{sessionToken:ie.sessionToken,functionBaseUrl:k,merchantId:N,onSelectAddress:e=>{Te({type:"saved_address_selected",step:Z?"payment":"done",buyerId:null==ie?void 0:ie.buyerId,digipin:e.digipin}),(null==ie?void 0:ie.sessionToken)&&R(Ie,ie.sessionToken,{pincode:e.pincode,digipin:e.digipin,state:e.state,district:e.district,locality:e.locality}).catch(()=>{})
|
|
257
|
+
const r={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"}
|
|
257
258
|
De(r)},onAddNew:()=>X("map")}),"map"===Y&&r(I,{onLocationConfirm:(e,r,n)=>{ne({lat:e,lng:r,digipin:n}),Te({type:"location_confirmed",step:"form",digipin:n,buyerId:null==ie?void 0:ie.buyerId}),X("form")},defaultLat:p,defaultLng:m,mapHeight:v,theme:f,indiaBoundaryUrl:g,enableSearch:q,apiKey:l,apiBaseUrl:d,brandColor:C}),"form"===Y&&re&&r(A,{digipin:re.digipin,lat:re.lat,lng:re.lng,apiKey:l,apiBaseUrl:d,onAddressComplete:async e=>{await De(e)},onBack:()=>{"form"===Y?X("map"):"map"===Y&&(null==ie?void 0:ie.sessionToken)?X("saved"):"email-otp"===Y&&X("email")},onError:h,theme:f}),"payment"===Y&&Z&&Pe&&U&&r(ce,{checkoutConfig:Ie,sessionToken:Pe,sessionId:null==ie?void 0:ie.sessionId,amountPaise:U,enableCod:L,codAllowed:_e,theme:f,onComplete:e=>{Ce(e),Te({type:"payment_method_selected",step:"done",paymentMethod:e}),X("done"),ae&&u(ae),null==F||F({paymentMethod:e,sessionId:null==ie?void 0:ie.sessionId})},onBack:()=>X("form"),onEvent:(e,r)=>Te({type:e,step:"payment",paymentMethod:r,buyerId:null==ie?void 0:ie.buyerId})}),"done"===Y&&ae&&e(n,{children:[r(ge,{address:ae,onEditAddress:()=>{Te({type:"widget_reset",step:G}),X(G),ne(null),te(null)}}),ke?e("p",{className:"qr-cod-banner__text qr-cod-banner__text--ok",style:{textAlign:"center",margin:"8px 16px"},children:["Paid via ","cod"===ke?"Cash on Delivery":"online payment"]}):null,L&&N&&k&&Pe?e(n,{children:[r(le,{checkoutConfig:Ie,sessionToken:Pe,pincode:ae.pincode,cartTotalPaise:P??U,theme:f,onCodAllowedChange:qe}),j&&_e?r(se,{copy:W??"Save more when you pay online — faster delivery & exclusive offers.",ctaUrl:J,theme:f}):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:"🇮🇳"})]})]})}
|
|
258
259
|
function we(e,r){return c(()=>{if(!b(e,r))return null
|
|
259
|
-
try{return m(e,r)}catch{return null}},[e,r])}export{A as AddressForm,qe as CheckoutWidget,le as CodAvailabilityBanner,p as DIGIPIN_BOUNDS,pe as EmailOtpStep,ue as EmailStep,I as MapPinSelector,ee as OtpStep,ce as PaymentStep,Q as PhoneStep,se as PrepaidNudge,oe as SavedAddressStep,C as autocompleteAddress,ve as captureUtmFromUrl,J as checkCodEligibility
|
|
260
|
+
try{return m(e,r)}catch{return null}},[e,r])}export{A as AddressForm,qe as CheckoutWidget,le as CodAvailabilityBanner,p as DIGIPIN_BOUNDS,pe as EmailOtpStep,ue as EmailStep,I as MapPinSelector,ee as OtpStep,ce as PaymentStep,Q as PhoneStep,se as PrepaidNudge,oe as SavedAddressStep,C as autocompleteAddress,ve as captureUtmFromUrl,J as checkCodEligibility,$ as createAddress,K as createPaymentOrder,qe as default,U as deleteAddress,me as detectDeviceType,fe as detectPlatform,Y as fetchPrepaidNudgeConfig,H as fetchSessionOffer,m as getDigiPin,f as getLatLngFromDigiPin,ye as getWebDeviceContext,_e as hasUtmParams,y as isValidDigiPin,b as isWithinIndia,O as listAddresses,z as logFunnelEvent,k as looksLikeDigiPin,q as lookupLocation,R as notifyAddressCompleted,V as notifySessionAbandoned,N as pincodeHasDeliveryOffice,Z as recordCodPayment,x as reverseGeocode,j as sendEmailOtp,B as sendOtp,F as setDefaultAddress,we as useDigiPin,E as useGeolocation,w as validatePincode,W as verifyEmailOtp,D as verifyOtp,G as verifyPayment}
|