@quantaroute/checkout 1.7.2 → 1.7.4
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 +22 -0
- package/README.md +4 -1
- package/dist/lib/index.d.ts +67 -10
- package/dist/lib/quantaroute-checkout.es.js +159 -139
- package/dist/lib/quantaroute-checkout.umd.js +151 -131
- package/dist/style.css +1 -1
- package/package.json +7 -3
- package/src/components/AddressForm.native.tsx +3 -3
- package/src/components/AddressForm.tsx +3 -3
- package/src/components/CheckoutWidget.tsx +51 -14
- package/src/components/MapPinSelector.native.tsx +14 -9
- package/src/components/MapPinSelector.tsx +43 -15
- package/src/components/PaymentStep.tsx +36 -8
- package/src/core/map-runtime.ts +98 -3
- package/src/core/types.ts +33 -8
- package/src/index.ts +11 -0
- package/src/styles/checkout.css +19 -0
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
notifyAddressCompleted,
|
|
11
11
|
logFunnelEvent,
|
|
12
12
|
notifySessionAbandoned,
|
|
13
|
+
checkCodEligibility,
|
|
13
14
|
fetchSessionOffer,
|
|
14
15
|
scoreAddressRisk,
|
|
15
16
|
selectAddress,
|
|
@@ -212,7 +213,9 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
212
213
|
indiaBoundaryUrl,
|
|
213
214
|
enableSearch = true,
|
|
214
215
|
mapStyle,
|
|
216
|
+
mapTheme,
|
|
215
217
|
embedMode,
|
|
218
|
+
mapsKey,
|
|
216
219
|
enablePhoneAuth = false,
|
|
217
220
|
merchantId = '',
|
|
218
221
|
supabaseFunctionBaseUrl = '',
|
|
@@ -277,10 +280,10 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
277
280
|
[utmParams, deviceCtx, variant]
|
|
278
281
|
);
|
|
279
282
|
|
|
280
|
-
const checkoutConfig =
|
|
281
|
-
functionBaseUrl: supabaseFunctionBaseUrl,
|
|
282
|
-
merchantId
|
|
283
|
-
|
|
283
|
+
const checkoutConfig = useMemo(
|
|
284
|
+
() => ({ functionBaseUrl: supabaseFunctionBaseUrl, merchantId }),
|
|
285
|
+
[supabaseFunctionBaseUrl, merchantId]
|
|
286
|
+
);
|
|
284
287
|
|
|
285
288
|
const codSession = auth?.sessionToken || codSessionToken;
|
|
286
289
|
|
|
@@ -369,6 +372,32 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
369
372
|
.catch(() => setSessionOffer(null));
|
|
370
373
|
}, [auth?.sessionToken, merchantId, supabaseFunctionBaseUrl, checkoutConfig]);
|
|
371
374
|
|
|
375
|
+
// Resolve COD eligibility as soon as an address is chosen, so the payment
|
|
376
|
+
// step (which comes before `done`) already knows whether to offer COD.
|
|
377
|
+
const completedPincode = completedAddress?.pincode;
|
|
378
|
+
const codCheckTotalPaise = codCartTotalPaise ?? paymentAmountPaise;
|
|
379
|
+
useEffect(() => {
|
|
380
|
+
setCodAllowed(false);
|
|
381
|
+
if (!withPayment || !enableCod || !merchantId || !codSession || !completedPincode) return;
|
|
382
|
+
let cancelled = false;
|
|
383
|
+
checkCodEligibility(checkoutConfig, codSession, completedPincode, codCheckTotalPaise)
|
|
384
|
+
.then((r) => {
|
|
385
|
+
if (!cancelled) setCodAllowed(r.cod_allowed);
|
|
386
|
+
})
|
|
387
|
+
.catch(() => {/* stay false: fail closed */});
|
|
388
|
+
return () => {
|
|
389
|
+
cancelled = true;
|
|
390
|
+
};
|
|
391
|
+
}, [
|
|
392
|
+
withPayment,
|
|
393
|
+
enableCod,
|
|
394
|
+
merchantId,
|
|
395
|
+
codSession,
|
|
396
|
+
completedPincode,
|
|
397
|
+
codCheckTotalPaise,
|
|
398
|
+
checkoutConfig,
|
|
399
|
+
]);
|
|
400
|
+
|
|
372
401
|
const rootStyle = useMemo(
|
|
373
402
|
() => mergeBrandRootStyle(style as CSSProperties | undefined, brandColor),
|
|
374
403
|
[style, brandColor]
|
|
@@ -438,14 +467,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
438
467
|
digipin: saved.digipin,
|
|
439
468
|
});
|
|
440
469
|
|
|
441
|
-
|
|
442
|
-
pincode: saved.pincode,
|
|
443
|
-
digipin: saved.digipin,
|
|
444
|
-
state: saved.state,
|
|
445
|
-
district: saved.district,
|
|
446
|
-
locality: saved.locality,
|
|
447
|
-
}).catch(() => {/* silent */});
|
|
448
|
-
|
|
470
|
+
// finishAddress() sends the address_completed notification.
|
|
449
471
|
await finishAddress(savedAddressToComplete(saved), { skipCreate: true, paymentBackStep: 'saved' });
|
|
450
472
|
};
|
|
451
473
|
|
|
@@ -673,12 +695,23 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
673
695
|
}, [registerController, auth?.sessionToken, verifyAddress, paymentBackStep]);
|
|
674
696
|
|
|
675
697
|
const handleEditAddress = () => {
|
|
676
|
-
|
|
677
|
-
|
|
698
|
+
// A recorded payment completes the server session, so its token is dead:
|
|
699
|
+
// drop it and re-authenticate. Otherwise the session is still live, so a
|
|
700
|
+
// verified buyer goes back to their saved addresses instead of the OTP gate.
|
|
701
|
+
const sessionCompleted = paymentMethod !== null;
|
|
702
|
+
const nextStep: Step =
|
|
703
|
+
!sessionCompleted && auth?.sessionToken ? 'saved' : initialStep;
|
|
704
|
+
emit({ type: 'widget_reset', step: nextStep });
|
|
705
|
+
if (sessionCompleted) {
|
|
706
|
+
setAuth(null);
|
|
707
|
+
setSessionOffer(null);
|
|
708
|
+
}
|
|
709
|
+
setStep(nextStep);
|
|
678
710
|
setConfirmedLocation(null);
|
|
679
711
|
setCompletedAddress(null);
|
|
680
712
|
setAddressRisk(null);
|
|
681
713
|
setVerifyAddress(null);
|
|
714
|
+
setPaymentMethod(null);
|
|
682
715
|
};
|
|
683
716
|
|
|
684
717
|
// ── Emit "step viewed" event on every step change ────────────────────────
|
|
@@ -945,7 +978,9 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
945
978
|
apiBaseUrl={apiBaseUrl}
|
|
946
979
|
brandColor={brandColor}
|
|
947
980
|
mapStyle={mapStyle}
|
|
981
|
+
mapTheme={mapTheme}
|
|
948
982
|
embedMode={embedMode}
|
|
983
|
+
mapsKey={mapsKey}
|
|
949
984
|
/>
|
|
950
985
|
</>
|
|
951
986
|
)}
|
|
@@ -964,7 +999,9 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
964
999
|
apiBaseUrl={apiBaseUrl}
|
|
965
1000
|
brandColor={brandColor}
|
|
966
1001
|
mapStyle={mapStyle}
|
|
1002
|
+
mapTheme={mapTheme}
|
|
967
1003
|
embedMode={embedMode}
|
|
1004
|
+
mapsKey={mapsKey}
|
|
968
1005
|
/>
|
|
969
1006
|
)}
|
|
970
1007
|
|
|
@@ -16,6 +16,7 @@ import { getDigiPin, getLatLngFromDigiPin, formatDigiPin, isWithinIndia } from '
|
|
|
16
16
|
import { autocompleteAddress, looksLikeDigiPin, couldBeDigiPinInput } from '../core/api';
|
|
17
17
|
import type { AutocompleteSuggestion } from '../core/api';
|
|
18
18
|
import type { MapPinSelectorProps } from '../core/types';
|
|
19
|
+
import { QUANTAROUTE_MAP_STYLE_URL, withMapsKey } from '../core/map-runtime';
|
|
19
20
|
import { styles, COLORS } from '../styles/checkout.native';
|
|
20
21
|
|
|
21
22
|
// ─── Constants ────────────────────────────────────────────────────────────────
|
|
@@ -24,13 +25,6 @@ const INDIA_CENTER = { latitude: 20.5937, longitude: 78.9629 };
|
|
|
24
25
|
const OVERVIEW_ZOOM = 5;
|
|
25
26
|
const STREET_ZOOM = 16;
|
|
26
27
|
|
|
27
|
-
/**
|
|
28
|
-
* Carto Positron vector basemap — same source as the web version.
|
|
29
|
-
* Free, no API key required. Attribution required (shown by OSMView natively).
|
|
30
|
-
*/
|
|
31
|
-
const CARTO_STYLE_URL =
|
|
32
|
-
'https://basemaps.cartocdn.com/gl/positron-gl-style/style.json';
|
|
33
|
-
|
|
34
28
|
const DEFAULT_BRAND = '#0ea5e9';
|
|
35
29
|
|
|
36
30
|
/**
|
|
@@ -78,6 +72,7 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
|
|
|
78
72
|
apiKey,
|
|
79
73
|
apiBaseUrl,
|
|
80
74
|
brandColor = DEFAULT_BRAND,
|
|
75
|
+
mapsKey,
|
|
81
76
|
}) => {
|
|
82
77
|
const mapRef = useRef<OSMViewRef>(null);
|
|
83
78
|
|
|
@@ -98,6 +93,8 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
|
|
|
98
93
|
const [searchLoading, setSearchLoading] = useState(false);
|
|
99
94
|
const [searchError, setSearchError] = useState<string | null>(null);
|
|
100
95
|
const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
96
|
+
/** Bumped on every input change so a slow, superseded autocomplete response is ignored. */
|
|
97
|
+
const searchSeqRef = useRef(0);
|
|
101
98
|
|
|
102
99
|
const isDark = theme === 'dark';
|
|
103
100
|
const accentColor = brandColor ?? DEFAULT_BRAND;
|
|
@@ -126,6 +123,7 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
|
|
|
126
123
|
setSearchQuery(value);
|
|
127
124
|
setSearchError(null);
|
|
128
125
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
126
|
+
const seq = ++searchSeqRef.current;
|
|
129
127
|
|
|
130
128
|
const trimmed = value.trim();
|
|
131
129
|
|
|
@@ -138,6 +136,7 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
|
|
|
138
136
|
// DigiPin — offline, instant
|
|
139
137
|
// Keep the text visible in the input; just close the keyboard and dropdown.
|
|
140
138
|
if (looksLikeDigiPin(trimmed)) {
|
|
139
|
+
setSearchLoading(false);
|
|
141
140
|
try {
|
|
142
141
|
const coords = getLatLngFromDigiPin(trimmed);
|
|
143
142
|
flyToCoord(parseFloat(coords.latitude), parseFloat(coords.longitude));
|
|
@@ -159,6 +158,7 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
|
|
|
159
158
|
|
|
160
159
|
if (trimmed.length < 3) {
|
|
161
160
|
setSuggestions([]);
|
|
161
|
+
setSearchLoading(false);
|
|
162
162
|
return;
|
|
163
163
|
}
|
|
164
164
|
|
|
@@ -170,18 +170,23 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
|
|
|
170
170
|
trimmed, apiKey ?? '', apiBaseUrl, 5,
|
|
171
171
|
coord.latitude, coord.longitude,
|
|
172
172
|
);
|
|
173
|
+
if (seq !== searchSeqRef.current) return;
|
|
173
174
|
setSuggestions(results);
|
|
174
175
|
} catch (err) {
|
|
176
|
+
if (seq !== searchSeqRef.current) return;
|
|
175
177
|
setSearchError(err instanceof Error ? err.message : 'Search failed');
|
|
176
178
|
setSuggestions([]);
|
|
177
179
|
} finally {
|
|
178
|
-
setSearchLoading(false);
|
|
180
|
+
if (seq === searchSeqRef.current) setSearchLoading(false);
|
|
179
181
|
}
|
|
180
182
|
}, 400);
|
|
181
183
|
}, [apiKey, apiBaseUrl, flyToCoord]);
|
|
182
184
|
|
|
183
185
|
const handleSuggestionSelect = useCallback((s: AutocompleteSuggestion) => {
|
|
184
186
|
flyToCoord(s.coordinates.latitude, s.coordinates.longitude);
|
|
187
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
188
|
+
searchSeqRef.current += 1;
|
|
189
|
+
setSearchLoading(false);
|
|
185
190
|
setSearchQuery('');
|
|
186
191
|
setSuggestions([]);
|
|
187
192
|
Keyboard.dismiss();
|
|
@@ -318,7 +323,7 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
|
|
|
318
323
|
style={{ flex: 1 }}
|
|
319
324
|
initialCenter={{ latitude: initLat, longitude: initLng }}
|
|
320
325
|
initialZoom={hasDefault ? STREET_ZOOM : OVERVIEW_ZOOM}
|
|
321
|
-
styleUrl={
|
|
326
|
+
styleUrl={withMapsKey(QUANTAROUTE_MAP_STYLE_URL, mapsKey)}
|
|
322
327
|
markers={pinMarkers}
|
|
323
328
|
showUserLocation={false}
|
|
324
329
|
scrollEnabled
|
|
@@ -8,8 +8,11 @@ import type { AutocompleteSuggestion } from '../core/api';
|
|
|
8
8
|
import { useGeolocation } from '../hooks/useGeolocation';
|
|
9
9
|
import type { MapPinSelectorProps } from '../core/types';
|
|
10
10
|
import {
|
|
11
|
-
|
|
11
|
+
addQuantaRouteWatermark,
|
|
12
|
+
mapsTransformRequest,
|
|
13
|
+
resolveQuantaRouteMapStyle,
|
|
12
14
|
waitForExternalMapRuntime,
|
|
15
|
+
withMapsKey,
|
|
13
16
|
type MapRuntime,
|
|
14
17
|
} from '../core/map-runtime';
|
|
15
18
|
|
|
@@ -100,12 +103,11 @@ function createPinElement(brandColor: string = DEFAULT_BRAND): HTMLDivElement {
|
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
function collapseCompactAttribution(container: HTMLElement | null): void {
|
|
103
|
-
const attribEl = container?.querySelector(
|
|
104
|
-
'.maplibregl-ctrl-attrib.maplibregl-compact'
|
|
105
|
-
);
|
|
106
|
+
const attribEl = container?.querySelector('.maplibregl-ctrl-attrib');
|
|
106
107
|
if (attribEl instanceof HTMLElement) {
|
|
108
|
+
attribEl.classList.add('maplibregl-compact');
|
|
107
109
|
attribEl.classList.remove('maplibregl-compact-show');
|
|
108
|
-
attribEl.
|
|
110
|
+
attribEl.removeAttribute('open');
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
113
|
|
|
@@ -120,6 +122,7 @@ function initMapWithRuntime(
|
|
|
120
122
|
initZoom: number;
|
|
121
123
|
brandColor: string;
|
|
122
124
|
indiaBoundaryUrl?: string;
|
|
125
|
+
mapsKey?: string;
|
|
123
126
|
refreshDigipin: (la: number, lo: number) => void;
|
|
124
127
|
onReady: () => void;
|
|
125
128
|
onError: (message: string) => void;
|
|
@@ -132,6 +135,7 @@ function initMapWithRuntime(
|
|
|
132
135
|
initZoom,
|
|
133
136
|
brandColor,
|
|
134
137
|
indiaBoundaryUrl,
|
|
138
|
+
mapsKey,
|
|
135
139
|
refreshDigipin,
|
|
136
140
|
onReady,
|
|
137
141
|
onError,
|
|
@@ -145,25 +149,25 @@ function initMapWithRuntime(
|
|
|
145
149
|
|
|
146
150
|
const map = new runtime.Map({
|
|
147
151
|
container,
|
|
148
|
-
style: styleUrl,
|
|
152
|
+
style: withMapsKey(styleUrl, mapsKey),
|
|
153
|
+
transformRequest: mapsTransformRequest(mapsKey),
|
|
149
154
|
center: [initLng, initLat],
|
|
150
155
|
zoom: initZoom,
|
|
151
156
|
minZoom: MIN_ZOOM,
|
|
152
157
|
attributionControl: false,
|
|
158
|
+
maplibreLogo: false,
|
|
153
159
|
touchZoomRotate: true,
|
|
154
160
|
});
|
|
155
161
|
|
|
156
162
|
if (typeof runtime.AttributionControl === 'function') {
|
|
157
163
|
map.addControl(
|
|
158
|
-
new runtime.AttributionControl({
|
|
159
|
-
compact: true,
|
|
160
|
-
customAttribution:
|
|
161
|
-
'© <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>',
|
|
162
|
-
}),
|
|
164
|
+
new runtime.AttributionControl({ compact: true }),
|
|
163
165
|
'bottom-right'
|
|
164
166
|
);
|
|
165
167
|
}
|
|
166
168
|
|
|
169
|
+
addQuantaRouteWatermark(map);
|
|
170
|
+
|
|
167
171
|
if (typeof runtime.NavigationControl === 'function') {
|
|
168
172
|
map.addControl(
|
|
169
173
|
new runtime.NavigationControl({ showCompass: false }),
|
|
@@ -173,11 +177,17 @@ function initMapWithRuntime(
|
|
|
173
177
|
|
|
174
178
|
let marker: MapLibreMarker | null = null;
|
|
175
179
|
|
|
180
|
+
map.on('style.load', () => {
|
|
181
|
+
collapseCompactAttribution(container);
|
|
182
|
+
});
|
|
183
|
+
|
|
176
184
|
map.on('load', () => {
|
|
177
185
|
collapseCompactAttribution(container);
|
|
178
186
|
onReady();
|
|
179
187
|
|
|
180
188
|
boundaryPromise.then((geoJson) => {
|
|
189
|
+
// Our hosted style already draws the official outline; skip a second line.
|
|
190
|
+
if (styleUrl.includes('maps.quantaroute.com')) return;
|
|
181
191
|
if (!geoJson || !map.isStyleLoaded()) return;
|
|
182
192
|
try {
|
|
183
193
|
map.addSource('india-boundary', {
|
|
@@ -255,9 +265,12 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
|
|
|
255
265
|
apiKey,
|
|
256
266
|
apiBaseUrl,
|
|
257
267
|
brandColor = DEFAULT_BRAND,
|
|
258
|
-
mapStyle
|
|
268
|
+
mapStyle,
|
|
269
|
+
mapTheme,
|
|
259
270
|
embedMode = 'bundled',
|
|
271
|
+
mapsKey,
|
|
260
272
|
}) => {
|
|
273
|
+
const resolvedMapStyle = resolveQuantaRouteMapStyle(mapStyle, mapTheme);
|
|
261
274
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
262
275
|
const mapRef = useRef<MapLibreMap | null>(null);
|
|
263
276
|
const markerRef = useRef<MapLibreMarker | null>(null);
|
|
@@ -282,6 +295,8 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
|
|
|
282
295
|
const [searchError, setSearchError] = useState<string | null>(null);
|
|
283
296
|
const [dropdownOpen, setDropdownOpen] = useState(false);
|
|
284
297
|
const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
298
|
+
/** Bumped on every input change so a slow, superseded autocomplete response is ignored. */
|
|
299
|
+
const searchSeqRef = useRef(0);
|
|
285
300
|
const searchInputRef = useRef<HTMLInputElement>(null);
|
|
286
301
|
const listboxId = useId();
|
|
287
302
|
|
|
@@ -307,6 +322,7 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
|
|
|
307
322
|
setSearchError(null);
|
|
308
323
|
|
|
309
324
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
325
|
+
const seq = ++searchSeqRef.current;
|
|
310
326
|
|
|
311
327
|
const trimmed = value.trim();
|
|
312
328
|
|
|
@@ -318,6 +334,7 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
|
|
|
318
334
|
}
|
|
319
335
|
|
|
320
336
|
if (looksLikeDigiPin(trimmed)) {
|
|
337
|
+
setSearchLoading(false);
|
|
321
338
|
try {
|
|
322
339
|
const coords = getLatLngFromDigiPin(trimmed);
|
|
323
340
|
const la = parseFloat(coords.latitude);
|
|
@@ -342,6 +359,7 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
|
|
|
342
359
|
if (trimmed.length < 3) {
|
|
343
360
|
setSuggestions([]);
|
|
344
361
|
setDropdownOpen(false);
|
|
362
|
+
setSearchLoading(false);
|
|
345
363
|
return;
|
|
346
364
|
}
|
|
347
365
|
|
|
@@ -350,20 +368,25 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
|
|
|
350
368
|
try {
|
|
351
369
|
const key = apiKey ?? '';
|
|
352
370
|
const results = await autocompleteAddress(trimmed, key, apiBaseUrl, 5, lat, lng);
|
|
371
|
+
if (seq !== searchSeqRef.current) return;
|
|
353
372
|
setSuggestions(results);
|
|
354
373
|
setDropdownOpen(results.length > 0);
|
|
355
374
|
} catch (err) {
|
|
375
|
+
if (seq !== searchSeqRef.current) return;
|
|
356
376
|
setSearchError(err instanceof Error ? err.message : 'Search failed');
|
|
357
377
|
setSuggestions([]);
|
|
358
378
|
setDropdownOpen(false);
|
|
359
379
|
} finally {
|
|
360
|
-
setSearchLoading(false);
|
|
380
|
+
if (seq === searchSeqRef.current) setSearchLoading(false);
|
|
361
381
|
}
|
|
362
382
|
}, 400);
|
|
363
383
|
}, [apiKey, apiBaseUrl, flyToCoord, lat, lng]);
|
|
364
384
|
|
|
365
385
|
const handleSuggestionSelect = useCallback((s: AutocompleteSuggestion) => {
|
|
366
386
|
flyToCoord(s.coordinates.latitude, s.coordinates.longitude);
|
|
387
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
388
|
+
searchSeqRef.current += 1;
|
|
389
|
+
setSearchLoading(false);
|
|
367
390
|
setSearchQuery('');
|
|
368
391
|
setSuggestions([]);
|
|
369
392
|
setDropdownOpen(false);
|
|
@@ -372,6 +395,9 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
|
|
|
372
395
|
|
|
373
396
|
const handleSearchKeyDown = useCallback((e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
374
397
|
if (e.key === 'Escape') {
|
|
398
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
399
|
+
searchSeqRef.current += 1;
|
|
400
|
+
setSearchLoading(false);
|
|
375
401
|
setSuggestions([]);
|
|
376
402
|
setDropdownOpen(false);
|
|
377
403
|
setSearchQuery('');
|
|
@@ -394,12 +420,13 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
|
|
|
394
420
|
|
|
395
421
|
try {
|
|
396
422
|
const { map, cleanup } = initMapWithRuntime(runtime, container, markerRef, {
|
|
397
|
-
styleUrl:
|
|
423
|
+
styleUrl: resolvedMapStyle,
|
|
398
424
|
initLat,
|
|
399
425
|
initLng,
|
|
400
426
|
initZoom,
|
|
401
427
|
brandColor,
|
|
402
428
|
indiaBoundaryUrl,
|
|
429
|
+
mapsKey,
|
|
403
430
|
refreshDigipin,
|
|
404
431
|
onReady: () => {
|
|
405
432
|
if (cancelled) return;
|
|
@@ -449,7 +476,8 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
|
|
|
449
476
|
indiaBoundaryUrl,
|
|
450
477
|
initLat,
|
|
451
478
|
initLng,
|
|
452
|
-
|
|
479
|
+
mapsKey,
|
|
480
|
+
resolvedMapStyle,
|
|
453
481
|
refreshDigipin,
|
|
454
482
|
]);
|
|
455
483
|
|
|
@@ -14,21 +14,49 @@ declare global {
|
|
|
14
14
|
|
|
15
15
|
const RAZORPAY_SCRIPT = 'https://checkout.razorpay.com/v1/checkout.js';
|
|
16
16
|
|
|
17
|
+
const RAZORPAY_LOAD_TIMEOUT_MS = 15_000;
|
|
18
|
+
let razorpayLoad: Promise<void> | null = null;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Load Razorpay Checkout once. Always settles: a failed or stalled tag is
|
|
22
|
+
* removed and the cached promise cleared, so the next attempt starts clean.
|
|
23
|
+
*/
|
|
17
24
|
function loadRazorpayScript(): Promise<void> {
|
|
18
25
|
if (window.Razorpay) return Promise.resolve();
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
26
|
+
if (razorpayLoad) return razorpayLoad;
|
|
27
|
+
|
|
28
|
+
razorpayLoad = new Promise<void>((resolve, reject) => {
|
|
29
|
+
// A tag we are not already tracking may have finished or failed before we
|
|
30
|
+
// could listen to it; without window.Razorpay it is useless, so replace it.
|
|
31
|
+
document.querySelector(`script[src="${RAZORPAY_SCRIPT}"]`)?.remove();
|
|
32
|
+
|
|
25
33
|
const script = document.createElement('script');
|
|
26
34
|
script.src = RAZORPAY_SCRIPT;
|
|
27
35
|
script.async = true;
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
|
|
37
|
+
const fail = (message: string) => {
|
|
38
|
+
window.clearTimeout(timer);
|
|
39
|
+
script.remove();
|
|
40
|
+
razorpayLoad = null;
|
|
41
|
+
reject(new Error(message));
|
|
42
|
+
};
|
|
43
|
+
const timer = window.setTimeout(
|
|
44
|
+
() => fail('Razorpay took too long to load'),
|
|
45
|
+
RAZORPAY_LOAD_TIMEOUT_MS
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
script.onload = () => {
|
|
49
|
+
window.clearTimeout(timer);
|
|
50
|
+
if (window.Razorpay) {
|
|
51
|
+
resolve();
|
|
52
|
+
} else {
|
|
53
|
+
fail('Razorpay unavailable');
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
script.onerror = () => fail('Failed to load Razorpay');
|
|
30
57
|
document.body.appendChild(script);
|
|
31
58
|
});
|
|
59
|
+
return razorpayLoad;
|
|
32
60
|
}
|
|
33
61
|
|
|
34
62
|
const PaymentStep: React.FC<PaymentStepProps> = ({
|
package/src/core/map-runtime.ts
CHANGED
|
@@ -33,11 +33,106 @@ export type { MapLibreMap, MapLibreMarker, MapMouseEvent };
|
|
|
33
33
|
*/
|
|
34
34
|
export type MapEmbedMode = 'bundled' | 'external';
|
|
35
35
|
|
|
36
|
-
/**
|
|
37
|
-
export const
|
|
36
|
+
/** QuantaRoute India basemap (Geofabrik PBF, Survey of India outline). */
|
|
37
|
+
export const QUANTAROUTE_MAP_STYLE_URL =
|
|
38
|
+
'https://maps.quantaroute.com/styles/quantaroute.json';
|
|
39
|
+
|
|
40
|
+
export const QUANTAROUTE_MAP_STYLE_LIGHT_URL =
|
|
41
|
+
'https://maps.quantaroute.com/styles/quantaroute-pro-light.json';
|
|
42
|
+
|
|
43
|
+
export const QUANTAROUTE_MAP_STYLE_DARK_URL =
|
|
44
|
+
'https://maps.quantaroute.com/styles/quantaroute-pro-dark.json';
|
|
45
|
+
|
|
46
|
+
export const QUANTAROUTE_MAP_STYLES = {
|
|
47
|
+
pro: QUANTAROUTE_MAP_STYLE_URL,
|
|
48
|
+
light: QUANTAROUTE_MAP_STYLE_LIGHT_URL,
|
|
49
|
+
dark: QUANTAROUTE_MAP_STYLE_DARK_URL,
|
|
50
|
+
} as const;
|
|
51
|
+
|
|
52
|
+
export type QuantaRouteMapTheme = keyof typeof QUANTAROUTE_MAP_STYLES;
|
|
53
|
+
|
|
54
|
+
export const QUANTAROUTE_MAP_STYLES_CATALOG_URL =
|
|
55
|
+
'https://maps.quantaroute.com/styles.json';
|
|
56
|
+
|
|
57
|
+
export function resolveQuantaRouteMapStyle(
|
|
58
|
+
mapStyle?: string,
|
|
59
|
+
mapTheme?: QuantaRouteMapTheme
|
|
60
|
+
): string {
|
|
61
|
+
if (mapStyle) return mapStyle;
|
|
62
|
+
if (mapTheme) return QUANTAROUTE_MAP_STYLES[mapTheme];
|
|
63
|
+
return QUANTAROUTE_MAP_STYLE_URL;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const MAPS_ORIGIN = 'https://maps.quantaroute.com';
|
|
67
|
+
|
|
68
|
+
/** Attach `?key=` for MapLibre requests to maps.quantaroute.com. No-op for other hosts or a missing key. */
|
|
69
|
+
export function withMapsKey(url: string, key?: string): string {
|
|
70
|
+
if (!key || !url.startsWith(MAPS_ORIGIN)) return url;
|
|
71
|
+
try {
|
|
72
|
+
const next = new URL(url);
|
|
73
|
+
next.searchParams.set('key', key);
|
|
74
|
+
return next.toString();
|
|
75
|
+
} catch {
|
|
76
|
+
return url;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function mapsTransformRequest(
|
|
81
|
+
key?: string
|
|
82
|
+
): ((url: string) => { url: string }) | undefined {
|
|
83
|
+
if (!key) return undefined;
|
|
84
|
+
return (url: string) =>
|
|
85
|
+
url.startsWith(MAPS_ORIGIN) ? { url: withMapsKey(url, key) } : { url };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Official India outline GeoJSON (Survey of India / Datameet). Same file as the style overlay. */
|
|
89
|
+
export const QUANTAROUTE_INDIA_BOUNDARY_URL =
|
|
90
|
+
'https://maps.quantaroute.com/geojson/india.geojson';
|
|
91
|
+
|
|
92
|
+
/** Bottom-left watermark; hide MapLibre’s logo so this owns that corner. */
|
|
93
|
+
export const QUANTAROUTE_WATERMARK_URL =
|
|
94
|
+
'https://maps.quantaroute.com/brand/quantaroute-mark.png';
|
|
95
|
+
|
|
96
|
+
export function addQuantaRouteWatermark(
|
|
97
|
+
map: MapLibreMap,
|
|
98
|
+
imageUrl: string = QUANTAROUTE_WATERMARK_URL
|
|
99
|
+
): void {
|
|
100
|
+
let container: HTMLElement | undefined;
|
|
101
|
+
map.addControl(
|
|
102
|
+
{
|
|
103
|
+
onAdd() {
|
|
104
|
+
const anchor = document.createElement('a');
|
|
105
|
+
anchor.className = 'maplibregl-ctrl qr-map-watermark';
|
|
106
|
+
anchor.href = 'https://quantaroute.com';
|
|
107
|
+
anchor.target = '_blank';
|
|
108
|
+
anchor.rel = 'noopener noreferrer';
|
|
109
|
+
anchor.title = 'QuantaRoute';
|
|
110
|
+
anchor.setAttribute('aria-label', 'QuantaRoute');
|
|
111
|
+
const img = document.createElement('img');
|
|
112
|
+
img.src = imageUrl;
|
|
113
|
+
img.alt = 'QuantaRoute';
|
|
114
|
+
img.width = 28;
|
|
115
|
+
img.height = 28;
|
|
116
|
+
anchor.appendChild(img);
|
|
117
|
+
container = anchor;
|
|
118
|
+
return anchor;
|
|
119
|
+
},
|
|
120
|
+
onRemove() {
|
|
121
|
+
container?.remove();
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
'bottom-left'
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Default basemap for web embeds (Atlas Pro). */
|
|
129
|
+
export const DEFAULT_MAP_STYLE_URL = QUANTAROUTE_MAP_STYLE_URL;
|
|
130
|
+
|
|
131
|
+
/** Carto Positron — fallback if maps.quantaroute.com is unavailable. */
|
|
132
|
+
export const CARTO_POSITRON_STYLE_URL =
|
|
38
133
|
'https://basemaps.cartocdn.com/gl/positron-gl-style/style.json';
|
|
39
134
|
|
|
40
|
-
/** OpenFreeMap Positron —
|
|
135
|
+
/** OpenFreeMap Positron — fallback used by some Shopify embeds historically. */
|
|
41
136
|
export const OPENFREEMAP_POSITRON_STYLE_URL =
|
|
42
137
|
'https://tiles.openfreemap.org/styles/positron';
|
|
43
138
|
|
package/src/core/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
|
-
import type { MapEmbedMode } from './map-runtime';
|
|
2
|
+
import type { MapEmbedMode, QuantaRouteMapTheme } from './map-runtime';
|
|
3
3
|
import type { UtmParams } from './utm';
|
|
4
4
|
import type {
|
|
5
5
|
AddressRiskScore,
|
|
@@ -198,7 +198,7 @@ export interface MapPinSelectorProps {
|
|
|
198
198
|
* When provided, a thin grey outline of India's border is drawn on the map
|
|
199
199
|
* to satisfy Indian government map policy requirements.
|
|
200
200
|
* The file is fetched in parallel with map initialisation — no visible delay.
|
|
201
|
-
* Example: indiaBoundaryUrl="/geojson/india.geojson"
|
|
201
|
+
* Example: indiaBoundaryUrl="https://maps.quantaroute.com/geojson/india.geojson"
|
|
202
202
|
*/
|
|
203
203
|
indiaBoundaryUrl?: string;
|
|
204
204
|
/**
|
|
@@ -218,15 +218,28 @@ export interface MapPinSelectorProps {
|
|
|
218
218
|
*/
|
|
219
219
|
brandColor?: string;
|
|
220
220
|
/**
|
|
221
|
-
* MapLibre style URL for the basemap. Defaults to
|
|
222
|
-
*
|
|
221
|
+
* MapLibre style URL for the basemap. Defaults to QuantaRoute India
|
|
222
|
+
* (`QUANTAROUTE_MAP_STYLE_URL`). `CARTO_POSITRON_STYLE_URL` and
|
|
223
|
+
* `OPENFREEMAP_POSITRON_STYLE_URL` remain available as fallbacks.
|
|
224
|
+
* Wins over `mapTheme`.
|
|
223
225
|
*/
|
|
224
226
|
mapStyle?: string;
|
|
227
|
+
/**
|
|
228
|
+
* Named QuantaRoute Atlas theme when `mapStyle` is omitted:
|
|
229
|
+
* `pro` (default), `light`, or `dark`.
|
|
230
|
+
*/
|
|
231
|
+
mapTheme?: QuantaRouteMapTheme;
|
|
225
232
|
/**
|
|
226
233
|
* How MapLibre GL JS is loaded on web. `bundled` imports the peer dependency;
|
|
227
234
|
* `external` waits for `window.maplibregl` (CDN script loaded by the host).
|
|
228
235
|
*/
|
|
229
236
|
embedMode?: MapEmbedMode;
|
|
237
|
+
/**
|
|
238
|
+
* Public `dp_` key with the maps scope. Required when the style is on
|
|
239
|
+
* maps.quantaroute.com and the page is not a first-party origin. MapLibre
|
|
240
|
+
* `transformRequest` attaches it to the style, sprite, font and tile URLs.
|
|
241
|
+
*/
|
|
242
|
+
mapsKey?: string;
|
|
230
243
|
}
|
|
231
244
|
|
|
232
245
|
/** Pre-fill manual fields when verifying an imported saved address. */
|
|
@@ -246,7 +259,8 @@ export interface AddressFormProps {
|
|
|
246
259
|
lng: number;
|
|
247
260
|
apiKey: string;
|
|
248
261
|
apiBaseUrl?: string;
|
|
249
|
-
|
|
262
|
+
/** May return a promise; the form stays in its submitting state until it settles. */
|
|
263
|
+
onAddressComplete: (address: CompleteAddress) => void | Promise<void>;
|
|
250
264
|
onBack: () => void;
|
|
251
265
|
onError?: (error: Error) => void;
|
|
252
266
|
theme?: 'light' | 'dark';
|
|
@@ -305,19 +319,30 @@ export interface CheckoutWidgetProps {
|
|
|
305
319
|
* URL to an India boundary GeoJSON file (FeatureCollection).
|
|
306
320
|
* When provided, a thin grey outline is drawn on the map for legal compliance.
|
|
307
321
|
* Host the file in your app's public folder and pass its path here.
|
|
308
|
-
* Example: indiaBoundaryUrl="/geojson/india.geojson"
|
|
322
|
+
* Example: indiaBoundaryUrl="https://maps.quantaroute.com/geojson/india.geojson"
|
|
309
323
|
*/
|
|
310
324
|
indiaBoundaryUrl?: string;
|
|
311
325
|
/**
|
|
312
|
-
* MapLibre style URL for the map step. Defaults to
|
|
313
|
-
*
|
|
326
|
+
* MapLibre style URL for the map step. Defaults to QuantaRoute India.
|
|
327
|
+
* `CARTO_POSITRON_STYLE_URL` / `OPENFREEMAP_POSITRON_STYLE_URL` remain fallbacks.
|
|
328
|
+
* Wins over `mapTheme`.
|
|
314
329
|
*/
|
|
315
330
|
mapStyle?: string;
|
|
331
|
+
/**
|
|
332
|
+
* Named QuantaRoute Atlas theme when `mapStyle` is omitted:
|
|
333
|
+
* `pro` (default), `light`, or `dark`.
|
|
334
|
+
*/
|
|
335
|
+
mapTheme?: QuantaRouteMapTheme;
|
|
316
336
|
/**
|
|
317
337
|
* How MapLibre GL JS is loaded on web. `external` waits for `window.maplibregl`
|
|
318
338
|
* when the host loads MapLibre from a CDN (e.g. Shopify theme extensions).
|
|
319
339
|
*/
|
|
320
340
|
embedMode?: MapEmbedMode;
|
|
341
|
+
/**
|
|
342
|
+
* Public `dp_` key with the maps scope. Passed through to the map step.
|
|
343
|
+
* Shopify and other third-party hosts must set this; first-party sites can omit it.
|
|
344
|
+
*/
|
|
345
|
+
mapsKey?: string;
|
|
321
346
|
/**
|
|
322
347
|
* Show the smart search bar on the map step (default: true).
|
|
323
348
|
* Supports address search (API) and DigiPin lookup (100% offline).
|