@quantaroute/checkout 1.4.3 → 1.4.5
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 +28 -0
- package/README.md +70 -2
- package/dist/lib/index.d.ts +69 -0
- package/dist/lib/quantaroute-checkout.es.js +165 -147
- package/dist/lib/quantaroute-checkout.umd.js +159 -141
- package/dist/style.css +1 -1
- package/package.json +3 -2
- package/src/components/AddressForm.native.tsx +184 -23
- package/src/components/AddressForm.tsx +152 -20
- package/src/components/AddressLabelIcons.native.tsx +144 -0
- package/src/components/AddressLabelIcons.tsx +46 -0
- package/src/components/CheckoutWidget.native.tsx +8 -0
- package/src/components/CheckoutWidget.tsx +11 -0
- package/src/components/MapPinSelector.native.tsx +8 -1
- package/src/components/MapPinSelector.tsx +9 -1
- package/src/components/SavedAddressStep.tsx +7 -1
- package/src/core/api.ts +9 -1
- package/src/core/checkout-api.ts +56 -0
- package/src/core/digipin.ts +10 -1
- package/src/core/types.ts +30 -1
- package/src/index.ts +4 -0
- package/src/styles/checkout.css +115 -20
- package/src/styles/checkout.native.ts +50 -15
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
pincodeHasDeliveryOffice,
|
|
19
19
|
type AddressComponents,
|
|
20
20
|
} from '../core/api';
|
|
21
|
+
import { checkServiceability, type ServiceabilityResult } from '../core/checkout-api';
|
|
21
22
|
import type {
|
|
22
23
|
AddressFormProps,
|
|
23
24
|
AddressLabel,
|
|
@@ -26,6 +27,7 @@ import type {
|
|
|
26
27
|
LocationAlternative,
|
|
27
28
|
} from '../core/types';
|
|
28
29
|
import { styles, COLORS } from '../styles/checkout.native';
|
|
30
|
+
import { AddressDetailsIcon, AddressLabelIcon } from './AddressLabelIcons.native';
|
|
29
31
|
|
|
30
32
|
// ─── State (identical logic to web AddressForm) ───────────────────────────────
|
|
31
33
|
|
|
@@ -45,9 +47,11 @@ type FormState =
|
|
|
45
47
|
alternatives: LocationAlternative[];
|
|
46
48
|
selectedLocality: string;
|
|
47
49
|
selectedLabel: AddressLabel;
|
|
50
|
+
labelText: string;
|
|
48
51
|
fields: ManualFields;
|
|
49
52
|
submitting: boolean;
|
|
50
53
|
pincodeHasDelivery: boolean;
|
|
54
|
+
serviceabilityResult: ServiceabilityResult | null;
|
|
51
55
|
};
|
|
52
56
|
|
|
53
57
|
type FormAction =
|
|
@@ -58,11 +62,13 @@ type FormAction =
|
|
|
58
62
|
alternatives: LocationAlternative[];
|
|
59
63
|
addressComponents: AddressComponents;
|
|
60
64
|
pincodeHasDelivery: boolean;
|
|
65
|
+
serviceabilityResult: ServiceabilityResult | null;
|
|
61
66
|
}
|
|
62
67
|
| { type: 'LOAD_ERROR'; message: string }
|
|
63
68
|
| { type: 'SET_FIELD'; key: keyof ManualFields; value: string }
|
|
64
69
|
| { type: 'SET_LOCALITY'; locality: string }
|
|
65
70
|
| { type: 'SET_LABEL'; label: AddressLabel }
|
|
71
|
+
| { type: 'SET_LABEL_TEXT'; value: string }
|
|
66
72
|
| { type: 'SUBMIT_START' }
|
|
67
73
|
| { type: 'SUBMIT_END' };
|
|
68
74
|
|
|
@@ -106,9 +112,11 @@ function reducer(state: FormState, action: FormAction): FormState {
|
|
|
106
112
|
alternatives: action.alternatives || [],
|
|
107
113
|
selectedLocality: action.adminInfo.locality,
|
|
108
114
|
selectedLabel: 'home',
|
|
115
|
+
labelText: '',
|
|
109
116
|
fields: { ...INITIAL_FIELDS, ...preFilled },
|
|
110
117
|
submitting: false,
|
|
111
118
|
pincodeHasDelivery: action.pincodeHasDelivery,
|
|
119
|
+
serviceabilityResult: action.serviceabilityResult,
|
|
112
120
|
};
|
|
113
121
|
}
|
|
114
122
|
case 'LOAD_ERROR':
|
|
@@ -121,7 +129,14 @@ function reducer(state: FormState, action: FormAction): FormState {
|
|
|
121
129
|
return { ...state, selectedLocality: action.locality };
|
|
122
130
|
case 'SET_LABEL':
|
|
123
131
|
if (state.status !== 'ready') return state;
|
|
124
|
-
return {
|
|
132
|
+
return {
|
|
133
|
+
...state,
|
|
134
|
+
selectedLabel: action.label,
|
|
135
|
+
labelText: action.label === 'other' ? state.labelText : '',
|
|
136
|
+
};
|
|
137
|
+
case 'SET_LABEL_TEXT':
|
|
138
|
+
if (state.status !== 'ready') return state;
|
|
139
|
+
return { ...state, labelText: action.value.slice(0, 64) };
|
|
125
140
|
case 'SUBMIT_START':
|
|
126
141
|
if (state.status !== 'ready') return state;
|
|
127
142
|
return { ...state, submitting: true };
|
|
@@ -150,6 +165,12 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
150
165
|
onBack,
|
|
151
166
|
onError,
|
|
152
167
|
theme = 'light',
|
|
168
|
+
checkoutConfig,
|
|
169
|
+
serviceabilitySessionToken,
|
|
170
|
+
enableServiceabilityCheck = false,
|
|
171
|
+
showIndiaPostDeliveryWarning = false,
|
|
172
|
+
serviceabilityBlockCheckout,
|
|
173
|
+
onServiceabilityResult,
|
|
153
174
|
}) => {
|
|
154
175
|
const [state, dispatch] = useReducer(reducer, { status: 'loading' });
|
|
155
176
|
const [showLocalityPicker, setShowLocalityPicker] = useState(false);
|
|
@@ -191,6 +212,26 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
191
212
|
}
|
|
192
213
|
|
|
193
214
|
const hasDelivery = pincodeHasDeliveryOffice(pinValidation.offices);
|
|
215
|
+
let serviceabilityResult: ServiceabilityResult | null = null;
|
|
216
|
+
|
|
217
|
+
if (
|
|
218
|
+
enableServiceabilityCheck
|
|
219
|
+
&& checkoutConfig?.functionBaseUrl
|
|
220
|
+
&& checkoutConfig.merchantId
|
|
221
|
+
&& serviceabilitySessionToken
|
|
222
|
+
) {
|
|
223
|
+
try {
|
|
224
|
+
serviceabilityResult = await checkServiceability(
|
|
225
|
+
checkoutConfig,
|
|
226
|
+
serviceabilitySessionToken,
|
|
227
|
+
pincode,
|
|
228
|
+
{ lat, lng }
|
|
229
|
+
);
|
|
230
|
+
onServiceabilityResult?.(serviceabilityResult);
|
|
231
|
+
} catch {
|
|
232
|
+
// Fail open if the platform serviceability check itself is unavailable.
|
|
233
|
+
}
|
|
234
|
+
}
|
|
194
235
|
|
|
195
236
|
dispatch({
|
|
196
237
|
type: 'LOAD_SUCCESS',
|
|
@@ -198,13 +239,25 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
198
239
|
alternatives: adminRes.data.alternatives || [],
|
|
199
240
|
addressComponents: reverseRes.data.addressComponents,
|
|
200
241
|
pincodeHasDelivery: hasDelivery,
|
|
242
|
+
serviceabilityResult,
|
|
201
243
|
});
|
|
202
244
|
} catch (err) {
|
|
203
245
|
const msg = err instanceof Error ? err.message : 'Failed to fetch address data.';
|
|
204
246
|
dispatch({ type: 'LOAD_ERROR', message: msg });
|
|
205
247
|
onError?.(err instanceof Error ? err : new Error(msg));
|
|
206
248
|
}
|
|
207
|
-
}, [
|
|
249
|
+
}, [
|
|
250
|
+
digipin,
|
|
251
|
+
lat,
|
|
252
|
+
lng,
|
|
253
|
+
apiKey,
|
|
254
|
+
apiBaseUrl,
|
|
255
|
+
onError,
|
|
256
|
+
checkoutConfig,
|
|
257
|
+
serviceabilitySessionToken,
|
|
258
|
+
enableServiceabilityCheck,
|
|
259
|
+
onServiceabilityResult,
|
|
260
|
+
]);
|
|
208
261
|
|
|
209
262
|
useEffect(() => {
|
|
210
263
|
void fetchAdminInfo();
|
|
@@ -214,8 +267,14 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
214
267
|
const handleSubmit = useCallback(() => {
|
|
215
268
|
if (state.status !== 'ready') return;
|
|
216
269
|
if (!state.fields.flatNumber.trim()) return;
|
|
270
|
+
if (state.selectedLabel === 'other' && !state.labelText.trim()) return;
|
|
271
|
+
const serviceabilityBlocked =
|
|
272
|
+
state.serviceabilityResult?.checked
|
|
273
|
+
&& state.serviceabilityResult.serviceable === false
|
|
274
|
+
&& (serviceabilityBlockCheckout ?? state.serviceabilityResult.block_checkout);
|
|
275
|
+
if (serviceabilityBlocked) return;
|
|
217
276
|
|
|
218
|
-
const { adminInfo, selectedLocality, selectedLabel, fields } = state;
|
|
277
|
+
const { adminInfo, selectedLocality, selectedLabel, labelText, fields } = state;
|
|
219
278
|
|
|
220
279
|
const parts: string[] = [
|
|
221
280
|
fields.flatNumber,
|
|
@@ -242,6 +301,7 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
242
301
|
...fields,
|
|
243
302
|
formattedAddress: parts.join(', '),
|
|
244
303
|
label: selectedLabel,
|
|
304
|
+
...(selectedLabel === 'other' ? { labelText: labelText.trim() } : {}),
|
|
245
305
|
};
|
|
246
306
|
|
|
247
307
|
dispatch({ type: 'SUBMIT_START' });
|
|
@@ -250,7 +310,7 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
250
310
|
} finally {
|
|
251
311
|
dispatch({ type: 'SUBMIT_END' });
|
|
252
312
|
}
|
|
253
|
-
}, [state, digipin, lat, lng, onAddressComplete]);
|
|
313
|
+
}, [state, digipin, lat, lng, onAddressComplete, serviceabilityBlockCheckout]);
|
|
254
314
|
|
|
255
315
|
// ─── Field input helper ────────────────────────────────────────────────────
|
|
256
316
|
const renderField = (
|
|
@@ -293,6 +353,24 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
293
353
|
</View>
|
|
294
354
|
);
|
|
295
355
|
|
|
356
|
+
const serviceabilityBlocked =
|
|
357
|
+
state.status === 'ready'
|
|
358
|
+
&& state.serviceabilityResult?.checked
|
|
359
|
+
&& state.serviceabilityResult.serviceable === false
|
|
360
|
+
&& (serviceabilityBlockCheckout ?? state.serviceabilityResult.block_checkout);
|
|
361
|
+
|
|
362
|
+
const showMerchantServiceability =
|
|
363
|
+
state.status === 'ready'
|
|
364
|
+
&& state.serviceabilityResult?.checked
|
|
365
|
+
&& state.serviceabilityResult.serviceable === false;
|
|
366
|
+
|
|
367
|
+
const showIndiaPostInfo =
|
|
368
|
+
state.status === 'ready'
|
|
369
|
+
&& !state.pincodeHasDelivery
|
|
370
|
+
&& state.serviceabilityResult?.serviceable !== true
|
|
371
|
+
&& !showMerchantServiceability
|
|
372
|
+
&& (state.serviceabilityResult?.show_india_post_delivery_warning ?? showIndiaPostDeliveryWarning);
|
|
373
|
+
|
|
296
374
|
return (
|
|
297
375
|
<KeyboardAvoidingView
|
|
298
376
|
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
|
|
@@ -368,7 +446,7 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
368
446
|
<View style={styles.sectionHeader}>
|
|
369
447
|
<Text style={styles.sectionHeaderIcon}>📍</Text>
|
|
370
448
|
<Text style={[styles.sectionHeaderText, isDark && styles.sectionHeaderTextDark]}>
|
|
371
|
-
Auto-detected from your
|
|
449
|
+
Auto-detected from your digipin
|
|
372
450
|
</Text>
|
|
373
451
|
</View>
|
|
374
452
|
|
|
@@ -436,20 +514,58 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
436
514
|
</View>
|
|
437
515
|
</View>
|
|
438
516
|
|
|
439
|
-
{
|
|
517
|
+
{showMerchantServiceability && state.serviceabilityResult ? (
|
|
518
|
+
<View
|
|
519
|
+
style={[
|
|
520
|
+
styles.pincodeBanner,
|
|
521
|
+
serviceabilityBlocked
|
|
522
|
+
? styles.pincodeBannerError
|
|
523
|
+
: styles.pincodeBannerWarning,
|
|
524
|
+
isDark && (
|
|
525
|
+
serviceabilityBlocked
|
|
526
|
+
? styles.pincodeBannerErrorDark
|
|
527
|
+
: styles.pincodeBannerDark
|
|
528
|
+
),
|
|
529
|
+
]}
|
|
530
|
+
accessibilityRole="text"
|
|
531
|
+
accessibilityLabel={
|
|
532
|
+
serviceabilityBlocked
|
|
533
|
+
? 'Delivery unavailable'
|
|
534
|
+
: 'Delivery may be limited'
|
|
535
|
+
}
|
|
536
|
+
>
|
|
537
|
+
<Text style={styles.pincodeBannerIcon}>{serviceabilityBlocked ? '!' : '⚠'}</Text>
|
|
538
|
+
<View style={{ flex: 1 }}>
|
|
539
|
+
<Text style={[styles.pincodeBannerTitle, isDark && styles.pincodeBannerTitleDark]}>
|
|
540
|
+
{serviceabilityBlocked ? 'Delivery unavailable' : 'Delivery may be limited'}
|
|
541
|
+
</Text>
|
|
542
|
+
<Text style={[styles.pincodeBannerBody, isDark && styles.pincodeBannerBodyDark]}>
|
|
543
|
+
{state.serviceabilityResult.message
|
|
544
|
+
?? (serviceabilityBlocked
|
|
545
|
+
? 'This seller does not currently deliver to this pincode.'
|
|
546
|
+
: 'This seller recommends confirming delivery availability for this pincode.')}
|
|
547
|
+
</Text>
|
|
548
|
+
</View>
|
|
549
|
+
</View>
|
|
550
|
+
) : null}
|
|
551
|
+
|
|
552
|
+
{showIndiaPostInfo ? (
|
|
440
553
|
<View
|
|
441
|
-
style={[
|
|
554
|
+
style={[
|
|
555
|
+
styles.pincodeBanner,
|
|
556
|
+
styles.pincodeBannerInfo,
|
|
557
|
+
isDark && styles.pincodeBannerInfoDark,
|
|
558
|
+
]}
|
|
442
559
|
accessibilityRole="text"
|
|
443
|
-
accessibilityLabel="
|
|
560
|
+
accessibilityLabel="India Post home-delivery information"
|
|
444
561
|
>
|
|
445
|
-
<Text style={styles.pincodeBannerIcon}
|
|
562
|
+
<Text style={styles.pincodeBannerIcon}>i</Text>
|
|
446
563
|
<View style={{ flex: 1 }}>
|
|
447
564
|
<Text style={[styles.pincodeBannerTitle, isDark && styles.pincodeBannerTitleDark]}>
|
|
448
|
-
|
|
565
|
+
India Post: no home-delivery office
|
|
449
566
|
</Text>
|
|
450
567
|
<Text style={[styles.pincodeBannerBody, isDark && styles.pincodeBannerBodyDark]}>
|
|
451
|
-
|
|
452
|
-
limited — confirm with your seller before placing the order.
|
|
568
|
+
Courier partners may still deliver to this pincode.
|
|
453
569
|
</Text>
|
|
454
570
|
</View>
|
|
455
571
|
</View>
|
|
@@ -457,20 +573,27 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
457
573
|
|
|
458
574
|
{/* Address label */}
|
|
459
575
|
<View style={[styles.sectionDivider, isDark && styles.sectionDividerDark]} />
|
|
460
|
-
<View style={styles.sectionHeader}>
|
|
461
|
-
<Text
|
|
576
|
+
<View style={[styles.sectionHeader, styles.sectionHeaderCompact]}>
|
|
577
|
+
<Text
|
|
578
|
+
style={[
|
|
579
|
+
styles.sectionHeaderText,
|
|
580
|
+
styles.sectionHeaderTextCompact,
|
|
581
|
+
isDark && styles.sectionHeaderTextDark,
|
|
582
|
+
]}
|
|
583
|
+
>
|
|
462
584
|
Save as
|
|
463
585
|
</Text>
|
|
464
586
|
</View>
|
|
465
587
|
<View style={styles.labelPicker}>
|
|
466
588
|
{(
|
|
467
589
|
[
|
|
468
|
-
{ value: 'home' as const, title: 'Home'
|
|
469
|
-
{ value: 'work' as const, title: 'Work'
|
|
470
|
-
{ value: 'other' as const, title: 'Other'
|
|
590
|
+
{ value: 'home' as const, title: 'Home' },
|
|
591
|
+
{ value: 'work' as const, title: 'Work' },
|
|
592
|
+
{ value: 'other' as const, title: 'Other' },
|
|
471
593
|
] as const
|
|
472
|
-
).map(({ value, title
|
|
594
|
+
).map(({ value, title }) => {
|
|
473
595
|
const active = state.selectedLabel === value;
|
|
596
|
+
const iconColor = active ? COLORS.primary : COLORS.textMuted;
|
|
474
597
|
return (
|
|
475
598
|
<TouchableOpacity
|
|
476
599
|
key={value}
|
|
@@ -484,9 +607,12 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
484
607
|
accessibilityRole="radio"
|
|
485
608
|
accessibilityState={{ checked: active }}
|
|
486
609
|
accessibilityLabel={title}
|
|
487
|
-
activeOpacity={0.
|
|
610
|
+
activeOpacity={0.97}
|
|
488
611
|
>
|
|
489
|
-
<
|
|
612
|
+
<AddressLabelIcon
|
|
613
|
+
label={value}
|
|
614
|
+
color={isDark && !active ? COLORS.textMutedDark : iconColor}
|
|
615
|
+
/>
|
|
490
616
|
<Text
|
|
491
617
|
style={[
|
|
492
618
|
styles.labelPickerText,
|
|
@@ -500,11 +626,39 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
500
626
|
);
|
|
501
627
|
})}
|
|
502
628
|
</View>
|
|
629
|
+
{state.selectedLabel === 'other' ? (
|
|
630
|
+
<View style={styles.labelTextField}>
|
|
631
|
+
<View style={styles.fieldLabel}>
|
|
632
|
+
<Text style={[styles.fieldLabelText, isDark && styles.fieldLabelTextDark]}>
|
|
633
|
+
Label name
|
|
634
|
+
</Text>
|
|
635
|
+
<Text style={styles.fieldRequired}>*</Text>
|
|
636
|
+
</View>
|
|
637
|
+
<TextInput
|
|
638
|
+
style={[
|
|
639
|
+
styles.fieldInput,
|
|
640
|
+
isDark && styles.fieldInputDark,
|
|
641
|
+
]}
|
|
642
|
+
placeholder="e.g. Friend's home, Gym"
|
|
643
|
+
placeholderTextColor={isDark ? COLORS.textFaintDark : COLORS.textFaint}
|
|
644
|
+
value={state.labelText}
|
|
645
|
+
onChangeText={(value) =>
|
|
646
|
+
dispatch({ type: 'SET_LABEL_TEXT', value })
|
|
647
|
+
}
|
|
648
|
+
maxLength={64}
|
|
649
|
+
autoCapitalize="words"
|
|
650
|
+
returnKeyType="next"
|
|
651
|
+
/>
|
|
652
|
+
</View>
|
|
653
|
+
) : null}
|
|
503
654
|
|
|
504
655
|
{/* Manual entry section */}
|
|
505
656
|
<View style={[styles.sectionDivider, isDark && styles.sectionDividerDark]} />
|
|
506
657
|
<View style={styles.sectionHeader}>
|
|
507
|
-
<
|
|
658
|
+
<AddressDetailsIcon
|
|
659
|
+
color={isDark ? COLORS.textMutedDark : COLORS.textMuted}
|
|
660
|
+
size={14}
|
|
661
|
+
/>
|
|
508
662
|
<Text style={[styles.sectionHeaderText, isDark && styles.sectionHeaderTextDark]}>
|
|
509
663
|
Your details
|
|
510
664
|
</Text>
|
|
@@ -560,10 +714,17 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
560
714
|
style={[
|
|
561
715
|
styles.btnPrimary,
|
|
562
716
|
{ flex: 1 },
|
|
563
|
-
(state.submitting || !state.fields.flatNumber.trim()
|
|
717
|
+
(state.submitting || !state.fields.flatNumber.trim()
|
|
718
|
+
|| (state.selectedLabel === 'other' && !state.labelText.trim())
|
|
719
|
+
|| serviceabilityBlocked) && styles.btnDisabled,
|
|
564
720
|
]}
|
|
565
721
|
onPress={handleSubmit}
|
|
566
|
-
disabled={
|
|
722
|
+
disabled={
|
|
723
|
+
state.submitting
|
|
724
|
+
|| !state.fields.flatNumber.trim()
|
|
725
|
+
|| (state.selectedLabel === 'other' && !state.labelText.trim())
|
|
726
|
+
|| Boolean(serviceabilityBlocked)
|
|
727
|
+
}
|
|
567
728
|
activeOpacity={0.8}
|
|
568
729
|
accessibilityRole="button"
|
|
569
730
|
accessibilityLabel="Save address"
|