@quantaroute/checkout 1.4.5 → 1.6.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.
- package/CHANGELOG.md +40 -0
- package/README.md +170 -132
- package/dist/lib/index.d.ts +61 -5
- package/dist/lib/quantaroute-checkout.es.js +137 -117
- package/dist/lib/quantaroute-checkout.umd.js +133 -113
- package/dist/style.css +1 -1
- package/package.json +2 -1
- package/src/components/AddressForm.native.tsx +11 -10
- package/src/components/AddressForm.tsx +41 -19
- package/src/components/CheckoutWidget.tsx +203 -56
- package/src/components/PaymentStep.tsx +11 -2
- package/src/components/SavedAddressStep.tsx +8 -4
- package/src/core/checkout-api.ts +64 -5
- package/src/core/locality.ts +74 -0
- package/src/core/types.ts +35 -2
- package/src/index.ts +4 -0
- package/src/styles/checkout.css +32 -0
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
type AddressComponents,
|
|
8
8
|
} from '../core/api';
|
|
9
9
|
import { checkServiceability, type ServiceabilityResult } from '../core/checkout-api';
|
|
10
|
+
import { processLocalityLookup } from '../core/locality';
|
|
10
11
|
import type {
|
|
11
12
|
AddressFormProps,
|
|
12
13
|
AddressLabel,
|
|
@@ -32,6 +33,7 @@ type FormState =
|
|
|
32
33
|
status: 'ready';
|
|
33
34
|
adminInfo: AdministrativeInfo;
|
|
34
35
|
alternatives: LocationAlternative[];
|
|
36
|
+
localityOptions: string[];
|
|
35
37
|
selectedLocality: string; // Selected locality name (from adminInfo or alternatives)
|
|
36
38
|
selectedLabel: AddressLabel;
|
|
37
39
|
labelText: string;
|
|
@@ -51,6 +53,7 @@ type FormAction =
|
|
|
51
53
|
addressComponents: AddressComponents;
|
|
52
54
|
pincodeHasDelivery: boolean;
|
|
53
55
|
serviceabilityResult: ServiceabilityResult | null;
|
|
56
|
+
initialValues?: import('../core/types').AddressFormInitialValues;
|
|
54
57
|
}
|
|
55
58
|
| { type: 'LOAD_ERROR'; message: string }
|
|
56
59
|
| { type: 'SET_FIELD'; key: keyof ManualFields; value: string }
|
|
@@ -104,17 +107,37 @@ function reducer(state: FormState, action: FormAction): FormState {
|
|
|
104
107
|
case 'LOAD_START':
|
|
105
108
|
return { status: 'loading' };
|
|
106
109
|
case 'LOAD_SUCCESS': {
|
|
107
|
-
// Pre-fill fields from addressComponents
|
|
110
|
+
// Pre-fill fields from addressComponents, then override with initialValues
|
|
108
111
|
const preFilled = parseAddressComponents(action.addressComponents);
|
|
109
|
-
|
|
112
|
+
const iv = action.initialValues;
|
|
113
|
+
const fields: ManualFields = {
|
|
114
|
+
...INITIAL_FIELDS,
|
|
115
|
+
...preFilled,
|
|
116
|
+
...(iv?.flatNumber !== undefined ? { flatNumber: iv.flatNumber } : {}),
|
|
117
|
+
...(iv?.floorNumber !== undefined ? { floorNumber: iv.floorNumber } : {}),
|
|
118
|
+
...(iv?.buildingName !== undefined ? { buildingName: iv.buildingName } : {}),
|
|
119
|
+
...(iv?.streetName !== undefined ? { streetName: iv.streetName } : {}),
|
|
120
|
+
};
|
|
121
|
+
const processed = processLocalityLookup(action.adminInfo, action.alternatives || []);
|
|
122
|
+
let localityOptions = processed.localityOptions;
|
|
123
|
+
let selectedLocality = processed.selectedLocality;
|
|
124
|
+
if (iv?.locality?.trim()) {
|
|
125
|
+
const savedLocality = iv.locality.trim();
|
|
126
|
+
if (!localityOptions.includes(savedLocality)) {
|
|
127
|
+
localityOptions = [savedLocality, ...localityOptions];
|
|
128
|
+
}
|
|
129
|
+
selectedLocality = savedLocality;
|
|
130
|
+
}
|
|
131
|
+
const selectedLabel = iv?.label ?? 'home';
|
|
110
132
|
return {
|
|
111
133
|
status: 'ready',
|
|
112
|
-
adminInfo:
|
|
113
|
-
alternatives:
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
134
|
+
adminInfo: processed.adminInfo,
|
|
135
|
+
alternatives: processed.alternatives,
|
|
136
|
+
localityOptions,
|
|
137
|
+
selectedLocality,
|
|
138
|
+
selectedLabel,
|
|
139
|
+
labelText: selectedLabel === 'other' ? (iv?.labelText ?? '') : '',
|
|
140
|
+
fields,
|
|
118
141
|
submitting: false,
|
|
119
142
|
pincodeHasDelivery: action.pincodeHasDelivery,
|
|
120
143
|
serviceabilityResult: action.serviceabilityResult,
|
|
@@ -166,6 +189,8 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
166
189
|
showIndiaPostDeliveryWarning = false,
|
|
167
190
|
serviceabilityBlockCheckout,
|
|
168
191
|
onServiceabilityResult,
|
|
192
|
+
initialValues,
|
|
193
|
+
submitLabel = 'Save Address',
|
|
169
194
|
}) => {
|
|
170
195
|
const [state, dispatch] = useReducer(reducer, { status: 'loading' });
|
|
171
196
|
|
|
@@ -234,6 +259,7 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
234
259
|
addressComponents: reverseRes.data.addressComponents,
|
|
235
260
|
pincodeHasDelivery: hasDelivery,
|
|
236
261
|
serviceabilityResult,
|
|
262
|
+
initialValues,
|
|
237
263
|
});
|
|
238
264
|
} catch (err) {
|
|
239
265
|
const msg = err instanceof Error ? err.message : 'Failed to fetch address data.';
|
|
@@ -251,6 +277,7 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
251
277
|
serviceabilitySessionToken,
|
|
252
278
|
enableServiceabilityCheck,
|
|
253
279
|
onServiceabilityResult,
|
|
280
|
+
initialValues,
|
|
254
281
|
]);
|
|
255
282
|
|
|
256
283
|
useEffect(() => {
|
|
@@ -421,24 +448,19 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
421
448
|
<span className="qr-auto-row__value">{state.adminInfo.district}</span>
|
|
422
449
|
</div>
|
|
423
450
|
|
|
424
|
-
{/* Locality - show dropdown if
|
|
451
|
+
{/* Locality - show dropdown if multiple unique localities exist */}
|
|
425
452
|
<div className="qr-auto-row qr-auto-row--full">
|
|
426
453
|
<span className="qr-auto-row__label">Locality</span>
|
|
427
|
-
{state.
|
|
454
|
+
{state.localityOptions.length > 1 ? (
|
|
428
455
|
<select
|
|
429
456
|
className="qr-auto-row__select"
|
|
430
457
|
value={state.selectedLocality}
|
|
431
458
|
onChange={(e) => dispatch({ type: 'SET_LOCALITY', locality: e.target.value })}
|
|
432
459
|
aria-label="Select locality"
|
|
433
460
|
>
|
|
434
|
-
{
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
</option>
|
|
438
|
-
{/* Alternatives */}
|
|
439
|
-
{state.alternatives.map((alt, idx) => (
|
|
440
|
-
<option key={idx} value={alt.name}>
|
|
441
|
-
{alt.name}
|
|
461
|
+
{state.localityOptions.map((name) => (
|
|
462
|
+
<option key={name} value={name}>
|
|
463
|
+
{name}
|
|
442
464
|
</option>
|
|
443
465
|
))}
|
|
444
466
|
</select>
|
|
@@ -676,7 +698,7 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
676
698
|
</>
|
|
677
699
|
) : (
|
|
678
700
|
<>
|
|
679
|
-
|
|
701
|
+
{submitLabel}
|
|
680
702
|
<svg
|
|
681
703
|
aria-hidden="true"
|
|
682
704
|
viewBox="0 0 24 24"
|
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
logFunnelEvent,
|
|
12
12
|
notifySessionAbandoned,
|
|
13
13
|
fetchSessionOffer,
|
|
14
|
+
selectAddress,
|
|
15
|
+
verifyDigipin,
|
|
14
16
|
type SessionOffer,
|
|
15
17
|
} from '../core/checkout-api';
|
|
16
18
|
import type { CheckoutEvent, CheckoutWidgetProps, CompleteAddress } from '../core/types';
|
|
@@ -28,7 +30,17 @@ import '../styles/checkout.css';
|
|
|
28
30
|
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
29
31
|
|
|
30
32
|
/** Full step machine — auth gate is phone, email, or none */
|
|
31
|
-
type Step =
|
|
33
|
+
type Step =
|
|
34
|
+
| 'phone'
|
|
35
|
+
| 'otp'
|
|
36
|
+
| 'email'
|
|
37
|
+
| 'email-otp'
|
|
38
|
+
| 'saved'
|
|
39
|
+
| 'verify-address'
|
|
40
|
+
| 'map'
|
|
41
|
+
| 'form'
|
|
42
|
+
| 'payment'
|
|
43
|
+
| 'done';
|
|
32
44
|
|
|
33
45
|
interface ConfirmedLocation {
|
|
34
46
|
lat: number;
|
|
@@ -84,13 +96,14 @@ const SuccessScreen: React.FC<SuccessScreenProps> = ({ address, onEditAddress })
|
|
|
84
96
|
type AuthMode = 'phone' | 'email' | 'none';
|
|
85
97
|
|
|
86
98
|
function stepToIndex(step: Step, mode: AuthMode, withPayment: boolean): number {
|
|
99
|
+
const normalizedStep = step === 'verify-address' ? 'map' : step;
|
|
87
100
|
if (mode === 'none') {
|
|
88
101
|
if (withPayment) {
|
|
89
102
|
const order: Step[] = ['map', 'form', 'payment', 'done'];
|
|
90
|
-
const idx = order.indexOf(
|
|
103
|
+
const idx = order.indexOf(normalizedStep);
|
|
91
104
|
return idx === -1 ? 0 : idx;
|
|
92
105
|
}
|
|
93
|
-
return
|
|
106
|
+
return normalizedStep === 'map' ? 0 : normalizedStep === 'form' ? 1 : 2;
|
|
94
107
|
}
|
|
95
108
|
const order: Step[] =
|
|
96
109
|
mode === 'email'
|
|
@@ -100,7 +113,7 @@ function stepToIndex(step: Step, mode: AuthMode, withPayment: boolean): number {
|
|
|
100
113
|
: withPayment
|
|
101
114
|
? ['phone', 'otp', 'saved', 'map', 'form', 'payment', 'done']
|
|
102
115
|
: ['phone', 'otp', 'saved', 'map', 'form', 'done'];
|
|
103
|
-
const idx = order.indexOf(
|
|
116
|
+
const idx = order.indexOf(normalizedStep);
|
|
104
117
|
return idx === -1 ? 0 : idx;
|
|
105
118
|
}
|
|
106
119
|
|
|
@@ -125,6 +138,41 @@ function mergeBrandRootStyle(
|
|
|
125
138
|
return base ? { ...base, ...vars } : vars;
|
|
126
139
|
}
|
|
127
140
|
|
|
141
|
+
function savedAddressToComplete(saved: SavedAddress): CompleteAddress {
|
|
142
|
+
return {
|
|
143
|
+
digipin: saved.digipin!,
|
|
144
|
+
lat: saved.lat!,
|
|
145
|
+
lng: saved.lng!,
|
|
146
|
+
state: saved.state,
|
|
147
|
+
district: saved.district,
|
|
148
|
+
division: '',
|
|
149
|
+
locality: saved.locality,
|
|
150
|
+
pincode: saved.pincode,
|
|
151
|
+
delivery: saved.delivery_status,
|
|
152
|
+
country: 'India',
|
|
153
|
+
flatNumber: saved.flat_number,
|
|
154
|
+
floorNumber: saved.floor_number,
|
|
155
|
+
buildingName: saved.building_name,
|
|
156
|
+
streetName: saved.street_name,
|
|
157
|
+
formattedAddress: [
|
|
158
|
+
saved.flat_number,
|
|
159
|
+
saved.building_name,
|
|
160
|
+
saved.street_name,
|
|
161
|
+
saved.locality,
|
|
162
|
+
saved.district,
|
|
163
|
+
saved.state,
|
|
164
|
+
saved.pincode,
|
|
165
|
+
]
|
|
166
|
+
.filter(Boolean)
|
|
167
|
+
.join(', '),
|
|
168
|
+
label: (saved.label === 'work' || saved.label === 'other'
|
|
169
|
+
? saved.label
|
|
170
|
+
: 'home') as CompleteAddress['label'],
|
|
171
|
+
labelText: saved.label_text?.trim() || undefined,
|
|
172
|
+
addressId: saved.id,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
128
176
|
// ─── Main Widget ──────────────────────────────────────────────────────────────
|
|
129
177
|
|
|
130
178
|
/**
|
|
@@ -174,6 +222,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
174
222
|
prepaidNudgeCopy,
|
|
175
223
|
prepaidNudgeCtaUrl,
|
|
176
224
|
registerController,
|
|
225
|
+
orderConfirmationUrl,
|
|
177
226
|
}) => {
|
|
178
227
|
const authMode: AuthMode = enablePhoneAuth ? 'phone' : enableEmailAuth ? 'email' : 'none';
|
|
179
228
|
const initialStep: Step = authMode === 'phone' ? 'phone' : authMode === 'email' ? 'email' : 'map';
|
|
@@ -188,6 +237,8 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
188
237
|
const [codAllowed, setCodAllowed] = useState(false);
|
|
189
238
|
const [sessionOffer, setSessionOffer] = useState<SessionOffer | null>(null);
|
|
190
239
|
const [paymentMethod, setPaymentMethod] = useState<string | null>(null);
|
|
240
|
+
const [verifyAddress, setVerifyAddress] = useState<SavedAddress | null>(null);
|
|
241
|
+
const [paymentBackStep, setPaymentBackStep] = useState<Step>('form');
|
|
191
242
|
const stepRef = useRef(step);
|
|
192
243
|
|
|
193
244
|
const utmParams = useMemo(
|
|
@@ -343,58 +394,60 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
343
394
|
|
|
344
395
|
// ── Saved addresses callbacks ─────────────────────────────────────────────
|
|
345
396
|
|
|
346
|
-
const handleSelectSavedAddress = (saved: SavedAddress) => {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
397
|
+
const handleSelectSavedAddress = async (saved: SavedAddress) => {
|
|
398
|
+
if (!auth?.sessionToken) return;
|
|
399
|
+
|
|
400
|
+
try {
|
|
401
|
+
await selectAddress(checkoutConfig, auth.sessionToken, saved.id);
|
|
402
|
+
} catch (err: unknown) {
|
|
403
|
+
onError?.(err instanceof Error ? err : new Error('Failed to select address.'));
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (!saved.digipin) {
|
|
408
|
+
setVerifyAddress(saved);
|
|
409
|
+
emit({
|
|
410
|
+
type: 'saved_address_selected',
|
|
411
|
+
step: 'verify-address',
|
|
412
|
+
buyerId: auth.buyerId,
|
|
413
|
+
});
|
|
414
|
+
setStep('verify-address');
|
|
415
|
+
return;
|
|
356
416
|
}
|
|
357
|
-
|
|
417
|
+
|
|
418
|
+
emit({
|
|
419
|
+
type: 'saved_address_selected',
|
|
420
|
+
step: withPayment ? 'payment' : 'done',
|
|
421
|
+
buyerId: auth.buyerId,
|
|
422
|
+
digipin: saved.digipin,
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
notifyAddressCompleted(checkoutConfig, auth.sessionToken, {
|
|
426
|
+
pincode: saved.pincode,
|
|
358
427
|
digipin: saved.digipin,
|
|
359
|
-
lat: saved.lat,
|
|
360
|
-
lng: saved.lng,
|
|
361
428
|
state: saved.state,
|
|
362
429
|
district: saved.district,
|
|
363
|
-
division: '',
|
|
364
430
|
locality: saved.locality,
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
flatNumber: saved.flat_number,
|
|
369
|
-
floorNumber: saved.floor_number,
|
|
370
|
-
buildingName: saved.building_name,
|
|
371
|
-
streetName: saved.street_name,
|
|
372
|
-
formattedAddress: [
|
|
373
|
-
saved.flat_number,
|
|
374
|
-
saved.building_name,
|
|
375
|
-
saved.street_name,
|
|
376
|
-
saved.locality,
|
|
377
|
-
saved.district,
|
|
378
|
-
saved.state,
|
|
379
|
-
saved.pincode,
|
|
380
|
-
]
|
|
381
|
-
.filter(Boolean)
|
|
382
|
-
.join(', '),
|
|
383
|
-
label: (saved.label === 'work' || saved.label === 'other'
|
|
384
|
-
? saved.label
|
|
385
|
-
: 'home') as CompleteAddress['label'],
|
|
386
|
-
labelText: saved.label_text?.trim() || undefined,
|
|
387
|
-
addressId: saved.id,
|
|
388
|
-
};
|
|
389
|
-
void finishAddress(complete);
|
|
431
|
+
}).catch(() => {/* silent */});
|
|
432
|
+
|
|
433
|
+
await finishAddress(savedAddressToComplete(saved), { skipCreate: true, paymentBackStep: 'saved' });
|
|
390
434
|
};
|
|
391
435
|
|
|
392
|
-
const handlePaymentComplete = (
|
|
393
|
-
|
|
394
|
-
|
|
436
|
+
const handlePaymentComplete = ({ paymentMethod, razorpayOrderId, razorpayPaymentId }: {
|
|
437
|
+
paymentMethod: string;
|
|
438
|
+
razorpayOrderId?: string;
|
|
439
|
+
razorpayPaymentId?: string;
|
|
440
|
+
}) => {
|
|
441
|
+
setPaymentMethod(paymentMethod);
|
|
442
|
+
emit({ type: 'payment_method_selected', step: 'done', paymentMethod });
|
|
395
443
|
setStep('done');
|
|
396
444
|
if (completedAddress) onComplete(completedAddress);
|
|
397
|
-
onPaymentComplete?.({
|
|
445
|
+
onPaymentComplete?.({
|
|
446
|
+
paymentMethod,
|
|
447
|
+
sessionId: auth?.sessionId,
|
|
448
|
+
razorpayOrderId,
|
|
449
|
+
razorpayPaymentId,
|
|
450
|
+
});
|
|
398
451
|
};
|
|
399
452
|
|
|
400
453
|
// ── Map step callbacks ────────────────────────────────────────────────────
|
|
@@ -407,9 +460,18 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
407
460
|
|
|
408
461
|
// ── Form step callbacks ───────────────────────────────────────────────────
|
|
409
462
|
|
|
410
|
-
const finishAddress = async (
|
|
463
|
+
const finishAddress = async (
|
|
464
|
+
address: CompleteAddress,
|
|
465
|
+
options?: { skipCreate?: boolean; paymentBackStep?: Step }
|
|
466
|
+
) => {
|
|
411
467
|
setCompletedAddress(address);
|
|
412
|
-
|
|
468
|
+
setPaymentBackStep(options?.paymentBackStep ?? 'form');
|
|
469
|
+
emit({
|
|
470
|
+
type: 'address_completed',
|
|
471
|
+
step: withPayment ? 'payment' : 'done',
|
|
472
|
+
digipin: address.digipin,
|
|
473
|
+
buyerId: auth?.buyerId,
|
|
474
|
+
});
|
|
413
475
|
|
|
414
476
|
if (auth?.sessionToken) {
|
|
415
477
|
notifyAddressCompleted(checkoutConfig, auth.sessionToken, {
|
|
@@ -420,7 +482,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
420
482
|
locality: address.locality,
|
|
421
483
|
}).catch(() => {/* silent */});
|
|
422
484
|
|
|
423
|
-
if (!address.addressId) {
|
|
485
|
+
if (!options?.skipCreate && !address.addressId) {
|
|
424
486
|
try {
|
|
425
487
|
await createAddress(checkoutConfig, auth.sessionToken, {
|
|
426
488
|
digipin: address.digipin,
|
|
@@ -449,6 +511,11 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
449
511
|
|
|
450
512
|
if (withPayment && codSession) {
|
|
451
513
|
setStep('payment');
|
|
514
|
+
} else if (withPayment && !codSession) {
|
|
515
|
+
onError?.(new Error('enablePayment requires phone/email auth or a codSessionToken prop.'));
|
|
516
|
+
setStep('done');
|
|
517
|
+
onComplete(address);
|
|
518
|
+
return;
|
|
452
519
|
} else {
|
|
453
520
|
setStep('done');
|
|
454
521
|
onComplete(address);
|
|
@@ -456,12 +523,42 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
456
523
|
};
|
|
457
524
|
|
|
458
525
|
const handleAddressComplete = async (address: CompleteAddress) => {
|
|
526
|
+
if (verifyAddress && auth?.sessionToken) {
|
|
527
|
+
try {
|
|
528
|
+
await verifyDigipin(checkoutConfig, auth.sessionToken, verifyAddress.id, {
|
|
529
|
+
digipin: address.digipin,
|
|
530
|
+
lat: address.lat,
|
|
531
|
+
lng: address.lng,
|
|
532
|
+
state: address.state,
|
|
533
|
+
district: address.district,
|
|
534
|
+
locality: address.locality,
|
|
535
|
+
pincode: address.pincode,
|
|
536
|
+
delivery_status: address.delivery,
|
|
537
|
+
flat_number: address.flatNumber,
|
|
538
|
+
floor_number: address.floorNumber,
|
|
539
|
+
building_name: address.buildingName,
|
|
540
|
+
street_name: address.streetName,
|
|
541
|
+
});
|
|
542
|
+
const complete: CompleteAddress = { ...address, addressId: verifyAddress.id };
|
|
543
|
+
setVerifyAddress(null);
|
|
544
|
+
await finishAddress(complete, { skipCreate: true });
|
|
545
|
+
} catch (err: unknown) {
|
|
546
|
+
onError?.(err instanceof Error ? err : new Error('Failed to verify delivery pin.'));
|
|
547
|
+
}
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
459
550
|
await finishAddress(address);
|
|
460
551
|
};
|
|
461
552
|
|
|
462
553
|
const handleBack = (): boolean => {
|
|
463
554
|
if (step === 'form') {
|
|
464
|
-
setStep('map');
|
|
555
|
+
setStep(verifyAddress ? 'verify-address' : 'map');
|
|
556
|
+
return true;
|
|
557
|
+
}
|
|
558
|
+
if (step === 'verify-address') {
|
|
559
|
+
setVerifyAddress(null);
|
|
560
|
+
setConfirmedLocation(null);
|
|
561
|
+
setStep('saved');
|
|
465
562
|
return true;
|
|
466
563
|
}
|
|
467
564
|
if (step === 'map' && auth?.sessionToken) {
|
|
@@ -477,7 +574,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
477
574
|
return true;
|
|
478
575
|
}
|
|
479
576
|
if (step === 'payment') {
|
|
480
|
-
setStep(
|
|
577
|
+
setStep(paymentBackStep);
|
|
481
578
|
return true;
|
|
482
579
|
}
|
|
483
580
|
return false;
|
|
@@ -489,7 +586,13 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
489
586
|
goBack: () => {
|
|
490
587
|
const current = stepRef.current;
|
|
491
588
|
if (current === 'form') {
|
|
492
|
-
setStep('map');
|
|
589
|
+
setStep(verifyAddress ? 'verify-address' : 'map');
|
|
590
|
+
return true;
|
|
591
|
+
}
|
|
592
|
+
if (current === 'verify-address') {
|
|
593
|
+
setVerifyAddress(null);
|
|
594
|
+
setConfirmedLocation(null);
|
|
595
|
+
setStep('saved');
|
|
493
596
|
return true;
|
|
494
597
|
}
|
|
495
598
|
if (current === 'map' && auth?.sessionToken) {
|
|
@@ -505,20 +608,21 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
505
608
|
return true;
|
|
506
609
|
}
|
|
507
610
|
if (current === 'payment') {
|
|
508
|
-
setStep(
|
|
611
|
+
setStep(paymentBackStep);
|
|
509
612
|
return true;
|
|
510
613
|
}
|
|
511
614
|
return false;
|
|
512
615
|
},
|
|
513
616
|
getStep: () => stepRef.current,
|
|
514
617
|
});
|
|
515
|
-
}, [registerController, auth?.sessionToken]);
|
|
618
|
+
}, [registerController, auth?.sessionToken, verifyAddress, paymentBackStep]);
|
|
516
619
|
|
|
517
620
|
const handleEditAddress = () => {
|
|
518
621
|
emit({ type: 'widget_reset', step: initialStep });
|
|
519
622
|
setStep(initialStep);
|
|
520
623
|
setConfirmedLocation(null);
|
|
521
624
|
setCompletedAddress(null);
|
|
625
|
+
setVerifyAddress(null);
|
|
522
626
|
};
|
|
523
627
|
|
|
524
628
|
// ── Emit "step viewed" event on every step change ────────────────────────
|
|
@@ -529,6 +633,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
529
633
|
phone: 'phone_step_viewed',
|
|
530
634
|
email: 'email_step_viewed',
|
|
531
635
|
saved: 'saved_addresses_viewed',
|
|
636
|
+
'verify-address': 'verify_address_step_viewed',
|
|
532
637
|
map: 'map_step_viewed',
|
|
533
638
|
form: 'form_step_viewed',
|
|
534
639
|
payment: 'payment_step_viewed',
|
|
@@ -689,10 +794,35 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
689
794
|
functionBaseUrl={supabaseFunctionBaseUrl}
|
|
690
795
|
merchantId={merchantId}
|
|
691
796
|
onSelectAddress={handleSelectSavedAddress}
|
|
692
|
-
onAddNew={() =>
|
|
797
|
+
onAddNew={() => {
|
|
798
|
+
setVerifyAddress(null);
|
|
799
|
+
setConfirmedLocation(null);
|
|
800
|
+
setStep('map');
|
|
801
|
+
}}
|
|
693
802
|
/>
|
|
694
803
|
)}
|
|
695
804
|
|
|
805
|
+
{/* ── Verify address (lazy DigiPin) ── */}
|
|
806
|
+
{step === 'verify-address' && verifyAddress && (
|
|
807
|
+
<>
|
|
808
|
+
<div className="qr-order-lock-banner" role="status">
|
|
809
|
+
Confirm your delivery pin to complete this order
|
|
810
|
+
</div>
|
|
811
|
+
<MapPinSelector
|
|
812
|
+
onLocationConfirm={handleLocationConfirm}
|
|
813
|
+
defaultLat={verifyAddress.lat ?? defaultLat}
|
|
814
|
+
defaultLng={verifyAddress.lng ?? defaultLng}
|
|
815
|
+
mapHeight={mapHeight}
|
|
816
|
+
theme={theme}
|
|
817
|
+
indiaBoundaryUrl={indiaBoundaryUrl}
|
|
818
|
+
enableSearch={enableSearch}
|
|
819
|
+
apiKey={apiKey}
|
|
820
|
+
apiBaseUrl={apiBaseUrl}
|
|
821
|
+
brandColor={brandColor}
|
|
822
|
+
/>
|
|
823
|
+
</>
|
|
824
|
+
)}
|
|
825
|
+
|
|
696
826
|
{/* ── Map step ── */}
|
|
697
827
|
{step === 'map' && (
|
|
698
828
|
<MapPinSelector
|
|
@@ -726,6 +856,22 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
726
856
|
enableServiceabilityCheck={enableServiceabilityCheck}
|
|
727
857
|
showIndiaPostDeliveryWarning={showIndiaPostDeliveryWarning}
|
|
728
858
|
serviceabilityBlockCheckout={serviceabilityBlockCheckout}
|
|
859
|
+
initialValues={
|
|
860
|
+
verifyAddress
|
|
861
|
+
? {
|
|
862
|
+
flatNumber: verifyAddress.flat_number,
|
|
863
|
+
floorNumber: verifyAddress.floor_number,
|
|
864
|
+
buildingName: verifyAddress.building_name,
|
|
865
|
+
streetName: verifyAddress.street_name,
|
|
866
|
+
locality: verifyAddress.locality,
|
|
867
|
+
label: (verifyAddress.label === 'work' || verifyAddress.label === 'other'
|
|
868
|
+
? verifyAddress.label
|
|
869
|
+
: 'home') as CompleteAddress['label'],
|
|
870
|
+
labelText: verifyAddress.label_text?.trim() || undefined,
|
|
871
|
+
}
|
|
872
|
+
: undefined
|
|
873
|
+
}
|
|
874
|
+
submitLabel={verifyAddress ? 'Confirm delivery pin' : undefined}
|
|
729
875
|
/>
|
|
730
876
|
)}
|
|
731
877
|
|
|
@@ -744,6 +890,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
744
890
|
onEvent={(type, paymentMethod) =>
|
|
745
891
|
emit({ type, step: 'payment', paymentMethod, buyerId: auth?.buyerId })
|
|
746
892
|
}
|
|
893
|
+
orderConfirmationUrl={orderConfirmationUrl}
|
|
747
894
|
/>
|
|
748
895
|
)}
|
|
749
896
|
|
|
@@ -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(
|
|
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 {
|
|
@@ -122,10 +122,14 @@ function AddressCard({ address, onUse, onDelete, onSetDefault, deleting }: Addre
|
|
|
122
122
|
</>
|
|
123
123
|
)}
|
|
124
124
|
<div className="qr-addr-card__meta">
|
|
125
|
-
|
|
126
|
-
<span className="qr-digipin-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
{address.digipin ? (
|
|
126
|
+
<span className="qr-digipin-badge qr-digipin-badge--inline qr-digipin-badge--sm">
|
|
127
|
+
<span className="qr-digipin-badge__label">DigiPin</span>
|
|
128
|
+
<span className="qr-digipin-badge__code">{address.digipin}</span>
|
|
129
|
+
</span>
|
|
130
|
+
) : (
|
|
131
|
+
<span className="qr-addr-card__pending-pin">Pin confirmation needed</span>
|
|
132
|
+
)}
|
|
129
133
|
{address.saved_at_brand && (
|
|
130
134
|
<span className="qr-addr-card__brand-chip" title={`First saved at ${address.saved_at_brand}`}>
|
|
131
135
|
<svg viewBox="0 0 12 12" fill="currentColor" aria-hidden="true">
|