@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
package/src/core/checkout-api.ts
CHANGED
|
@@ -69,9 +69,10 @@ export async function verifyOtp(
|
|
|
69
69
|
|
|
70
70
|
export interface SavedAddress {
|
|
71
71
|
id: string;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
/** Null for imported addresses pending lazy map verification. */
|
|
73
|
+
digipin: string | null;
|
|
74
|
+
lat: number | null;
|
|
75
|
+
lng: number | null;
|
|
75
76
|
state: string;
|
|
76
77
|
district: string;
|
|
77
78
|
locality: string;
|
|
@@ -183,6 +184,60 @@ export async function setDefaultAddress(
|
|
|
183
184
|
}
|
|
184
185
|
}
|
|
185
186
|
|
|
187
|
+
/** Record the buyer's address choice for the current checkout session. */
|
|
188
|
+
export async function selectAddress(
|
|
189
|
+
config: CheckoutApiConfig,
|
|
190
|
+
sessionToken: string,
|
|
191
|
+
addressId: string
|
|
192
|
+
): Promise<void> {
|
|
193
|
+
const res = await fetch(`${config.functionBaseUrl}/checkout-addresses`, {
|
|
194
|
+
method: 'POST',
|
|
195
|
+
headers: addressHeaders(sessionToken),
|
|
196
|
+
body: JSON.stringify({ action: 'select_address', address_id: addressId }),
|
|
197
|
+
});
|
|
198
|
+
const data = await res.json().catch(() => ({}));
|
|
199
|
+
if (!res.ok || !data.success) {
|
|
200
|
+
throw new Error(data.error ?? 'Failed to select address.');
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface VerifyDigipinPayload {
|
|
205
|
+
digipin: string;
|
|
206
|
+
lat: number;
|
|
207
|
+
lng: number;
|
|
208
|
+
state?: string;
|
|
209
|
+
district?: string;
|
|
210
|
+
locality?: string;
|
|
211
|
+
pincode?: string;
|
|
212
|
+
delivery_status?: string;
|
|
213
|
+
flat_number?: string;
|
|
214
|
+
floor_number?: string;
|
|
215
|
+
building_name?: string;
|
|
216
|
+
street_name?: string;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Confirm map pin + form for an imported address missing DigiPin.
|
|
221
|
+
* Updates buyer_addresses and marks the session address as verified.
|
|
222
|
+
*/
|
|
223
|
+
export async function verifyDigipin(
|
|
224
|
+
config: CheckoutApiConfig,
|
|
225
|
+
sessionToken: string,
|
|
226
|
+
addressId: string,
|
|
227
|
+
payload: VerifyDigipinPayload
|
|
228
|
+
): Promise<SavedAddress> {
|
|
229
|
+
const res = await fetch(`${config.functionBaseUrl}/checkout-addresses`, {
|
|
230
|
+
method: 'POST',
|
|
231
|
+
headers: addressHeaders(sessionToken),
|
|
232
|
+
body: JSON.stringify({ action: 'verify_digipin', address_id: addressId, ...payload }),
|
|
233
|
+
});
|
|
234
|
+
const data = await res.json().catch(() => ({}));
|
|
235
|
+
if (!res.ok || !data.success) {
|
|
236
|
+
throw new Error(data.error ?? 'Failed to verify delivery pin.');
|
|
237
|
+
}
|
|
238
|
+
return data.data as SavedAddress;
|
|
239
|
+
}
|
|
240
|
+
|
|
186
241
|
// ─── Webhook: address completed ──────────────────────────────────────────────
|
|
187
242
|
|
|
188
243
|
/**
|
|
@@ -467,7 +522,7 @@ export async function verifyPayment(
|
|
|
467
522
|
razorpay_signature: string;
|
|
468
523
|
payment_method?: string;
|
|
469
524
|
}
|
|
470
|
-
): Promise<{ payment_method: string }> {
|
|
525
|
+
): Promise<{ payment_method: string; razorpay_order_id: string; razorpay_payment_id: string }> {
|
|
471
526
|
const res = await fetch(`${config.functionBaseUrl}/checkout-payment`, {
|
|
472
527
|
method: 'POST',
|
|
473
528
|
headers: addressHeaders(sessionToken),
|
|
@@ -477,7 +532,11 @@ export async function verifyPayment(
|
|
|
477
532
|
if (!res.ok || !data.success) {
|
|
478
533
|
throw new Error(data.error ?? 'Payment verification failed.');
|
|
479
534
|
}
|
|
480
|
-
return {
|
|
535
|
+
return {
|
|
536
|
+
payment_method: data.payment_method as string,
|
|
537
|
+
razorpay_order_id: data.razorpay_order_id as string,
|
|
538
|
+
razorpay_payment_id: data.razorpay_payment_id as string,
|
|
539
|
+
};
|
|
481
540
|
}
|
|
482
541
|
|
|
483
542
|
export async function recordCodPayment(
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { AdministrativeInfo, LocationAlternative } from './types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* India Post office-type suffixes on locality names (e.g. "Hessarghatta Lake S.O").
|
|
5
|
+
* These are post-office designations, not buyer-facing locality labels.
|
|
6
|
+
*/
|
|
7
|
+
const INDIA_POST_OFFICE_SUFFIX =
|
|
8
|
+
/\s+(?:B\.?\s*O\.?|S\.?\s*O\.?|H\.?\s*O\.?|P\.?\s*O\.?|D\.?\s*S\.?\s*O\.?|S\.?\s*D\.?\s*O\.?|S\.?\s*B\.?\s*C\.?|C\.?\s*P\.?\s*C\.?|M\.?\s*D\.?\s*G\.?)\.?\s*$/i;
|
|
9
|
+
|
|
10
|
+
/** Remove trailing India Post office suffix from a locality name. */
|
|
11
|
+
export function stripIndiaPostOfficeSuffix(name: string): string {
|
|
12
|
+
return name.replace(INDIA_POST_OFFICE_SUFFIX, '').replace(/\s+/g, ' ').trim();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Case-insensitive key for deduplicating locality names. */
|
|
16
|
+
export function localityDedupeKey(name: string): string {
|
|
17
|
+
return stripIndiaPostOfficeSuffix(name).toLowerCase();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ProcessedLocalityLookup {
|
|
21
|
+
adminInfo: AdministrativeInfo;
|
|
22
|
+
alternatives: LocationAlternative[];
|
|
23
|
+
localityOptions: string[];
|
|
24
|
+
selectedLocality: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Normalize primary locality + alternatives from location lookup:
|
|
29
|
+
* - strip S.O / H.O / B.O style suffixes for display
|
|
30
|
+
* - merge duplicates that differ only by office suffix
|
|
31
|
+
*/
|
|
32
|
+
export function processLocalityLookup(
|
|
33
|
+
adminInfo: AdministrativeInfo,
|
|
34
|
+
alternatives: LocationAlternative[] = [],
|
|
35
|
+
): ProcessedLocalityLookup {
|
|
36
|
+
const seen = new Set<string>();
|
|
37
|
+
const localityOptions: string[] = [];
|
|
38
|
+
|
|
39
|
+
const addUnique = (rawName: string) => {
|
|
40
|
+
const key = localityDedupeKey(rawName);
|
|
41
|
+
if (!key || seen.has(key)) return;
|
|
42
|
+
seen.add(key);
|
|
43
|
+
localityOptions.push(stripIndiaPostOfficeSuffix(rawName));
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
addUnique(adminInfo.locality);
|
|
47
|
+
for (const alt of alternatives) {
|
|
48
|
+
addUnique(alt.name);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const primaryClean = stripIndiaPostOfficeSuffix(adminInfo.locality);
|
|
52
|
+
const primaryKey = localityDedupeKey(adminInfo.locality);
|
|
53
|
+
|
|
54
|
+
const cleanedAlternatives = alternatives
|
|
55
|
+
.map((alt) => ({
|
|
56
|
+
...alt,
|
|
57
|
+
name: stripIndiaPostOfficeSuffix(alt.name),
|
|
58
|
+
}))
|
|
59
|
+
.filter((alt) => {
|
|
60
|
+
const key = localityDedupeKey(alt.name);
|
|
61
|
+
return key && key !== primaryKey;
|
|
62
|
+
})
|
|
63
|
+
.filter(
|
|
64
|
+
(alt, idx, arr) =>
|
|
65
|
+
arr.findIndex((a) => localityDedupeKey(a.name) === localityDedupeKey(alt.name)) === idx,
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
adminInfo: { ...adminInfo, locality: primaryClean },
|
|
70
|
+
alternatives: cleanedAlternatives,
|
|
71
|
+
localityOptions,
|
|
72
|
+
selectedLocality: primaryClean,
|
|
73
|
+
};
|
|
74
|
+
}
|
package/src/core/types.ts
CHANGED
|
@@ -120,6 +120,7 @@ export type CheckoutEventType =
|
|
|
120
120
|
| 'auth_skipped'
|
|
121
121
|
| 'saved_addresses_viewed'
|
|
122
122
|
| 'saved_address_selected'
|
|
123
|
+
| 'verify_address_step_viewed'
|
|
123
124
|
| 'map_step_viewed'
|
|
124
125
|
| 'location_confirmed'
|
|
125
126
|
| 'form_step_viewed'
|
|
@@ -197,6 +198,17 @@ export interface MapPinSelectorProps {
|
|
|
197
198
|
brandColor?: string;
|
|
198
199
|
}
|
|
199
200
|
|
|
201
|
+
/** Pre-fill manual fields when verifying an imported saved address. */
|
|
202
|
+
export interface AddressFormInitialValues {
|
|
203
|
+
flatNumber?: string;
|
|
204
|
+
floorNumber?: string;
|
|
205
|
+
buildingName?: string;
|
|
206
|
+
streetName?: string;
|
|
207
|
+
locality?: string;
|
|
208
|
+
label?: AddressLabel;
|
|
209
|
+
labelText?: string;
|
|
210
|
+
}
|
|
211
|
+
|
|
200
212
|
export interface AddressFormProps {
|
|
201
213
|
digipin: string;
|
|
202
214
|
lat: number;
|
|
@@ -207,6 +219,10 @@ export interface AddressFormProps {
|
|
|
207
219
|
onBack: () => void;
|
|
208
220
|
onError?: (error: Error) => void;
|
|
209
221
|
theme?: 'light' | 'dark';
|
|
222
|
+
/** Pre-populate manual fields from a saved address row (lazy DigiPin verify). */
|
|
223
|
+
initialValues?: AddressFormInitialValues;
|
|
224
|
+
/** Override primary submit button label (default: "Save Address"). */
|
|
225
|
+
submitLabel?: string;
|
|
210
226
|
/** Checkout API config for merchant serviceability checks. */
|
|
211
227
|
checkoutConfig?: CheckoutApiConfig;
|
|
212
228
|
/** Buyer session token used by checkout-addresses serviceability_check. */
|
|
@@ -356,7 +372,19 @@ export interface CheckoutWidgetProps {
|
|
|
356
372
|
/** Cart total in paise for Razorpay order creation. Required when enablePayment is true. */
|
|
357
373
|
paymentAmountPaise?: number;
|
|
358
374
|
/** Called when payment completes (prepaid or COD). */
|
|
359
|
-
onPaymentComplete?: (result: {
|
|
375
|
+
onPaymentComplete?: (result: {
|
|
376
|
+
paymentMethod: string;
|
|
377
|
+
sessionId?: string;
|
|
378
|
+
razorpayOrderId?: string;
|
|
379
|
+
razorpayPaymentId?: string;
|
|
380
|
+
}) => void;
|
|
381
|
+
/**
|
|
382
|
+
* URL to redirect the buyer to after successful payment.
|
|
383
|
+
* Use `{{sessionId}}` as a placeholder — the widget replaces it before redirecting.
|
|
384
|
+
* Example: "https://yourstore.com/order/confirm?sid={{sessionId}}"
|
|
385
|
+
* When omitted, no redirect occurs and the host app handles navigation via onPaymentComplete.
|
|
386
|
+
*/
|
|
387
|
+
orderConfirmationUrl?: string;
|
|
360
388
|
/**
|
|
361
389
|
* Show prepaid conversion nudge when COD is eligible (merchant `prepaid_nudge_copy` or prop override).
|
|
362
390
|
*/
|
|
@@ -425,9 +453,14 @@ export interface PaymentStepProps {
|
|
|
425
453
|
enableCod?: boolean;
|
|
426
454
|
codAllowed?: boolean;
|
|
427
455
|
theme?: 'light' | 'dark';
|
|
428
|
-
onComplete: (
|
|
456
|
+
onComplete: (result: {
|
|
457
|
+
paymentMethod: string;
|
|
458
|
+
razorpayOrderId?: string;
|
|
459
|
+
razorpayPaymentId?: string;
|
|
460
|
+
}) => void;
|
|
429
461
|
onBack?: () => void;
|
|
430
462
|
onEvent?: (type: CheckoutEventType, paymentMethod?: string) => void;
|
|
463
|
+
orderConfirmationUrl?: string;
|
|
431
464
|
}
|
|
432
465
|
|
|
433
466
|
export interface PrepaidNudgeProps {
|
package/src/index.ts
CHANGED
|
@@ -71,6 +71,8 @@ export {
|
|
|
71
71
|
createAddress,
|
|
72
72
|
deleteAddress,
|
|
73
73
|
setDefaultAddress,
|
|
74
|
+
selectAddress,
|
|
75
|
+
verifyDigipin,
|
|
74
76
|
checkCodEligibility,
|
|
75
77
|
checkServiceability,
|
|
76
78
|
notifyAddressCompleted,
|
|
@@ -89,6 +91,7 @@ export type {
|
|
|
89
91
|
SendEmailOtpResult,
|
|
90
92
|
SavedAddress,
|
|
91
93
|
SavedAddressPayload,
|
|
94
|
+
VerifyDigipinPayload,
|
|
92
95
|
CodEligibilityResult,
|
|
93
96
|
ServiceabilityResult,
|
|
94
97
|
SessionContextPayload,
|
|
@@ -119,6 +122,7 @@ export type {
|
|
|
119
122
|
CheckoutWidgetProps,
|
|
120
123
|
MapPinSelectorProps,
|
|
121
124
|
AddressFormProps,
|
|
125
|
+
AddressFormInitialValues,
|
|
122
126
|
PhoneStepProps,
|
|
123
127
|
OtpStepProps,
|
|
124
128
|
EmailStepProps,
|
package/src/styles/checkout.css
CHANGED
|
@@ -1350,6 +1350,38 @@
|
|
|
1350
1350
|
font-weight: 600;
|
|
1351
1351
|
}
|
|
1352
1352
|
|
|
1353
|
+
/* Order lock — lazy DigiPin verification */
|
|
1354
|
+
.qr-order-lock-banner {
|
|
1355
|
+
margin: 0 16px 8px;
|
|
1356
|
+
padding: 10px 14px;
|
|
1357
|
+
border-radius: 8px;
|
|
1358
|
+
background: color-mix(in srgb, #f59e0b 14%, white);
|
|
1359
|
+
border: 1px solid color-mix(in srgb, #f59e0b 35%, white);
|
|
1360
|
+
font-size: 13px;
|
|
1361
|
+
font-weight: 600;
|
|
1362
|
+
line-height: 1.4;
|
|
1363
|
+
color: var(--qr-text, #1f2937);
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
.qr-checkout--dark .qr-order-lock-banner {
|
|
1367
|
+
background: color-mix(in srgb, #f59e0b 18%, #1f2937);
|
|
1368
|
+
border-color: color-mix(in srgb, #f59e0b 40%, #374151);
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
.qr-addr-card__pending-pin {
|
|
1372
|
+
font-size: 11px;
|
|
1373
|
+
font-weight: 600;
|
|
1374
|
+
color: #b45309;
|
|
1375
|
+
background: color-mix(in srgb, #f59e0b 12%, white);
|
|
1376
|
+
padding: 2px 8px;
|
|
1377
|
+
border-radius: 999px;
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
.qr-checkout--dark .qr-addr-card__pending-pin {
|
|
1381
|
+
color: #fbbf24;
|
|
1382
|
+
background: color-mix(in srgb, #f59e0b 20%, #1f2937);
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1353
1385
|
/* Payment step */
|
|
1354
1386
|
.qr-payment-step {
|
|
1355
1387
|
padding: 16px;
|