@quantaroute/checkout 1.6.0 → 1.7.1
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 +29 -0
- package/README.md +27 -0
- package/dist/lib/index.d.ts +77 -1
- package/dist/lib/quantaroute-checkout.es.js +203 -194
- package/dist/lib/quantaroute-checkout.umd.js +116 -107
- package/dist/style.css +1 -1
- package/package.json +6 -6
- package/src/components/CheckoutWidget.tsx +138 -14
- package/src/components/MapPinSelector.tsx +9 -0
- package/src/components/PaymentStep.tsx +32 -6
- package/src/core/checkout-api.ts +79 -0
- package/src/core/types.ts +34 -1
- package/src/index.ts +8 -0
- package/src/styles/checkout.css +580 -19
|
@@ -11,8 +11,10 @@ import {
|
|
|
11
11
|
logFunnelEvent,
|
|
12
12
|
notifySessionAbandoned,
|
|
13
13
|
fetchSessionOffer,
|
|
14
|
+
scoreAddressRisk,
|
|
14
15
|
selectAddress,
|
|
15
16
|
verifyDigipin,
|
|
17
|
+
type AddressRiskScore,
|
|
16
18
|
type SessionOffer,
|
|
17
19
|
} from '../core/checkout-api';
|
|
18
20
|
import type { CheckoutEvent, CheckoutWidgetProps, CompleteAddress } from '../core/types';
|
|
@@ -55,6 +57,14 @@ interface AuthState {
|
|
|
55
57
|
buyerId: string;
|
|
56
58
|
}
|
|
57
59
|
|
|
60
|
+
type MobileStepStatus = 'complete' | 'active' | 'pending';
|
|
61
|
+
|
|
62
|
+
interface MobileStepItem {
|
|
63
|
+
id: 'auth' | 'address' | 'payment';
|
|
64
|
+
label: string;
|
|
65
|
+
status: MobileStepStatus;
|
|
66
|
+
}
|
|
67
|
+
|
|
58
68
|
// ─── Success screen ───────────────────────────────────────────────────────────
|
|
59
69
|
|
|
60
70
|
interface SuccessScreenProps {
|
|
@@ -195,8 +205,10 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
195
205
|
theme = 'light',
|
|
196
206
|
className = '',
|
|
197
207
|
style,
|
|
198
|
-
mapHeight = '
|
|
208
|
+
mapHeight = 'min(52dvh, 420px)',
|
|
199
209
|
title = 'Add Delivery Address',
|
|
210
|
+
mobilePresentation = 'auto',
|
|
211
|
+
mobileStepLabels,
|
|
200
212
|
indiaBoundaryUrl,
|
|
201
213
|
enableSearch = true,
|
|
202
214
|
enablePhoneAuth = false,
|
|
@@ -208,6 +220,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
208
220
|
onCheckoutEvent,
|
|
209
221
|
enableCod = false,
|
|
210
222
|
enableServiceabilityCheck = false,
|
|
223
|
+
enableAddressIntelligence = false,
|
|
211
224
|
showIndiaPostDeliveryWarning = false,
|
|
212
225
|
serviceabilityBlockCheckout,
|
|
213
226
|
codCartTotalPaise,
|
|
@@ -236,6 +249,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
236
249
|
const [emailCodeReused, setEmailCodeReused] = useState(false);
|
|
237
250
|
const [codAllowed, setCodAllowed] = useState(false);
|
|
238
251
|
const [sessionOffer, setSessionOffer] = useState<SessionOffer | null>(null);
|
|
252
|
+
const [addressRisk, setAddressRisk] = useState<AddressRiskScore | null>(null);
|
|
239
253
|
const [paymentMethod, setPaymentMethod] = useState<string | null>(null);
|
|
240
254
|
const [verifyAddress, setVerifyAddress] = useState<SavedAddress | null>(null);
|
|
241
255
|
const [paymentBackStep, setPaymentBackStep] = useState<Step>('form');
|
|
@@ -464,14 +478,9 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
464
478
|
address: CompleteAddress,
|
|
465
479
|
options?: { skipCreate?: boolean; paymentBackStep?: Step }
|
|
466
480
|
) => {
|
|
467
|
-
|
|
481
|
+
let addressForCompletion: CompleteAddress = address;
|
|
482
|
+
setCompletedAddress(addressForCompletion);
|
|
468
483
|
setPaymentBackStep(options?.paymentBackStep ?? 'form');
|
|
469
|
-
emit({
|
|
470
|
-
type: 'address_completed',
|
|
471
|
-
step: withPayment ? 'payment' : 'done',
|
|
472
|
-
digipin: address.digipin,
|
|
473
|
-
buyerId: auth?.buyerId,
|
|
474
|
-
});
|
|
475
484
|
|
|
476
485
|
if (auth?.sessionToken) {
|
|
477
486
|
notifyAddressCompleted(checkoutConfig, auth.sessionToken, {
|
|
@@ -484,7 +493,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
484
493
|
|
|
485
494
|
if (!options?.skipCreate && !address.addressId) {
|
|
486
495
|
try {
|
|
487
|
-
await createAddress(checkoutConfig, auth.sessionToken, {
|
|
496
|
+
const saved = await createAddress(checkoutConfig, auth.sessionToken, {
|
|
488
497
|
digipin: address.digipin,
|
|
489
498
|
lat: address.lat,
|
|
490
499
|
lng: address.lng,
|
|
@@ -503,22 +512,66 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
503
512
|
address.label === 'other' ? (address.labelText?.trim() || null) : null,
|
|
504
513
|
is_default: false,
|
|
505
514
|
});
|
|
515
|
+
addressForCompletion = { ...addressForCompletion, addressId: saved.id };
|
|
516
|
+
setCompletedAddress(addressForCompletion);
|
|
506
517
|
} catch {
|
|
507
518
|
// Silent
|
|
508
519
|
}
|
|
509
520
|
}
|
|
510
521
|
}
|
|
511
522
|
|
|
523
|
+
if (enableAddressIntelligence && merchantId && supabaseFunctionBaseUrl && codSession) {
|
|
524
|
+
try {
|
|
525
|
+
const risk = await scoreAddressRisk(checkoutConfig, codSession, {
|
|
526
|
+
address_id: addressForCompletion.addressId,
|
|
527
|
+
digipin: addressForCompletion.digipin,
|
|
528
|
+
lat: addressForCompletion.lat,
|
|
529
|
+
lng: addressForCompletion.lng,
|
|
530
|
+
state: addressForCompletion.state,
|
|
531
|
+
district: addressForCompletion.district,
|
|
532
|
+
locality: addressForCompletion.locality,
|
|
533
|
+
pincode: addressForCompletion.pincode,
|
|
534
|
+
delivery_status: addressForCompletion.delivery,
|
|
535
|
+
flat_number: addressForCompletion.flatNumber,
|
|
536
|
+
floor_number: addressForCompletion.floorNumber,
|
|
537
|
+
building_name: addressForCompletion.buildingName,
|
|
538
|
+
street_name: addressForCompletion.streetName,
|
|
539
|
+
});
|
|
540
|
+
setAddressRisk(risk);
|
|
541
|
+
addressForCompletion = { ...addressForCompletion, addressRisk: risk };
|
|
542
|
+
setCompletedAddress(addressForCompletion);
|
|
543
|
+
emit({
|
|
544
|
+
type: 'address_risk_scored',
|
|
545
|
+
step: withPayment ? 'payment' : 'done',
|
|
546
|
+
digipin: addressForCompletion.digipin,
|
|
547
|
+
buyerId: auth?.buyerId,
|
|
548
|
+
addressRiskLevel: risk.level,
|
|
549
|
+
addressRiskScore: risk.score,
|
|
550
|
+
});
|
|
551
|
+
} catch {
|
|
552
|
+
setAddressRisk(null);
|
|
553
|
+
}
|
|
554
|
+
} else {
|
|
555
|
+
setAddressRisk(null);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
emit({
|
|
559
|
+
type: 'address_completed',
|
|
560
|
+
step: withPayment ? 'payment' : 'done',
|
|
561
|
+
digipin: addressForCompletion.digipin,
|
|
562
|
+
buyerId: auth?.buyerId,
|
|
563
|
+
});
|
|
564
|
+
|
|
512
565
|
if (withPayment && codSession) {
|
|
513
566
|
setStep('payment');
|
|
514
567
|
} else if (withPayment && !codSession) {
|
|
515
568
|
onError?.(new Error('enablePayment requires phone/email auth or a codSessionToken prop.'));
|
|
516
569
|
setStep('done');
|
|
517
|
-
onComplete(
|
|
570
|
+
onComplete(addressForCompletion);
|
|
518
571
|
return;
|
|
519
572
|
} else {
|
|
520
573
|
setStep('done');
|
|
521
|
-
onComplete(
|
|
574
|
+
onComplete(addressForCompletion);
|
|
522
575
|
}
|
|
523
576
|
};
|
|
524
577
|
|
|
@@ -622,6 +675,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
622
675
|
setStep(initialStep);
|
|
623
676
|
setConfirmedLocation(null);
|
|
624
677
|
setCompletedAddress(null);
|
|
678
|
+
setAddressRisk(null);
|
|
625
679
|
setVerifyAddress(null);
|
|
626
680
|
};
|
|
627
681
|
|
|
@@ -657,6 +711,44 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
657
711
|
const currentIndex = stepToIndex(step, authMode, withPayment);
|
|
658
712
|
const total = totalSteps(authMode, withPayment);
|
|
659
713
|
|
|
714
|
+
const activeMobileStep: MobileStepItem['id'] =
|
|
715
|
+
step === 'payment'
|
|
716
|
+
? 'payment'
|
|
717
|
+
: step === 'phone' || step === 'otp' || step === 'email' || step === 'email-otp'
|
|
718
|
+
? 'auth'
|
|
719
|
+
: 'address';
|
|
720
|
+
|
|
721
|
+
const authStepLabel =
|
|
722
|
+
mobileStepLabels?.auth ?? (authMode === 'email' ? 'Email' : 'Mobile');
|
|
723
|
+
|
|
724
|
+
const mobileSteps: MobileStepItem[] = [
|
|
725
|
+
...(authMode === 'none'
|
|
726
|
+
? []
|
|
727
|
+
: [{
|
|
728
|
+
id: 'auth' as const,
|
|
729
|
+
label: authStepLabel,
|
|
730
|
+
status: (activeMobileStep === 'auth'
|
|
731
|
+
? 'active'
|
|
732
|
+
: 'complete') as MobileStepStatus,
|
|
733
|
+
}]),
|
|
734
|
+
{
|
|
735
|
+
id: 'address',
|
|
736
|
+
label: mobileStepLabels?.address ?? 'Address',
|
|
737
|
+
status: (activeMobileStep === 'address'
|
|
738
|
+
? 'active'
|
|
739
|
+
: activeMobileStep === 'payment'
|
|
740
|
+
? 'complete'
|
|
741
|
+
: 'pending') as MobileStepStatus,
|
|
742
|
+
},
|
|
743
|
+
...(withPayment
|
|
744
|
+
? [{
|
|
745
|
+
id: 'payment' as const,
|
|
746
|
+
label: mobileStepLabels?.payment ?? 'Pay',
|
|
747
|
+
status: (activeMobileStep === 'payment' ? 'active' : 'pending') as MobileStepStatus,
|
|
748
|
+
}]
|
|
749
|
+
: []),
|
|
750
|
+
];
|
|
751
|
+
|
|
660
752
|
const renderProgress = () => {
|
|
661
753
|
const dots = Array.from({ length: total + 1 }, (_, i) => i);
|
|
662
754
|
return (
|
|
@@ -680,11 +772,37 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
680
772
|
);
|
|
681
773
|
};
|
|
682
774
|
|
|
775
|
+
const renderMobileStepper = () => (
|
|
776
|
+
<div
|
|
777
|
+
className="qr-mobile-stepper"
|
|
778
|
+
role="list"
|
|
779
|
+
aria-label="Checkout progress"
|
|
780
|
+
>
|
|
781
|
+
{mobileSteps.map((item, index) => (
|
|
782
|
+
<React.Fragment key={item.id}>
|
|
783
|
+
<div
|
|
784
|
+
className={`qr-mobile-stepper__item qr-mobile-stepper__item--${item.status}`}
|
|
785
|
+
role="listitem"
|
|
786
|
+
aria-current={item.status === 'active' ? 'step' : undefined}
|
|
787
|
+
>
|
|
788
|
+
<span className="qr-mobile-stepper__mark" aria-hidden="true">
|
|
789
|
+
{item.status === 'complete' ? '✓' : index + 1}
|
|
790
|
+
</span>
|
|
791
|
+
<span className="qr-mobile-stepper__label">{item.label}</span>
|
|
792
|
+
</div>
|
|
793
|
+
{index < mobileSteps.length - 1 ? (
|
|
794
|
+
<span className="qr-mobile-stepper__rail" aria-hidden="true" />
|
|
795
|
+
) : null}
|
|
796
|
+
</React.Fragment>
|
|
797
|
+
))}
|
|
798
|
+
</div>
|
|
799
|
+
);
|
|
800
|
+
|
|
683
801
|
// ── Render ────────────────────────────────────────────────────────────────
|
|
684
802
|
|
|
685
803
|
return (
|
|
686
804
|
<div
|
|
687
|
-
className={`qr-checkout qr-checkout--${theme} ${className}`}
|
|
805
|
+
className={`qr-checkout qr-checkout--${theme} qr-checkout--mobile-${mobilePresentation} ${className}`}
|
|
688
806
|
style={rootStyle}
|
|
689
807
|
data-testid="quantaroute-checkout"
|
|
690
808
|
>
|
|
@@ -719,7 +837,12 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
719
837
|
)}
|
|
720
838
|
<span className="qr-header__title">{title}</span>
|
|
721
839
|
</div>
|
|
722
|
-
|
|
840
|
+
<div className="qr-header__progress-desktop">
|
|
841
|
+
{renderProgress()}
|
|
842
|
+
</div>
|
|
843
|
+
</div>
|
|
844
|
+
<div className="qr-header__progress-mobile">
|
|
845
|
+
{renderMobileStepper()}
|
|
723
846
|
</div>
|
|
724
847
|
{headerBanner ? (
|
|
725
848
|
<div className="qr-header-banner" role="region" aria-label="Merchant message">
|
|
@@ -883,7 +1006,8 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
883
1006
|
sessionId={auth?.sessionId}
|
|
884
1007
|
amountPaise={paymentAmountPaise}
|
|
885
1008
|
enableCod={enableCod}
|
|
886
|
-
codAllowed={codAllowed}
|
|
1009
|
+
codAllowed={codAllowed && !addressRisk?.interventions.includes('hide_cod')}
|
|
1010
|
+
addressRisk={addressRisk}
|
|
887
1011
|
theme={theme}
|
|
888
1012
|
onComplete={handlePaymentComplete}
|
|
889
1013
|
onBack={handleBack}
|
|
@@ -286,6 +286,15 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
|
|
|
286
286
|
map.on('load', () => {
|
|
287
287
|
setMapLoaded(true);
|
|
288
288
|
|
|
289
|
+
// MapLibre compact attribution starts expanded; collapse to icon-only.
|
|
290
|
+
const attribEl = containerRef.current?.querySelector(
|
|
291
|
+
'.maplibregl-ctrl-attrib.maplibregl-compact'
|
|
292
|
+
);
|
|
293
|
+
if (attribEl instanceof HTMLElement) {
|
|
294
|
+
attribEl.classList.remove('maplibregl-compact-show');
|
|
295
|
+
attribEl.setAttribute('open', '');
|
|
296
|
+
}
|
|
297
|
+
|
|
289
298
|
// ── India boundary overlay (legal compliance) ────────────────────────
|
|
290
299
|
// Resolves instantly if the fetch finished before map loaded (typical),
|
|
291
300
|
// or waits the remaining milliseconds if still in-flight.
|
|
@@ -38,6 +38,7 @@ const PaymentStep: React.FC<PaymentStepProps> = ({
|
|
|
38
38
|
amountPaise,
|
|
39
39
|
enableCod = false,
|
|
40
40
|
codAllowed = false,
|
|
41
|
+
addressRisk,
|
|
41
42
|
theme = 'light',
|
|
42
43
|
onComplete,
|
|
43
44
|
onBack,
|
|
@@ -125,6 +126,9 @@ const PaymentStep: React.FC<PaymentStepProps> = ({
|
|
|
125
126
|
};
|
|
126
127
|
|
|
127
128
|
const amountDisplay = `₹${(amountPaise / 100).toLocaleString('en-IN')}`;
|
|
129
|
+
const codBlockedByRisk = addressRisk?.interventions.includes('hide_cod') ?? false;
|
|
130
|
+
const riskTone =
|
|
131
|
+
addressRisk?.level === 'high' ? 'high' : addressRisk?.level === 'medium' ? 'medium' : 'low';
|
|
128
132
|
|
|
129
133
|
return (
|
|
130
134
|
<div className={`qr-payment-step${isDark ? ' qr-payment-step--dark' : ''}`}>
|
|
@@ -140,24 +144,46 @@ const PaymentStep: React.FC<PaymentStepProps> = ({
|
|
|
140
144
|
|
|
141
145
|
{error ? <p className="qr-auth-step__error" role="alert">{error}</p> : null}
|
|
142
146
|
|
|
147
|
+
{addressRisk && addressRisk.level !== 'low' ? (
|
|
148
|
+
<div className={`qr-risk-banner qr-risk-banner--${riskTone}`} role="status">
|
|
149
|
+
<strong>
|
|
150
|
+
{addressRisk.level === 'high' ? 'Address needs extra confirmation' : 'Address confidence check'}
|
|
151
|
+
</strong>
|
|
152
|
+
<span>{addressRisk.reasons[0]}</span>
|
|
153
|
+
{codBlockedByRisk ? (
|
|
154
|
+
<span>Cash on Delivery is disabled for this order. Online payment is still available.</span>
|
|
155
|
+
) : null}
|
|
156
|
+
</div>
|
|
157
|
+
) : null}
|
|
158
|
+
|
|
143
159
|
<button
|
|
144
160
|
type="button"
|
|
145
|
-
className="qr-
|
|
161
|
+
className="qr-payment-option qr-payment-option--primary"
|
|
146
162
|
onClick={handlePrepaid}
|
|
147
163
|
disabled={loading}
|
|
148
164
|
>
|
|
149
|
-
|
|
165
|
+
<span className="qr-payment-option__icon" aria-hidden="true">UPI</span>
|
|
166
|
+
<span className="qr-payment-option__copy">
|
|
167
|
+
<span className="qr-payment-option__title">
|
|
168
|
+
{loading ? 'Processing...' : 'Pay online'}
|
|
169
|
+
</span>
|
|
170
|
+
<span className="qr-payment-option__sub">UPI, cards, wallets</span>
|
|
171
|
+
</span>
|
|
172
|
+
<strong className="qr-payment-option__amount">{amountDisplay}</strong>
|
|
150
173
|
</button>
|
|
151
174
|
|
|
152
|
-
{enableCod && codAllowed ? (
|
|
175
|
+
{enableCod && codAllowed && !codBlockedByRisk ? (
|
|
153
176
|
<button
|
|
154
177
|
type="button"
|
|
155
|
-
className="qr-
|
|
178
|
+
className="qr-payment-option qr-payment-option--secondary"
|
|
156
179
|
onClick={handleCod}
|
|
157
180
|
disabled={loading}
|
|
158
|
-
style={{ marginTop: 8 }}
|
|
159
181
|
>
|
|
160
|
-
|
|
182
|
+
<span className="qr-payment-option__icon" aria-hidden="true">₹</span>
|
|
183
|
+
<span className="qr-payment-option__copy">
|
|
184
|
+
<span className="qr-payment-option__title">Cash on Delivery</span>
|
|
185
|
+
<span className="qr-payment-option__sub">Pay when the order arrives</span>
|
|
186
|
+
</span>
|
|
161
187
|
</button>
|
|
162
188
|
) : null}
|
|
163
189
|
|
package/src/core/checkout-api.ts
CHANGED
|
@@ -386,6 +386,85 @@ export interface ServiceabilityResult {
|
|
|
386
386
|
| 'invalid_response';
|
|
387
387
|
}
|
|
388
388
|
|
|
389
|
+
// ─── Address Intelligence ─────────────────────────────────────────────────────
|
|
390
|
+
|
|
391
|
+
export type AddressRiskLevel = 'low' | 'medium' | 'high';
|
|
392
|
+
|
|
393
|
+
export type AddressIntervention =
|
|
394
|
+
| 'none'
|
|
395
|
+
| 'request_missing_details'
|
|
396
|
+
| 'reconfirm_pin'
|
|
397
|
+
| 'prepaid_nudge'
|
|
398
|
+
| 'hide_cod'
|
|
399
|
+
| 'manual_review'
|
|
400
|
+
| 'delivery_instruction';
|
|
401
|
+
|
|
402
|
+
export type AddressConfidenceState =
|
|
403
|
+
| 'new_source_collected'
|
|
404
|
+
| 'buyer_reconfirmed'
|
|
405
|
+
| 'merchant_successful'
|
|
406
|
+
| 'courier_corrected'
|
|
407
|
+
| 'rto_associated'
|
|
408
|
+
| 'trusted_repeat';
|
|
409
|
+
|
|
410
|
+
export interface AddressRiskSignals {
|
|
411
|
+
merchant_history_records: number;
|
|
412
|
+
buyer_successful_deliveries: number;
|
|
413
|
+
buyer_rto_orders: number;
|
|
414
|
+
pincode_successful_deliveries: number;
|
|
415
|
+
pincode_rto_orders: number;
|
|
416
|
+
digipin_cell_successful_deliveries: number;
|
|
417
|
+
digipin_cell_rto_orders: number;
|
|
418
|
+
repeat_verified_address: boolean;
|
|
419
|
+
imported_address_pending_digipin: boolean;
|
|
420
|
+
cod_requested: boolean;
|
|
421
|
+
address_edit_count: number;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export interface AddressRiskScore {
|
|
425
|
+
level: AddressRiskLevel;
|
|
426
|
+
score: number;
|
|
427
|
+
reasons: string[];
|
|
428
|
+
interventions: AddressIntervention[];
|
|
429
|
+
confidence_state: AddressConfidenceState;
|
|
430
|
+
signals: AddressRiskSignals;
|
|
431
|
+
scored_at: string;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export interface AddressRiskPayload {
|
|
435
|
+
address_id?: string;
|
|
436
|
+
digipin?: string;
|
|
437
|
+
lat?: number;
|
|
438
|
+
lng?: number;
|
|
439
|
+
pincode?: string;
|
|
440
|
+
state?: string;
|
|
441
|
+
district?: string;
|
|
442
|
+
locality?: string;
|
|
443
|
+
delivery_status?: string;
|
|
444
|
+
flat_number?: string;
|
|
445
|
+
floor_number?: string;
|
|
446
|
+
building_name?: string;
|
|
447
|
+
street_name?: string;
|
|
448
|
+
payment_method?: string;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export async function scoreAddressRisk(
|
|
452
|
+
config: CheckoutApiConfig,
|
|
453
|
+
sessionToken: string,
|
|
454
|
+
payload: AddressRiskPayload
|
|
455
|
+
): Promise<AddressRiskScore> {
|
|
456
|
+
const res = await fetch(`${config.functionBaseUrl}/checkout-addresses`, {
|
|
457
|
+
method: 'POST',
|
|
458
|
+
headers: addressHeaders(sessionToken),
|
|
459
|
+
body: JSON.stringify({ action: 'address_risk', data: payload }),
|
|
460
|
+
});
|
|
461
|
+
const data = await res.json().catch(() => ({}));
|
|
462
|
+
if (!res.ok || !data.success) {
|
|
463
|
+
throw new Error(data.error ?? 'Failed to score address risk.');
|
|
464
|
+
}
|
|
465
|
+
return data.data as AddressRiskScore;
|
|
466
|
+
}
|
|
467
|
+
|
|
389
468
|
/**
|
|
390
469
|
* Check merchant courier serviceability for a pincode.
|
|
391
470
|
* Uses the merchant's configured webhook on checkout.merchants and fails open.
|
package/src/core/types.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { UtmParams } from './utm';
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
AddressRiskScore,
|
|
5
|
+
CheckoutApiConfig,
|
|
6
|
+
ServiceabilityResult,
|
|
7
|
+
SessionContextPayload,
|
|
8
|
+
} from './checkout-api';
|
|
4
9
|
|
|
5
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
11
|
type AnyStyle = any; // CSSProperties on web · StyleProp<ViewStyle> on native
|
|
@@ -95,6 +100,8 @@ export interface CompleteAddress {
|
|
|
95
100
|
labelText?: string;
|
|
96
101
|
/** Set when the buyer re-selected an existing saved row (skip createAddress). */
|
|
97
102
|
addressId?: string;
|
|
103
|
+
/** Explainable checkout-time address discrepancy risk, when enabled. */
|
|
104
|
+
addressRisk?: AddressRiskScore;
|
|
98
105
|
}
|
|
99
106
|
|
|
100
107
|
/** Imperative hooks for host pages (e.g. Shopify pre-checkout shell). */
|
|
@@ -104,6 +111,14 @@ export interface CheckoutWidgetController {
|
|
|
104
111
|
getStep: () => string;
|
|
105
112
|
}
|
|
106
113
|
|
|
114
|
+
export type CheckoutMobilePresentation = 'auto' | 'sheet' | 'card';
|
|
115
|
+
|
|
116
|
+
export interface CheckoutMobileStepLabels {
|
|
117
|
+
auth?: string;
|
|
118
|
+
address?: string;
|
|
119
|
+
payment?: string;
|
|
120
|
+
}
|
|
121
|
+
|
|
107
122
|
// ─── Checkout event (client-side analytics hook) ─────────────────────────────
|
|
108
123
|
|
|
109
124
|
/** All step-transition event types emitted by the widget. */
|
|
@@ -125,6 +140,7 @@ export type CheckoutEventType =
|
|
|
125
140
|
| 'location_confirmed'
|
|
126
141
|
| 'form_step_viewed'
|
|
127
142
|
| 'address_completed'
|
|
143
|
+
| 'address_risk_scored'
|
|
128
144
|
| 'widget_reset'
|
|
129
145
|
| 'payment_step_viewed'
|
|
130
146
|
| 'payment_method_selected'
|
|
@@ -159,6 +175,10 @@ export interface CheckoutEvent {
|
|
|
159
175
|
experimentVariant?: string;
|
|
160
176
|
/** DigiPin of the confirmed location. Available after `location_confirmed` and `address_completed`. */
|
|
161
177
|
digipin?: string;
|
|
178
|
+
/** Address risk level when `address_risk_scored` fires. */
|
|
179
|
+
addressRiskLevel?: AddressRiskScore['level'];
|
|
180
|
+
/** Address risk score (0-100) when address intelligence is enabled. */
|
|
181
|
+
addressRiskScore?: number;
|
|
162
182
|
/** ISO timestamp of when the event fired. */
|
|
163
183
|
timestamp: string;
|
|
164
184
|
}
|
|
@@ -263,6 +283,13 @@ export interface CheckoutWidgetProps {
|
|
|
263
283
|
mapHeight?: string | number;
|
|
264
284
|
/** Widget header title. Defaults to 'Add Delivery Address'. */
|
|
265
285
|
title?: string;
|
|
286
|
+
/**
|
|
287
|
+
* Mobile visual treatment. `auto` applies the improved mobile layout below 480px,
|
|
288
|
+
* `sheet` is for storefront drawers/modals, and `card` preserves the compact card feel.
|
|
289
|
+
*/
|
|
290
|
+
mobilePresentation?: CheckoutMobilePresentation;
|
|
291
|
+
/** Override the compact mobile step labels (e.g. Mobile / Address / Pay). */
|
|
292
|
+
mobileStepLabels?: CheckoutMobileStepLabels;
|
|
266
293
|
/**
|
|
267
294
|
* URL to an India boundary GeoJSON file (FeatureCollection).
|
|
268
295
|
* When provided, a thin grey outline is drawn on the map for legal compliance.
|
|
@@ -315,6 +342,11 @@ export interface CheckoutWidgetProps {
|
|
|
315
342
|
* Requires `merchantId`, `supabaseFunctionBaseUrl`, and an authenticated checkout session.
|
|
316
343
|
*/
|
|
317
344
|
enableServiceabilityCheck?: boolean;
|
|
345
|
+
/**
|
|
346
|
+
* Score address-discrepancy-led RTO risk after address completion.
|
|
347
|
+
* Requires `merchantId`, `supabaseFunctionBaseUrl`, and phone/email auth or `codSessionToken`.
|
|
348
|
+
*/
|
|
349
|
+
enableAddressIntelligence?: boolean;
|
|
318
350
|
/**
|
|
319
351
|
* Opt-in fallback banner for India Post "Non Delivery" pincodes.
|
|
320
352
|
* Defaults off because courier partners may still deliver.
|
|
@@ -452,6 +484,7 @@ export interface PaymentStepProps {
|
|
|
452
484
|
amountPaise: number;
|
|
453
485
|
enableCod?: boolean;
|
|
454
486
|
codAllowed?: boolean;
|
|
487
|
+
addressRisk?: AddressRiskScore | null;
|
|
455
488
|
theme?: 'light' | 'dark';
|
|
456
489
|
onComplete: (result: {
|
|
457
490
|
paymentMethod: string;
|
package/src/index.ts
CHANGED
|
@@ -74,6 +74,7 @@ export {
|
|
|
74
74
|
selectAddress,
|
|
75
75
|
verifyDigipin,
|
|
76
76
|
checkCodEligibility,
|
|
77
|
+
scoreAddressRisk,
|
|
77
78
|
checkServiceability,
|
|
78
79
|
notifyAddressCompleted,
|
|
79
80
|
logFunnelEvent,
|
|
@@ -93,6 +94,11 @@ export type {
|
|
|
93
94
|
SavedAddressPayload,
|
|
94
95
|
VerifyDigipinPayload,
|
|
95
96
|
CodEligibilityResult,
|
|
97
|
+
AddressRiskScore,
|
|
98
|
+
AddressRiskPayload,
|
|
99
|
+
AddressRiskLevel,
|
|
100
|
+
AddressIntervention,
|
|
101
|
+
AddressConfidenceState,
|
|
96
102
|
ServiceabilityResult,
|
|
97
103
|
SessionContextPayload,
|
|
98
104
|
FunnelEventPayload,
|
|
@@ -120,6 +126,8 @@ export type { UtmParams } from './core/utm';
|
|
|
120
126
|
export { getWebDeviceContext, detectDeviceType, detectPlatform } from './core/device';
|
|
121
127
|
export type {
|
|
122
128
|
CheckoutWidgetProps,
|
|
129
|
+
CheckoutMobilePresentation,
|
|
130
|
+
CheckoutMobileStepLabels,
|
|
123
131
|
MapPinSelectorProps,
|
|
124
132
|
AddressFormProps,
|
|
125
133
|
AddressFormInitialValues,
|