@quantaroute/checkout 1.7.0 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/dist/lib/index.d.ts +122 -1
- package/dist/lib/quantaroute-checkout.es.js +201 -183
- package/dist/lib/quantaroute-checkout.umd.js +138 -120
- package/dist/style.css +1 -1
- package/package.json +6 -6
- package/src/components/CheckoutWidget.tsx +62 -11
- package/src/components/MapPinSelector.tsx +251 -167
- package/src/components/PaymentStep.tsx +17 -1
- package/src/core/checkout-api.ts +79 -0
- package/src/core/map-runtime.ts +100 -0
- package/src/core/types.ts +40 -1
- package/src/index.ts +19 -0
- package/src/styles/checkout.css +47 -28
|
@@ -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';
|
|
@@ -209,6 +211,8 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
209
211
|
mobileStepLabels,
|
|
210
212
|
indiaBoundaryUrl,
|
|
211
213
|
enableSearch = true,
|
|
214
|
+
mapStyle,
|
|
215
|
+
embedMode,
|
|
212
216
|
enablePhoneAuth = false,
|
|
213
217
|
merchantId = '',
|
|
214
218
|
supabaseFunctionBaseUrl = '',
|
|
@@ -218,6 +222,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
218
222
|
onCheckoutEvent,
|
|
219
223
|
enableCod = false,
|
|
220
224
|
enableServiceabilityCheck = false,
|
|
225
|
+
enableAddressIntelligence = false,
|
|
221
226
|
showIndiaPostDeliveryWarning = false,
|
|
222
227
|
serviceabilityBlockCheckout,
|
|
223
228
|
codCartTotalPaise,
|
|
@@ -246,6 +251,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
246
251
|
const [emailCodeReused, setEmailCodeReused] = useState(false);
|
|
247
252
|
const [codAllowed, setCodAllowed] = useState(false);
|
|
248
253
|
const [sessionOffer, setSessionOffer] = useState<SessionOffer | null>(null);
|
|
254
|
+
const [addressRisk, setAddressRisk] = useState<AddressRiskScore | null>(null);
|
|
249
255
|
const [paymentMethod, setPaymentMethod] = useState<string | null>(null);
|
|
250
256
|
const [verifyAddress, setVerifyAddress] = useState<SavedAddress | null>(null);
|
|
251
257
|
const [paymentBackStep, setPaymentBackStep] = useState<Step>('form');
|
|
@@ -474,14 +480,9 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
474
480
|
address: CompleteAddress,
|
|
475
481
|
options?: { skipCreate?: boolean; paymentBackStep?: Step }
|
|
476
482
|
) => {
|
|
477
|
-
|
|
483
|
+
let addressForCompletion: CompleteAddress = address;
|
|
484
|
+
setCompletedAddress(addressForCompletion);
|
|
478
485
|
setPaymentBackStep(options?.paymentBackStep ?? 'form');
|
|
479
|
-
emit({
|
|
480
|
-
type: 'address_completed',
|
|
481
|
-
step: withPayment ? 'payment' : 'done',
|
|
482
|
-
digipin: address.digipin,
|
|
483
|
-
buyerId: auth?.buyerId,
|
|
484
|
-
});
|
|
485
486
|
|
|
486
487
|
if (auth?.sessionToken) {
|
|
487
488
|
notifyAddressCompleted(checkoutConfig, auth.sessionToken, {
|
|
@@ -494,7 +495,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
494
495
|
|
|
495
496
|
if (!options?.skipCreate && !address.addressId) {
|
|
496
497
|
try {
|
|
497
|
-
await createAddress(checkoutConfig, auth.sessionToken, {
|
|
498
|
+
const saved = await createAddress(checkoutConfig, auth.sessionToken, {
|
|
498
499
|
digipin: address.digipin,
|
|
499
500
|
lat: address.lat,
|
|
500
501
|
lng: address.lng,
|
|
@@ -513,22 +514,66 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
513
514
|
address.label === 'other' ? (address.labelText?.trim() || null) : null,
|
|
514
515
|
is_default: false,
|
|
515
516
|
});
|
|
517
|
+
addressForCompletion = { ...addressForCompletion, addressId: saved.id };
|
|
518
|
+
setCompletedAddress(addressForCompletion);
|
|
516
519
|
} catch {
|
|
517
520
|
// Silent
|
|
518
521
|
}
|
|
519
522
|
}
|
|
520
523
|
}
|
|
521
524
|
|
|
525
|
+
if (enableAddressIntelligence && merchantId && supabaseFunctionBaseUrl && codSession) {
|
|
526
|
+
try {
|
|
527
|
+
const risk = await scoreAddressRisk(checkoutConfig, codSession, {
|
|
528
|
+
address_id: addressForCompletion.addressId,
|
|
529
|
+
digipin: addressForCompletion.digipin,
|
|
530
|
+
lat: addressForCompletion.lat,
|
|
531
|
+
lng: addressForCompletion.lng,
|
|
532
|
+
state: addressForCompletion.state,
|
|
533
|
+
district: addressForCompletion.district,
|
|
534
|
+
locality: addressForCompletion.locality,
|
|
535
|
+
pincode: addressForCompletion.pincode,
|
|
536
|
+
delivery_status: addressForCompletion.delivery,
|
|
537
|
+
flat_number: addressForCompletion.flatNumber,
|
|
538
|
+
floor_number: addressForCompletion.floorNumber,
|
|
539
|
+
building_name: addressForCompletion.buildingName,
|
|
540
|
+
street_name: addressForCompletion.streetName,
|
|
541
|
+
});
|
|
542
|
+
setAddressRisk(risk);
|
|
543
|
+
addressForCompletion = { ...addressForCompletion, addressRisk: risk };
|
|
544
|
+
setCompletedAddress(addressForCompletion);
|
|
545
|
+
emit({
|
|
546
|
+
type: 'address_risk_scored',
|
|
547
|
+
step: withPayment ? 'payment' : 'done',
|
|
548
|
+
digipin: addressForCompletion.digipin,
|
|
549
|
+
buyerId: auth?.buyerId,
|
|
550
|
+
addressRiskLevel: risk.level,
|
|
551
|
+
addressRiskScore: risk.score,
|
|
552
|
+
});
|
|
553
|
+
} catch {
|
|
554
|
+
setAddressRisk(null);
|
|
555
|
+
}
|
|
556
|
+
} else {
|
|
557
|
+
setAddressRisk(null);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
emit({
|
|
561
|
+
type: 'address_completed',
|
|
562
|
+
step: withPayment ? 'payment' : 'done',
|
|
563
|
+
digipin: addressForCompletion.digipin,
|
|
564
|
+
buyerId: auth?.buyerId,
|
|
565
|
+
});
|
|
566
|
+
|
|
522
567
|
if (withPayment && codSession) {
|
|
523
568
|
setStep('payment');
|
|
524
569
|
} else if (withPayment && !codSession) {
|
|
525
570
|
onError?.(new Error('enablePayment requires phone/email auth or a codSessionToken prop.'));
|
|
526
571
|
setStep('done');
|
|
527
|
-
onComplete(
|
|
572
|
+
onComplete(addressForCompletion);
|
|
528
573
|
return;
|
|
529
574
|
} else {
|
|
530
575
|
setStep('done');
|
|
531
|
-
onComplete(
|
|
576
|
+
onComplete(addressForCompletion);
|
|
532
577
|
}
|
|
533
578
|
};
|
|
534
579
|
|
|
@@ -632,6 +677,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
632
677
|
setStep(initialStep);
|
|
633
678
|
setConfirmedLocation(null);
|
|
634
679
|
setCompletedAddress(null);
|
|
680
|
+
setAddressRisk(null);
|
|
635
681
|
setVerifyAddress(null);
|
|
636
682
|
};
|
|
637
683
|
|
|
@@ -898,6 +944,8 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
898
944
|
apiKey={apiKey}
|
|
899
945
|
apiBaseUrl={apiBaseUrl}
|
|
900
946
|
brandColor={brandColor}
|
|
947
|
+
mapStyle={mapStyle}
|
|
948
|
+
embedMode={embedMode}
|
|
901
949
|
/>
|
|
902
950
|
</>
|
|
903
951
|
)}
|
|
@@ -915,6 +963,8 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
915
963
|
apiKey={apiKey}
|
|
916
964
|
apiBaseUrl={apiBaseUrl}
|
|
917
965
|
brandColor={brandColor}
|
|
966
|
+
mapStyle={mapStyle}
|
|
967
|
+
embedMode={embedMode}
|
|
918
968
|
/>
|
|
919
969
|
)}
|
|
920
970
|
|
|
@@ -962,7 +1012,8 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
962
1012
|
sessionId={auth?.sessionId}
|
|
963
1013
|
amountPaise={paymentAmountPaise}
|
|
964
1014
|
enableCod={enableCod}
|
|
965
|
-
codAllowed={codAllowed}
|
|
1015
|
+
codAllowed={codAllowed && !addressRisk?.interventions.includes('hide_cod')}
|
|
1016
|
+
addressRisk={addressRisk}
|
|
966
1017
|
theme={theme}
|
|
967
1018
|
onComplete={handlePaymentComplete}
|
|
968
1019
|
onBack={handleBack}
|