@quantaroute/checkout 1.4.4 → 1.5.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 +30 -0
- package/README.md +223 -122
- package/dist/lib/index.d.ts +72 -1
- package/dist/lib/quantaroute-checkout.es.js +158 -143
- package/dist/lib/quantaroute-checkout.umd.js +160 -145
- package/dist/style.css +1 -1
- package/package.json +2 -1
- package/src/components/AddressForm.native.tsx +126 -20
- package/src/components/AddressForm.tsx +113 -23
- package/src/components/CheckoutWidget.native.tsx +8 -0
- package/src/components/CheckoutWidget.tsx +28 -4
- package/src/components/PaymentStep.tsx +11 -2
- package/src/core/checkout-api.ts +59 -2
- package/src/core/locality.ts +74 -0
- package/src/core/types.ts +47 -3
- package/src/index.ts +2 -0
- package/src/styles/checkout.css +29 -0
- package/src/styles/checkout.native.ts +25 -0
package/src/core/checkout-api.ts
CHANGED
|
@@ -305,6 +305,59 @@ export async function checkCodEligibility(
|
|
|
305
305
|
return data.data as CodEligibilityResult;
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
+
// ─── Merchant serviceability (courier / 3PL pincode check) ───────────────────
|
|
309
|
+
|
|
310
|
+
export interface ServiceabilityResult {
|
|
311
|
+
/** Whether a merchant serviceability endpoint was configured and enabled. */
|
|
312
|
+
enabled: boolean;
|
|
313
|
+
/** Whether the merchant endpoint returned a definitive response. */
|
|
314
|
+
checked: boolean;
|
|
315
|
+
/** true/false when checked, null when disabled or failed open. */
|
|
316
|
+
serviceable: boolean | null;
|
|
317
|
+
/** Normalized 6-digit pincode when valid; otherwise the trimmed input. */
|
|
318
|
+
pincode: string;
|
|
319
|
+
/** Buyer-facing merchant message, when supplied by the merchant endpoint. */
|
|
320
|
+
message?: string;
|
|
321
|
+
/** Whether the widget should block address submission when not serviceable. */
|
|
322
|
+
block_checkout: boolean;
|
|
323
|
+
/** Whether the merchant wants the soft India Post info banner as fallback. */
|
|
324
|
+
show_india_post_delivery_warning: boolean;
|
|
325
|
+
/** Present when the endpoint was skipped or failed open. */
|
|
326
|
+
reason?:
|
|
327
|
+
| 'not_configured'
|
|
328
|
+
| 'invalid_pincode'
|
|
329
|
+
| 'merchant_error'
|
|
330
|
+
| 'merchant_unreachable'
|
|
331
|
+
| 'invalid_response';
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Check merchant courier serviceability for a pincode.
|
|
336
|
+
* Uses the merchant's configured webhook on checkout.merchants and fails open.
|
|
337
|
+
*/
|
|
338
|
+
export async function checkServiceability(
|
|
339
|
+
config: CheckoutApiConfig,
|
|
340
|
+
sessionToken: string,
|
|
341
|
+
pincode: string,
|
|
342
|
+
coords?: { lat?: number; lng?: number }
|
|
343
|
+
): Promise<ServiceabilityResult> {
|
|
344
|
+
const res = await fetch(`${config.functionBaseUrl}/checkout-addresses`, {
|
|
345
|
+
method: 'POST',
|
|
346
|
+
headers: addressHeaders(sessionToken),
|
|
347
|
+
body: JSON.stringify({
|
|
348
|
+
action: 'serviceability_check',
|
|
349
|
+
pincode,
|
|
350
|
+
...(coords?.lat !== undefined ? { lat: coords.lat } : {}),
|
|
351
|
+
...(coords?.lng !== undefined ? { lng: coords.lng } : {}),
|
|
352
|
+
}),
|
|
353
|
+
});
|
|
354
|
+
const data = await res.json().catch(() => ({}));
|
|
355
|
+
if (!res.ok || !data.success) {
|
|
356
|
+
throw new Error(data.error ?? 'Failed to check delivery serviceability.');
|
|
357
|
+
}
|
|
358
|
+
return data.data as ServiceabilityResult;
|
|
359
|
+
}
|
|
360
|
+
|
|
308
361
|
// ─── Funnel events (server-side analytics) ────────────────────────────────────
|
|
309
362
|
|
|
310
363
|
export interface FunnelEventPayload {
|
|
@@ -414,7 +467,7 @@ export async function verifyPayment(
|
|
|
414
467
|
razorpay_signature: string;
|
|
415
468
|
payment_method?: string;
|
|
416
469
|
}
|
|
417
|
-
): Promise<{ payment_method: string }> {
|
|
470
|
+
): Promise<{ payment_method: string; razorpay_order_id: string; razorpay_payment_id: string }> {
|
|
418
471
|
const res = await fetch(`${config.functionBaseUrl}/checkout-payment`, {
|
|
419
472
|
method: 'POST',
|
|
420
473
|
headers: addressHeaders(sessionToken),
|
|
@@ -424,7 +477,11 @@ export async function verifyPayment(
|
|
|
424
477
|
if (!res.ok || !data.success) {
|
|
425
478
|
throw new Error(data.error ?? 'Payment verification failed.');
|
|
426
479
|
}
|
|
427
|
-
return {
|
|
480
|
+
return {
|
|
481
|
+
payment_method: data.payment_method as string,
|
|
482
|
+
razorpay_order_id: data.razorpay_order_id as string,
|
|
483
|
+
razorpay_payment_id: data.razorpay_payment_id as string,
|
|
484
|
+
};
|
|
428
485
|
}
|
|
429
486
|
|
|
430
487
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { UtmParams } from './utm';
|
|
3
|
-
import type { SessionContextPayload } from './checkout-api';
|
|
3
|
+
import type { CheckoutApiConfig, ServiceabilityResult, SessionContextPayload } from './checkout-api';
|
|
4
4
|
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
6
|
type AnyStyle = any; // CSSProperties on web · StyleProp<ViewStyle> on native
|
|
@@ -207,6 +207,18 @@ export interface AddressFormProps {
|
|
|
207
207
|
onBack: () => void;
|
|
208
208
|
onError?: (error: Error) => void;
|
|
209
209
|
theme?: 'light' | 'dark';
|
|
210
|
+
/** Checkout API config for merchant serviceability checks. */
|
|
211
|
+
checkoutConfig?: CheckoutApiConfig;
|
|
212
|
+
/** Buyer session token used by checkout-addresses serviceability_check. */
|
|
213
|
+
serviceabilitySessionToken?: string;
|
|
214
|
+
/** When true, calls the merchant courier serviceability endpoint after pincode validation. */
|
|
215
|
+
enableServiceabilityCheck?: boolean;
|
|
216
|
+
/** Shows a soft India Post home-delivery info banner when merchant check is absent/failed. */
|
|
217
|
+
showIndiaPostDeliveryWarning?: boolean;
|
|
218
|
+
/** Optional client override for blocking address save when merchant says not serviceable. */
|
|
219
|
+
serviceabilityBlockCheckout?: boolean;
|
|
220
|
+
/** Optional observer for the merchant serviceability result. */
|
|
221
|
+
onServiceabilityResult?: (result: ServiceabilityResult) => void;
|
|
210
222
|
}
|
|
211
223
|
|
|
212
224
|
export interface CheckoutWidgetProps {
|
|
@@ -282,6 +294,21 @@ export interface CheckoutWidgetProps {
|
|
|
282
294
|
* `checkout.merchants.enable_cod` and optional D1/D2 columns.
|
|
283
295
|
*/
|
|
284
296
|
enableCod?: boolean;
|
|
297
|
+
/**
|
|
298
|
+
* Call the merchant's courier serviceability webhook for the resolved pincode.
|
|
299
|
+
* Requires `merchantId`, `supabaseFunctionBaseUrl`, and an authenticated checkout session.
|
|
300
|
+
*/
|
|
301
|
+
enableServiceabilityCheck?: boolean;
|
|
302
|
+
/**
|
|
303
|
+
* Opt-in fallback banner for India Post "Non Delivery" pincodes.
|
|
304
|
+
* Defaults off because courier partners may still deliver.
|
|
305
|
+
*/
|
|
306
|
+
showIndiaPostDeliveryWarning?: boolean;
|
|
307
|
+
/**
|
|
308
|
+
* Client override: block address save when merchant serviceability says not deliverable.
|
|
309
|
+
* If omitted, the server result from checkout.merchants.serviceability_block_checkout is used.
|
|
310
|
+
*/
|
|
311
|
+
serviceabilityBlockCheckout?: boolean;
|
|
285
312
|
/**
|
|
286
313
|
* Cart total in paise for the COD cart cap (D2). Omit if the cart total is unknown.
|
|
287
314
|
*/
|
|
@@ -329,7 +356,19 @@ export interface CheckoutWidgetProps {
|
|
|
329
356
|
/** Cart total in paise for Razorpay order creation. Required when enablePayment is true. */
|
|
330
357
|
paymentAmountPaise?: number;
|
|
331
358
|
/** Called when payment completes (prepaid or COD). */
|
|
332
|
-
onPaymentComplete?: (result: {
|
|
359
|
+
onPaymentComplete?: (result: {
|
|
360
|
+
paymentMethod: string;
|
|
361
|
+
sessionId?: string;
|
|
362
|
+
razorpayOrderId?: string;
|
|
363
|
+
razorpayPaymentId?: string;
|
|
364
|
+
}) => void;
|
|
365
|
+
/**
|
|
366
|
+
* URL to redirect the buyer to after successful payment.
|
|
367
|
+
* Use `{{sessionId}}` as a placeholder — the widget replaces it before redirecting.
|
|
368
|
+
* Example: "https://yourstore.com/order/confirm?sid={{sessionId}}"
|
|
369
|
+
* When omitted, no redirect occurs and the host app handles navigation via onPaymentComplete.
|
|
370
|
+
*/
|
|
371
|
+
orderConfirmationUrl?: string;
|
|
333
372
|
/**
|
|
334
373
|
* Show prepaid conversion nudge when COD is eligible (merchant `prepaid_nudge_copy` or prop override).
|
|
335
374
|
*/
|
|
@@ -398,9 +437,14 @@ export interface PaymentStepProps {
|
|
|
398
437
|
enableCod?: boolean;
|
|
399
438
|
codAllowed?: boolean;
|
|
400
439
|
theme?: 'light' | 'dark';
|
|
401
|
-
onComplete: (
|
|
440
|
+
onComplete: (result: {
|
|
441
|
+
paymentMethod: string;
|
|
442
|
+
razorpayOrderId?: string;
|
|
443
|
+
razorpayPaymentId?: string;
|
|
444
|
+
}) => void;
|
|
402
445
|
onBack?: () => void;
|
|
403
446
|
onEvent?: (type: CheckoutEventType, paymentMethod?: string) => void;
|
|
447
|
+
orderConfirmationUrl?: string;
|
|
404
448
|
}
|
|
405
449
|
|
|
406
450
|
export interface PrepaidNudgeProps {
|
package/src/index.ts
CHANGED
|
@@ -72,6 +72,7 @@ export {
|
|
|
72
72
|
deleteAddress,
|
|
73
73
|
setDefaultAddress,
|
|
74
74
|
checkCodEligibility,
|
|
75
|
+
checkServiceability,
|
|
75
76
|
notifyAddressCompleted,
|
|
76
77
|
logFunnelEvent,
|
|
77
78
|
notifySessionAbandoned,
|
|
@@ -89,6 +90,7 @@ export type {
|
|
|
89
90
|
SavedAddress,
|
|
90
91
|
SavedAddressPayload,
|
|
91
92
|
CodEligibilityResult,
|
|
93
|
+
ServiceabilityResult,
|
|
92
94
|
SessionContextPayload,
|
|
93
95
|
FunnelEventPayload,
|
|
94
96
|
SessionOffer,
|
package/src/styles/checkout.css
CHANGED
|
@@ -1923,10 +1923,39 @@
|
|
|
1923
1923
|
border-color: rgba(245, 158, 11, 0.35);
|
|
1924
1924
|
}
|
|
1925
1925
|
|
|
1926
|
+
.qr-pincode-banner--error {
|
|
1927
|
+
background: rgba(239, 68, 68, 0.1);
|
|
1928
|
+
border: 1px solid rgba(239, 68, 68, 0.38);
|
|
1929
|
+
color: var(--qr-text);
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
.qr-checkout--dark .qr-pincode-banner--error {
|
|
1933
|
+
background: rgba(239, 68, 68, 0.14);
|
|
1934
|
+
border-color: rgba(239, 68, 68, 0.34);
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1937
|
+
.qr-pincode-banner--info {
|
|
1938
|
+
background: color-mix(in srgb, var(--qr-primary) 9%, transparent);
|
|
1939
|
+
border: 1px solid color-mix(in srgb, var(--qr-primary) 28%, transparent);
|
|
1940
|
+
color: var(--qr-text);
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
.qr-checkout--dark .qr-pincode-banner--info {
|
|
1944
|
+
background: color-mix(in srgb, var(--qr-primary) 13%, transparent);
|
|
1945
|
+
border-color: color-mix(in srgb, var(--qr-primary) 26%, transparent);
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1926
1948
|
.qr-pincode-banner__icon {
|
|
1927
1949
|
flex-shrink: 0;
|
|
1950
|
+
display: inline-flex;
|
|
1951
|
+
align-items: center;
|
|
1952
|
+
justify-content: center;
|
|
1953
|
+
width: 18px;
|
|
1954
|
+
height: 18px;
|
|
1955
|
+
border-radius: 999px;
|
|
1928
1956
|
font-size: 16px;
|
|
1929
1957
|
line-height: 1.2;
|
|
1958
|
+
font-weight: 700;
|
|
1930
1959
|
}
|
|
1931
1960
|
|
|
1932
1961
|
.qr-pincode-banner__text {
|
|
@@ -519,13 +519,38 @@ export const styles = StyleSheet.create({
|
|
|
519
519
|
borderWidth: 1,
|
|
520
520
|
borderColor: 'rgba(245, 158, 11, 0.45)',
|
|
521
521
|
},
|
|
522
|
+
pincodeBannerWarning: {
|
|
523
|
+
backgroundColor: 'rgba(245, 158, 11, 0.12)',
|
|
524
|
+
borderColor: 'rgba(245, 158, 11, 0.45)',
|
|
525
|
+
},
|
|
522
526
|
pincodeBannerDark: {
|
|
523
527
|
backgroundColor: 'rgba(245, 158, 11, 0.15)',
|
|
524
528
|
borderColor: 'rgba(245, 158, 11, 0.35)',
|
|
525
529
|
},
|
|
530
|
+
pincodeBannerError: {
|
|
531
|
+
backgroundColor: 'rgba(239, 68, 68, 0.1)',
|
|
532
|
+
borderColor: 'rgba(239, 68, 68, 0.38)',
|
|
533
|
+
},
|
|
534
|
+
pincodeBannerErrorDark: {
|
|
535
|
+
backgroundColor: 'rgba(239, 68, 68, 0.14)',
|
|
536
|
+
borderColor: 'rgba(239, 68, 68, 0.34)',
|
|
537
|
+
},
|
|
538
|
+
pincodeBannerInfo: {
|
|
539
|
+
backgroundColor: 'rgba(14, 165, 233, 0.09)',
|
|
540
|
+
borderColor: 'rgba(14, 165, 233, 0.28)',
|
|
541
|
+
},
|
|
542
|
+
pincodeBannerInfoDark: {
|
|
543
|
+
backgroundColor: 'rgba(14, 165, 233, 0.13)',
|
|
544
|
+
borderColor: 'rgba(14, 165, 233, 0.26)',
|
|
545
|
+
},
|
|
526
546
|
pincodeBannerIcon: {
|
|
547
|
+
width: 18,
|
|
548
|
+
height: 18,
|
|
549
|
+
borderRadius: 9,
|
|
550
|
+
textAlign: 'center',
|
|
527
551
|
fontSize: 16,
|
|
528
552
|
lineHeight: 20,
|
|
553
|
+
fontWeight: '700',
|
|
529
554
|
},
|
|
530
555
|
pincodeBannerTitle: {
|
|
531
556
|
fontSize: 13,
|