@quantaroute/checkout 1.4.4 → 1.5.0

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.
@@ -18,6 +18,8 @@ import {
18
18
  pincodeHasDeliveryOffice,
19
19
  type AddressComponents,
20
20
  } from '../core/api';
21
+ import { checkServiceability, type ServiceabilityResult } from '../core/checkout-api';
22
+ import { processLocalityLookup } from '../core/locality';
21
23
  import type {
22
24
  AddressFormProps,
23
25
  AddressLabel,
@@ -44,12 +46,14 @@ type FormState =
44
46
  status: 'ready';
45
47
  adminInfo: AdministrativeInfo;
46
48
  alternatives: LocationAlternative[];
49
+ localityOptions: string[];
47
50
  selectedLocality: string;
48
51
  selectedLabel: AddressLabel;
49
52
  labelText: string;
50
53
  fields: ManualFields;
51
54
  submitting: boolean;
52
55
  pincodeHasDelivery: boolean;
56
+ serviceabilityResult: ServiceabilityResult | null;
53
57
  };
54
58
 
55
59
  type FormAction =
@@ -60,6 +64,7 @@ type FormAction =
60
64
  alternatives: LocationAlternative[];
61
65
  addressComponents: AddressComponents;
62
66
  pincodeHasDelivery: boolean;
67
+ serviceabilityResult: ServiceabilityResult | null;
63
68
  }
64
69
  | { type: 'LOAD_ERROR'; message: string }
65
70
  | { type: 'SET_FIELD'; key: keyof ManualFields; value: string }
@@ -103,16 +108,19 @@ function reducer(state: FormState, action: FormAction): FormState {
103
108
  return { status: 'loading' };
104
109
  case 'LOAD_SUCCESS': {
105
110
  const preFilled = parseAddressComponents(action.addressComponents);
111
+ const processed = processLocalityLookup(action.adminInfo, action.alternatives || []);
106
112
  return {
107
113
  status: 'ready',
108
- adminInfo: action.adminInfo,
109
- alternatives: action.alternatives || [],
110
- selectedLocality: action.adminInfo.locality,
114
+ adminInfo: processed.adminInfo,
115
+ alternatives: processed.alternatives,
116
+ localityOptions: processed.localityOptions,
117
+ selectedLocality: processed.selectedLocality,
111
118
  selectedLabel: 'home',
112
119
  labelText: '',
113
120
  fields: { ...INITIAL_FIELDS, ...preFilled },
114
121
  submitting: false,
115
122
  pincodeHasDelivery: action.pincodeHasDelivery,
123
+ serviceabilityResult: action.serviceabilityResult,
116
124
  };
117
125
  }
118
126
  case 'LOAD_ERROR':
@@ -161,6 +169,12 @@ const AddressForm: React.FC<AddressFormProps> = ({
161
169
  onBack,
162
170
  onError,
163
171
  theme = 'light',
172
+ checkoutConfig,
173
+ serviceabilitySessionToken,
174
+ enableServiceabilityCheck = false,
175
+ showIndiaPostDeliveryWarning = false,
176
+ serviceabilityBlockCheckout,
177
+ onServiceabilityResult,
164
178
  }) => {
165
179
  const [state, dispatch] = useReducer(reducer, { status: 'loading' });
166
180
  const [showLocalityPicker, setShowLocalityPicker] = useState(false);
@@ -202,6 +216,26 @@ const AddressForm: React.FC<AddressFormProps> = ({
202
216
  }
203
217
 
204
218
  const hasDelivery = pincodeHasDeliveryOffice(pinValidation.offices);
219
+ let serviceabilityResult: ServiceabilityResult | null = null;
220
+
221
+ if (
222
+ enableServiceabilityCheck
223
+ && checkoutConfig?.functionBaseUrl
224
+ && checkoutConfig.merchantId
225
+ && serviceabilitySessionToken
226
+ ) {
227
+ try {
228
+ serviceabilityResult = await checkServiceability(
229
+ checkoutConfig,
230
+ serviceabilitySessionToken,
231
+ pincode,
232
+ { lat, lng }
233
+ );
234
+ onServiceabilityResult?.(serviceabilityResult);
235
+ } catch {
236
+ // Fail open if the platform serviceability check itself is unavailable.
237
+ }
238
+ }
205
239
 
206
240
  dispatch({
207
241
  type: 'LOAD_SUCCESS',
@@ -209,13 +243,25 @@ const AddressForm: React.FC<AddressFormProps> = ({
209
243
  alternatives: adminRes.data.alternatives || [],
210
244
  addressComponents: reverseRes.data.addressComponents,
211
245
  pincodeHasDelivery: hasDelivery,
246
+ serviceabilityResult,
212
247
  });
213
248
  } catch (err) {
214
249
  const msg = err instanceof Error ? err.message : 'Failed to fetch address data.';
215
250
  dispatch({ type: 'LOAD_ERROR', message: msg });
216
251
  onError?.(err instanceof Error ? err : new Error(msg));
217
252
  }
218
- }, [digipin, lat, lng, apiKey, apiBaseUrl, onError]);
253
+ }, [
254
+ digipin,
255
+ lat,
256
+ lng,
257
+ apiKey,
258
+ apiBaseUrl,
259
+ onError,
260
+ checkoutConfig,
261
+ serviceabilitySessionToken,
262
+ enableServiceabilityCheck,
263
+ onServiceabilityResult,
264
+ ]);
219
265
 
220
266
  useEffect(() => {
221
267
  void fetchAdminInfo();
@@ -226,6 +272,11 @@ const AddressForm: React.FC<AddressFormProps> = ({
226
272
  if (state.status !== 'ready') return;
227
273
  if (!state.fields.flatNumber.trim()) return;
228
274
  if (state.selectedLabel === 'other' && !state.labelText.trim()) return;
275
+ const serviceabilityBlocked =
276
+ state.serviceabilityResult?.checked
277
+ && state.serviceabilityResult.serviceable === false
278
+ && (serviceabilityBlockCheckout ?? state.serviceabilityResult.block_checkout);
279
+ if (serviceabilityBlocked) return;
229
280
 
230
281
  const { adminInfo, selectedLocality, selectedLabel, labelText, fields } = state;
231
282
 
@@ -263,7 +314,7 @@ const AddressForm: React.FC<AddressFormProps> = ({
263
314
  } finally {
264
315
  dispatch({ type: 'SUBMIT_END' });
265
316
  }
266
- }, [state, digipin, lat, lng, onAddressComplete]);
317
+ }, [state, digipin, lat, lng, onAddressComplete, serviceabilityBlockCheckout]);
267
318
 
268
319
  // ─── Field input helper ────────────────────────────────────────────────────
269
320
  const renderField = (
@@ -306,6 +357,24 @@ const AddressForm: React.FC<AddressFormProps> = ({
306
357
  </View>
307
358
  );
308
359
 
360
+ const serviceabilityBlocked =
361
+ state.status === 'ready'
362
+ && state.serviceabilityResult?.checked
363
+ && state.serviceabilityResult.serviceable === false
364
+ && (serviceabilityBlockCheckout ?? state.serviceabilityResult.block_checkout);
365
+
366
+ const showMerchantServiceability =
367
+ state.status === 'ready'
368
+ && state.serviceabilityResult?.checked
369
+ && state.serviceabilityResult.serviceable === false;
370
+
371
+ const showIndiaPostInfo =
372
+ state.status === 'ready'
373
+ && !state.pincodeHasDelivery
374
+ && state.serviceabilityResult?.serviceable !== true
375
+ && !showMerchantServiceability
376
+ && (state.serviceabilityResult?.show_india_post_delivery_warning ?? showIndiaPostDeliveryWarning);
377
+
309
378
  return (
310
379
  <KeyboardAvoidingView
311
380
  behavior={Platform.OS === 'ios' ? 'padding' : undefined}
@@ -411,7 +480,7 @@ const AddressForm: React.FC<AddressFormProps> = ({
411
480
  <Text style={[styles.autoRowLabel, isDark && styles.autoRowLabelDark]}>
412
481
  Locality
413
482
  </Text>
414
- {state.alternatives.length > 0 ? (
483
+ {state.localityOptions.length > 1 ? (
415
484
  <TouchableOpacity
416
485
  style={[
417
486
  styles.localitySelector,
@@ -449,20 +518,58 @@ const AddressForm: React.FC<AddressFormProps> = ({
449
518
  </View>
450
519
  </View>
451
520
 
452
- {!state.pincodeHasDelivery ? (
521
+ {showMerchantServiceability && state.serviceabilityResult ? (
522
+ <View
523
+ style={[
524
+ styles.pincodeBanner,
525
+ serviceabilityBlocked
526
+ ? styles.pincodeBannerError
527
+ : styles.pincodeBannerWarning,
528
+ isDark && (
529
+ serviceabilityBlocked
530
+ ? styles.pincodeBannerErrorDark
531
+ : styles.pincodeBannerDark
532
+ ),
533
+ ]}
534
+ accessibilityRole="text"
535
+ accessibilityLabel={
536
+ serviceabilityBlocked
537
+ ? 'Delivery unavailable'
538
+ : 'Delivery may be limited'
539
+ }
540
+ >
541
+ <Text style={styles.pincodeBannerIcon}>{serviceabilityBlocked ? '!' : '⚠'}</Text>
542
+ <View style={{ flex: 1 }}>
543
+ <Text style={[styles.pincodeBannerTitle, isDark && styles.pincodeBannerTitleDark]}>
544
+ {serviceabilityBlocked ? 'Delivery unavailable' : 'Delivery may be limited'}
545
+ </Text>
546
+ <Text style={[styles.pincodeBannerBody, isDark && styles.pincodeBannerBodyDark]}>
547
+ {state.serviceabilityResult.message
548
+ ?? (serviceabilityBlocked
549
+ ? 'This seller does not currently deliver to this pincode.'
550
+ : 'This seller recommends confirming delivery availability for this pincode.')}
551
+ </Text>
552
+ </View>
553
+ </View>
554
+ ) : null}
555
+
556
+ {showIndiaPostInfo ? (
453
557
  <View
454
- style={[styles.pincodeBanner, isDark && styles.pincodeBannerDark]}
558
+ style={[
559
+ styles.pincodeBanner,
560
+ styles.pincodeBannerInfo,
561
+ isDark && styles.pincodeBannerInfoDark,
562
+ ]}
455
563
  accessibilityRole="text"
456
- accessibilityLabel="Non-delivery area warning"
564
+ accessibilityLabel="India Post home-delivery information"
457
565
  >
458
- <Text style={styles.pincodeBannerIcon}>⚠</Text>
566
+ <Text style={styles.pincodeBannerIcon}>i</Text>
459
567
  <View style={{ flex: 1 }}>
460
568
  <Text style={[styles.pincodeBannerTitle, isDark && styles.pincodeBannerTitleDark]}>
461
- Non-delivery area
569
+ India Post: no home-delivery office
462
570
  </Text>
463
571
  <Text style={[styles.pincodeBannerBody, isDark && styles.pincodeBannerBodyDark]}>
464
- This pincode has no India Post home-delivery office. Courier delivery may be
465
- limited — confirm with your seller before placing the order.
572
+ Courier partners may still deliver to this pincode.
466
573
  </Text>
467
574
  </View>
468
575
  </View>
@@ -612,13 +719,15 @@ const AddressForm: React.FC<AddressFormProps> = ({
612
719
  styles.btnPrimary,
613
720
  { flex: 1 },
614
721
  (state.submitting || !state.fields.flatNumber.trim()
615
- || (state.selectedLabel === 'other' && !state.labelText.trim())) && styles.btnDisabled,
722
+ || (state.selectedLabel === 'other' && !state.labelText.trim())
723
+ || serviceabilityBlocked) && styles.btnDisabled,
616
724
  ]}
617
725
  onPress={handleSubmit}
618
726
  disabled={
619
727
  state.submitting
620
728
  || !state.fields.flatNumber.trim()
621
729
  || (state.selectedLabel === 'other' && !state.labelText.trim())
730
+ || Boolean(serviceabilityBlocked)
622
731
  }
623
732
  activeOpacity={0.8}
624
733
  accessibilityRole="button"
@@ -634,7 +743,7 @@ const AddressForm: React.FC<AddressFormProps> = ({
634
743
  ) : null}
635
744
 
636
745
  {/* ── Locality picker modal ── */}
637
- {state.status === 'ready' && state.alternatives.length > 0 ? (
746
+ {state.status === 'ready' && state.localityOptions.length > 1 ? (
638
747
  <Modal
639
748
  visible={showLocalityPicker}
640
749
  transparent
@@ -656,11 +765,8 @@ const AddressForm: React.FC<AddressFormProps> = ({
656
765
  Select Locality
657
766
  </Text>
658
767
  <FlatList
659
- data={[
660
- { name: state.adminInfo.locality } as LocationAlternative,
661
- ...state.alternatives,
662
- ]}
663
- keyExtractor={(item, idx) => `${item.name}-${idx}`}
768
+ data={state.localityOptions.map((name) => ({ name }))}
769
+ keyExtractor={(item) => item.name}
664
770
  renderItem={({ item }) => {
665
771
  const isSelected = item.name === state.selectedLocality;
666
772
  return (
@@ -6,6 +6,8 @@ import {
6
6
  pincodeHasDeliveryOffice,
7
7
  type AddressComponents,
8
8
  } from '../core/api';
9
+ import { checkServiceability, type ServiceabilityResult } from '../core/checkout-api';
10
+ import { processLocalityLookup } from '../core/locality';
9
11
  import type {
10
12
  AddressFormProps,
11
13
  AddressLabel,
@@ -31,6 +33,7 @@ type FormState =
31
33
  status: 'ready';
32
34
  adminInfo: AdministrativeInfo;
33
35
  alternatives: LocationAlternative[];
36
+ localityOptions: string[];
34
37
  selectedLocality: string; // Selected locality name (from adminInfo or alternatives)
35
38
  selectedLabel: AddressLabel;
36
39
  labelText: string;
@@ -38,6 +41,7 @@ type FormState =
38
41
  submitting: boolean;
39
42
  /** At least one India Post office with "Delivery" (not only "Non Delivery") */
40
43
  pincodeHasDelivery: boolean;
44
+ serviceabilityResult: ServiceabilityResult | null;
41
45
  };
42
46
 
43
47
  type FormAction =
@@ -48,6 +52,7 @@ type FormAction =
48
52
  alternatives: LocationAlternative[];
49
53
  addressComponents: AddressComponents;
50
54
  pincodeHasDelivery: boolean;
55
+ serviceabilityResult: ServiceabilityResult | null;
51
56
  }
52
57
  | { type: 'LOAD_ERROR'; message: string }
53
58
  | { type: 'SET_FIELD'; key: keyof ManualFields; value: string }
@@ -103,17 +108,19 @@ function reducer(state: FormState, action: FormAction): FormState {
103
108
  case 'LOAD_SUCCESS': {
104
109
  // Pre-fill fields from addressComponents
105
110
  const preFilled = parseAddressComponents(action.addressComponents);
106
- // Default to primary locality from adminInfo
111
+ const processed = processLocalityLookup(action.adminInfo, action.alternatives || []);
107
112
  return {
108
113
  status: 'ready',
109
- adminInfo: action.adminInfo,
110
- alternatives: action.alternatives || [],
111
- selectedLocality: action.adminInfo.locality,
114
+ adminInfo: processed.adminInfo,
115
+ alternatives: processed.alternatives,
116
+ localityOptions: processed.localityOptions,
117
+ selectedLocality: processed.selectedLocality,
112
118
  selectedLabel: 'home',
113
119
  labelText: '',
114
120
  fields: { ...INITIAL_FIELDS, ...preFilled },
115
121
  submitting: false,
116
122
  pincodeHasDelivery: action.pincodeHasDelivery,
123
+ serviceabilityResult: action.serviceabilityResult,
117
124
  };
118
125
  }
119
126
  case 'LOAD_ERROR':
@@ -156,6 +163,12 @@ const AddressForm: React.FC<AddressFormProps> = ({
156
163
  onAddressComplete,
157
164
  onBack,
158
165
  onError,
166
+ checkoutConfig,
167
+ serviceabilitySessionToken,
168
+ enableServiceabilityCheck = false,
169
+ showIndiaPostDeliveryWarning = false,
170
+ serviceabilityBlockCheckout,
171
+ onServiceabilityResult,
159
172
  }) => {
160
173
  const [state, dispatch] = useReducer(reducer, { status: 'loading' });
161
174
 
@@ -195,6 +208,27 @@ const AddressForm: React.FC<AddressFormProps> = ({
195
208
  }
196
209
 
197
210
  const hasDelivery = pincodeHasDeliveryOffice(pinValidation.offices);
211
+ let serviceabilityResult: ServiceabilityResult | null = null;
212
+
213
+ if (
214
+ enableServiceabilityCheck
215
+ && checkoutConfig?.functionBaseUrl
216
+ && checkoutConfig.merchantId
217
+ && serviceabilitySessionToken
218
+ ) {
219
+ try {
220
+ serviceabilityResult = await checkServiceability(
221
+ checkoutConfig,
222
+ serviceabilitySessionToken,
223
+ pincode,
224
+ { lat, lng }
225
+ );
226
+ onServiceabilityResult?.(serviceabilityResult);
227
+ } catch {
228
+ // Fail open: merchant serviceability should never block address entry
229
+ // when the checkout-addresses function itself is unreachable.
230
+ }
231
+ }
198
232
 
199
233
  dispatch({
200
234
  type: 'LOAD_SUCCESS',
@@ -202,13 +236,25 @@ const AddressForm: React.FC<AddressFormProps> = ({
202
236
  alternatives: adminRes.data.alternatives || [],
203
237
  addressComponents: reverseRes.data.addressComponents,
204
238
  pincodeHasDelivery: hasDelivery,
239
+ serviceabilityResult,
205
240
  });
206
241
  } catch (err) {
207
242
  const msg = err instanceof Error ? err.message : 'Failed to fetch address data.';
208
243
  dispatch({ type: 'LOAD_ERROR', message: msg });
209
244
  onError?.(err instanceof Error ? err : new Error(msg));
210
245
  }
211
- }, [digipin, lat, lng, apiKey, apiBaseUrl, onError]);
246
+ }, [
247
+ digipin,
248
+ lat,
249
+ lng,
250
+ apiKey,
251
+ apiBaseUrl,
252
+ onError,
253
+ checkoutConfig,
254
+ serviceabilitySessionToken,
255
+ enableServiceabilityCheck,
256
+ onServiceabilityResult,
257
+ ]);
212
258
 
213
259
  useEffect(() => {
214
260
  void fetchAdminInfo();
@@ -223,6 +269,11 @@ const AddressForm: React.FC<AddressFormProps> = ({
223
269
  const { adminInfo, selectedLocality, selectedLabel, labelText, fields } = state;
224
270
 
225
271
  if (selectedLabel === 'other' && !labelText.trim()) return;
272
+ const serviceabilityBlocked =
273
+ state.serviceabilityResult?.checked
274
+ && state.serviceabilityResult.serviceable === false
275
+ && (serviceabilityBlockCheckout ?? state.serviceabilityResult.block_checkout);
276
+ if (serviceabilityBlocked) return;
226
277
 
227
278
  const parts: string[] = [
228
279
  fields.flatNumber,
@@ -259,9 +310,27 @@ const AddressForm: React.FC<AddressFormProps> = ({
259
310
  dispatch({ type: 'SUBMIT_END' });
260
311
  }
261
312
  },
262
- [state, digipin, lat, lng, onAddressComplete]
313
+ [state, digipin, lat, lng, onAddressComplete, serviceabilityBlockCheckout]
263
314
  );
264
315
 
316
+ const serviceabilityBlocked =
317
+ state.status === 'ready'
318
+ && state.serviceabilityResult?.checked
319
+ && state.serviceabilityResult.serviceable === false
320
+ && (serviceabilityBlockCheckout ?? state.serviceabilityResult.block_checkout);
321
+
322
+ const showMerchantServiceability =
323
+ state.status === 'ready'
324
+ && state.serviceabilityResult?.checked
325
+ && state.serviceabilityResult.serviceable === false;
326
+
327
+ const showIndiaPostInfo =
328
+ state.status === 'ready'
329
+ && !state.pincodeHasDelivery
330
+ && state.serviceabilityResult?.serviceable !== true
331
+ && !showMerchantServiceability
332
+ && (state.serviceabilityResult?.show_india_post_delivery_warning ?? showIndiaPostDeliveryWarning);
333
+
265
334
  return (
266
335
  <div className="qr-form-wrapper">
267
336
  {/* ── Step header ── */}
@@ -355,24 +424,19 @@ const AddressForm: React.FC<AddressFormProps> = ({
355
424
  <span className="qr-auto-row__value">{state.adminInfo.district}</span>
356
425
  </div>
357
426
 
358
- {/* Locality - show dropdown if alternatives exist */}
427
+ {/* Locality - show dropdown if multiple unique localities exist */}
359
428
  <div className="qr-auto-row qr-auto-row--full">
360
429
  <span className="qr-auto-row__label">Locality</span>
361
- {state.alternatives.length > 0 ? (
430
+ {state.localityOptions.length > 1 ? (
362
431
  <select
363
432
  className="qr-auto-row__select"
364
433
  value={state.selectedLocality}
365
434
  onChange={(e) => dispatch({ type: 'SET_LOCALITY', locality: e.target.value })}
366
435
  aria-label="Select locality"
367
436
  >
368
- {/* Primary option (from adminInfo) */}
369
- <option value={state.adminInfo.locality}>
370
- {state.adminInfo.locality}
371
- </option>
372
- {/* Alternatives */}
373
- {state.alternatives.map((alt, idx) => (
374
- <option key={idx} value={alt.name}>
375
- {alt.name}
437
+ {state.localityOptions.map((name) => (
438
+ <option key={name} value={name}>
439
+ {name}
376
440
  </option>
377
441
  ))}
378
442
  </select>
@@ -391,19 +455,44 @@ const AddressForm: React.FC<AddressFormProps> = ({
391
455
  </div>
392
456
  </fieldset>
393
457
 
394
- {/* Serviceability: India Post "Non Delivery" only — warn (still allow save) */}
395
- {!state.pincodeHasDelivery && (
458
+ {showMerchantServiceability && state.serviceabilityResult && (
459
+ <div
460
+ className={`qr-pincode-banner ${
461
+ serviceabilityBlocked
462
+ ? 'qr-pincode-banner--error'
463
+ : 'qr-pincode-banner--warning'
464
+ }`}
465
+ role={serviceabilityBlocked ? 'alert' : 'status'}
466
+ aria-live="polite"
467
+ >
468
+ <span className="qr-pincode-banner__icon" aria-hidden="true">
469
+ {serviceabilityBlocked ? '!' : '⚠'}
470
+ </span>
471
+ <div className="qr-pincode-banner__text">
472
+ <strong>
473
+ {serviceabilityBlocked ? 'Delivery unavailable' : 'Delivery may be limited'}
474
+ </strong>
475
+ <span>
476
+ {state.serviceabilityResult.message
477
+ ?? (serviceabilityBlocked
478
+ ? 'This seller does not currently deliver to this pincode.'
479
+ : 'This seller recommends confirming delivery availability for this pincode.')}
480
+ </span>
481
+ </div>
482
+ </div>
483
+ )}
484
+
485
+ {showIndiaPostInfo && (
396
486
  <div
397
- className="qr-pincode-banner qr-pincode-banner--warning"
487
+ className="qr-pincode-banner qr-pincode-banner--info"
398
488
  role="status"
399
489
  aria-live="polite"
400
490
  >
401
- <span className="qr-pincode-banner__icon" aria-hidden="true">⚠</span>
491
+ <span className="qr-pincode-banner__icon" aria-hidden="true">i</span>
402
492
  <div className="qr-pincode-banner__text">
403
- <strong>Non-delivery area</strong>
493
+ <strong>India Post: no home-delivery office</strong>
404
494
  <span>
405
- This pincode has no India Post home-delivery office. Courier delivery may be limited —
406
- confirm with your seller before placing the order.
495
+ Courier partners may still deliver to this pincode.
407
496
  </span>
408
497
  </div>
409
498
  </div>
@@ -575,6 +664,7 @@ const AddressForm: React.FC<AddressFormProps> = ({
575
664
  state.submitting
576
665
  || !state.fields.flatNumber.trim()
577
666
  || (state.selectedLabel === 'other' && !state.labelText.trim())
667
+ || Boolean(serviceabilityBlocked)
578
668
  }
579
669
  >
580
670
  {state.submitting ? (
@@ -97,6 +97,9 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
97
97
  merchantId = '',
98
98
  supabaseFunctionBaseUrl = '',
99
99
  enableCod = false,
100
+ enableServiceabilityCheck = false,
101
+ showIndiaPostDeliveryWarning = false,
102
+ serviceabilityBlockCheckout,
100
103
  codCartTotalPaise,
101
104
  codSessionToken = '',
102
105
  }) => {
@@ -243,6 +246,11 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
243
246
  onBack={handleBack}
244
247
  onError={onError}
245
248
  theme={theme}
249
+ checkoutConfig={checkoutConfig}
250
+ serviceabilitySessionToken={codSession}
251
+ enableServiceabilityCheck={enableServiceabilityCheck}
252
+ showIndiaPostDeliveryWarning={showIndiaPostDeliveryWarning}
253
+ serviceabilityBlockCheckout={serviceabilityBlockCheckout}
246
254
  />
247
255
  ) : null}
248
256
 
@@ -159,6 +159,9 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
159
159
  headerBanner,
160
160
  onCheckoutEvent,
161
161
  enableCod = false,
162
+ enableServiceabilityCheck = false,
163
+ showIndiaPostDeliveryWarning = false,
164
+ serviceabilityBlockCheckout,
162
165
  codCartTotalPaise,
163
166
  codSessionToken = '',
164
167
  enableEmailAuth = false,
@@ -171,6 +174,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
171
174
  prepaidNudgeCopy,
172
175
  prepaidNudgeCtaUrl,
173
176
  registerController,
177
+ orderConfirmationUrl,
174
178
  }) => {
175
179
  const authMode: AuthMode = enablePhoneAuth ? 'phone' : enableEmailAuth ? 'email' : 'none';
176
180
  const initialStep: Step = authMode === 'phone' ? 'phone' : authMode === 'email' ? 'email' : 'map';
@@ -386,12 +390,21 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
386
390
  void finishAddress(complete);
387
391
  };
388
392
 
389
- const handlePaymentComplete = (method: string) => {
390
- setPaymentMethod(method);
391
- emit({ type: 'payment_method_selected', step: 'done', paymentMethod: method });
393
+ const handlePaymentComplete = ({ paymentMethod, razorpayOrderId, razorpayPaymentId }: {
394
+ paymentMethod: string;
395
+ razorpayOrderId?: string;
396
+ razorpayPaymentId?: string;
397
+ }) => {
398
+ setPaymentMethod(paymentMethod);
399
+ emit({ type: 'payment_method_selected', step: 'done', paymentMethod });
392
400
  setStep('done');
393
401
  if (completedAddress) onComplete(completedAddress);
394
- onPaymentComplete?.({ paymentMethod: method, sessionId: auth?.sessionId });
402
+ onPaymentComplete?.({
403
+ paymentMethod,
404
+ sessionId: auth?.sessionId,
405
+ razorpayOrderId,
406
+ razorpayPaymentId,
407
+ });
395
408
  };
396
409
 
397
410
  // ── Map step callbacks ────────────────────────────────────────────────────
@@ -446,6 +459,11 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
446
459
 
447
460
  if (withPayment && codSession) {
448
461
  setStep('payment');
462
+ } else if (withPayment && !codSession) {
463
+ onError?.(new Error('enablePayment requires phone/email auth or a codSessionToken prop.'));
464
+ setStep('done');
465
+ onComplete(address);
466
+ return;
449
467
  } else {
450
468
  setStep('done');
451
469
  onComplete(address);
@@ -718,6 +736,11 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
718
736
  onBack={handleBack}
719
737
  onError={onError}
720
738
  theme={theme}
739
+ checkoutConfig={checkoutConfig}
740
+ serviceabilitySessionToken={codSession}
741
+ enableServiceabilityCheck={enableServiceabilityCheck}
742
+ showIndiaPostDeliveryWarning={showIndiaPostDeliveryWarning}
743
+ serviceabilityBlockCheckout={serviceabilityBlockCheckout}
721
744
  />
722
745
  )}
723
746
 
@@ -736,6 +759,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
736
759
  onEvent={(type, paymentMethod) =>
737
760
  emit({ type, step: 'payment', paymentMethod, buyerId: auth?.buyerId })
738
761
  }
762
+ orderConfirmationUrl={orderConfirmationUrl}
739
763
  />
740
764
  )}
741
765
 
@@ -42,6 +42,7 @@ const PaymentStep: React.FC<PaymentStepProps> = ({
42
42
  onComplete,
43
43
  onBack,
44
44
  onEvent,
45
+ orderConfirmationUrl,
45
46
  }) => {
46
47
  const [loading, setLoading] = useState(false);
47
48
  const [error, setError] = useState<string | null>(null);
@@ -82,7 +83,15 @@ const PaymentStep: React.FC<PaymentStepProps> = ({
82
83
  payment_method: 'prepaid',
83
84
  });
84
85
  onEvent?.('payment_method_selected', result.payment_method);
85
- onComplete(result.payment_method);
86
+ onComplete({
87
+ paymentMethod: result.payment_method,
88
+ razorpayOrderId: result.razorpay_order_id,
89
+ razorpayPaymentId: result.razorpay_payment_id,
90
+ });
91
+ if (orderConfirmationUrl) {
92
+ const url = orderConfirmationUrl.replace('{{sessionId}}', sessionId ?? '');
93
+ window.location.href = url;
94
+ }
86
95
  resolve();
87
96
  } catch (e) {
88
97
  reject(e);
@@ -107,7 +116,7 @@ const PaymentStep: React.FC<PaymentStepProps> = ({
107
116
  try {
108
117
  const result = await recordCodPayment(checkoutConfig, sessionToken);
109
118
  onEvent?.('payment_method_selected', result.payment_method);
110
- onComplete(result.payment_method);
119
+ onComplete({ paymentMethod: result.payment_method });
111
120
  } catch (e) {
112
121
  setError(e instanceof Error ? e.message : 'Failed to select COD');
113
122
  } finally {