@quantaroute/checkout 1.7.4 → 1.8.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/README.md CHANGED
@@ -1,1024 +1,185 @@
1
1
  # @quantaroute/checkout
2
2
 
3
- > **DigiPin-powered smart address checkout widget for Indian e-commerce.**
4
- > Two-step: Map pin → Auto-filled form.
5
- > One package. Three platforms: **React web · iOS · Android.**
3
+ A verified-address checkout step for Indian e-commerce. Shoppers sign in, drop a pin on the map, and get an auto-filled address with a [DigiPin](https://www.indiapost.gov.in). The step runs before your own payment page, and you keep your existing payment gateway.
6
4
 
7
- [Made in India](https://quantaroute.com)
8
- [DigiPin](https://www.indiapost.gov.in)
9
- [Map](https://carto.com)
10
- [License](./LICENSE)
11
-
12
- ---
13
-
14
- ## What it does
15
-
16
- Replaces broken Indian address forms with a precise two-step pin-drop flow:
17
-
18
- ```
19
- Step 1 – Map Pin Step 2 – Auto-fill + Details
20
- ┌──────────────────────────┐ ┌──────────────────────────┐
21
- │ [DigiPin: 39J-438-TJC7] │ │ 📍 Auto-detected │
22
- │ │ │ State: Delhi │
23
- │ 🗺 OSM vector map │ ──► │ District: New Delhi │
24
- │ 📍 ← drag │ │ Pincode: 110011 │
25
- │ │ │ ✓ Deliverable │
26
- │ [⊕ Locate Me] │ │ 🏠 Add details │
27
- │ [Confirm Location →] │ │ Flat No: [_________] │
28
- └──────────────────────────┘ │ [← Adjust] [Save ✓] │
29
- └──────────────────────────┘
30
- ```
31
-
32
- **Key features:**
33
-
34
- - DigiPin shown **offline** in real-time as the user drags the pin (~4 m × 4 m precision)
35
- - **No Google Maps.** Free Carto Positron vector basemap
36
- - Auto-fills State, District, Locality, Pincode, Delivery status from QuantaRoute API
37
- - Manual fields: Flat no., Floor, Building (OSM pre-filled), Street/Area (OSM pre-filled)
38
- - Mobile-first (full-screen on phones, card on desktop/tablet)
39
- - Dark mode, reduced-motion, keyboard navigation, ARIA labels
40
- - TypeScript — zero runtime deps beyond peer dependencies
41
-
42
- ---
5
+ - **Hosted for you.** You need a merchant ID and a public key. There's no backend to deploy.
6
+ - **Not a payment gateway.** The widget never takes payment. It hands you a verified address and a session ID.
7
+ - **Funnel tracking.** Every step emits an event, so you can see where shoppers drop off.
43
8
 
44
9
  ## Platform support
45
10
 
11
+ | Platform | Install | Shopper sign-in and sessions | Map, DigiPin, address form |
12
+ | --- | --- | --- | --- |
13
+ | Any website (script tag) | One `<script>` tag | Yes | Yes |
14
+ | React, Next.js, Vite | `npm i @quantaroute/checkout maplibre-gl` | Yes | Yes |
15
+ | iOS and Android (Expo) | `npm i @quantaroute/checkout expo-osm-sdk expo-location` | No (address capture only) | Yes |
46
16
 
47
- | Platform | Bundler | Map engine | Install |
48
- | ----------------------------- | -------------- | --------------------------------- | ---------------------------- |
49
- | React / Next.js / Vite / Nuxt | Webpack / Vite | MapLibre GL JS | `maplibre-gl` |
50
- | iOS (Expo / React Native) | Metro | expo-osm-sdk (MapLibre GL Native) | `expo-osm-sdk expo-location` |
51
- | Android (Expo / React Native) | Metro | expo-osm-sdk (MapLibre GL Native) | `expo-osm-sdk expo-location` |
52
-
53
-
54
- > **Same import on all platforms.**
55
- > Metro automatically resolves `.native.tsx` files on mobile; Vite/Webpack use the web `.tsx` files.
56
-
57
- ---
58
-
59
- ## Quick start
60
-
61
- ### 0 · Get an API key
62
-
63
- 1. Sign up at **[developers.quantaroute.com](https://developers.quantaroute.com)**
64
- 2. Create a project → copy your **API key**
65
-
66
- > **Never hard-code or commit API keys to git.**
67
-
68
- ---
69
-
70
- ## Web (React / Next.js / Vite / Nuxt)
71
-
72
- ### Install
73
-
74
- ```bash
75
- npm install @quantaroute/checkout maplibre-gl
76
- ```
77
-
78
- ### Import CSS
79
-
80
- ```ts
81
- // In your app entry file (main.tsx / _app.tsx / layout.tsx / nuxt.config.ts)
82
- import 'maplibre-gl/dist/maplibre-gl.css';
83
- import '@quantaroute/checkout/style.css';
84
- ```
85
-
86
- ### Use
87
-
88
- ```tsx
89
- import { CheckoutWidget } from '@quantaroute/checkout';
90
-
91
- export default function CheckoutPage() {
92
- return (
93
- <CheckoutWidget
94
- apiKey={process.env.NEXT_PUBLIC_QUANTAROUTE_KEY!}
95
- mapsKey={process.env.NEXT_PUBLIC_QUANTAROUTE_MAPS_KEY}
96
- onComplete={(address) => {
97
- console.log(address.digipin); // "39J-438-TJC7"
98
- console.log(address.pincode); // "110011"
99
- console.log(address.formattedAddress); // "Flat 4B, Floor 3rd, ..."
100
- // → send to your backend / payment gateway
101
- }}
102
- />
103
- );
104
- }
105
- ```
17
+ Shopify stores don't need this package. Install the **QuantaRoute Checkout** app from the Shopify App Store instead.
106
18
 
107
- Third-party hosts must pass `mapsKey` (a public `dp_` key with the maps scope). First-party QuantaRoute sites can omit it.
19
+ ## 1. Get your keys
108
20
 
109
- ### Next.js (App Router)
21
+ Sign up at [developers.quantaroute.com](https://developers.quantaroute.com). Onboarding gives you three things:
110
22
 
111
- ```tsx
112
- // app/checkout/page.tsx
113
- 'use client';
23
+ | Credential | Looks like | Where it goes |
24
+ | --- | --- | --- |
25
+ | Merchant ID | UUID | Browser or app (public) |
26
+ | Public key | `dp_…` | Browser or app (public). Covers geocoding and maps. |
27
+ | Admin key | `qca_…` | **Your server only.** Shown once. |
114
28
 
115
- import dynamic from 'next/dynamic';
29
+ Then add every domain the checkout runs on under **Dashboard → Checkout → Widget settings**. That includes `www.`, any staging domain, and wildcards like `*.example.com`. Sign-in requests from any other domain are refused.
116
30
 
117
- const CheckoutWidget = dynamic(
118
- () => import('@quantaroute/checkout').then((m) => m.CheckoutWidget),
119
- { ssr: false }
120
- );
31
+ ## 2. Add it to your site
121
32
 
122
- export default function CheckoutPage() {
123
- return (
124
- <main className="max-w-lg mx-auto p-4">
125
- <CheckoutWidget
126
- apiKey={process.env.NEXT_PUBLIC_QUANTAROUTE_KEY!}
127
- onComplete={(addr) => console.log(addr)}
128
- />
129
- </main>
130
- );
131
- }
132
- ```
33
+ ### Any website: script tag
133
34
 
134
- CSS in `app/layout.tsx`:
135
-
136
- ```tsx
137
- import 'maplibre-gl/dist/maplibre-gl.css';
138
- import '@quantaroute/checkout/style.css';
139
- ```
140
-
141
- ### Next.js (Pages Router)
142
-
143
- ```tsx
144
- import dynamic from 'next/dynamic';
145
- const CheckoutWidget = dynamic(() => import('@quantaroute/checkout'), { ssr: false });
146
-
147
- export default function CheckoutPage() {
148
- return (
149
- <CheckoutWidget
150
- apiKey={process.env.NEXT_PUBLIC_QUANTAROUTE_KEY!}
151
- onComplete={(a) => console.log(a)}
152
- />
153
- );
154
- }
155
- ```
156
-
157
- ### Nuxt 3
158
-
159
- ```ts
160
- // nuxt.config.ts
161
- export default defineNuxtConfig({
162
- css: ['maplibre-gl/dist/maplibre-gl.css', '@quantaroute/checkout/style.css'],
163
- });
164
- ```
165
-
166
- ```vue
167
- <!-- components/AddressWidget.client.vue (.client = browser-only) -->
168
- <script setup lang="ts">
169
- import { CheckoutWidget } from '@quantaroute/checkout';
170
- const { public: { qrApiKey } } = useRuntimeConfig();
171
- </script>
172
- <template>
173
- <CheckoutWidget :api-key="qrApiKey" map-height="360px" @complete="console.log" />
174
- </template>
175
- ```
176
-
177
- ### Vite + React
178
-
179
- ```tsx
180
- import 'maplibre-gl/dist/maplibre-gl.css';
181
- import '@quantaroute/checkout/style.css';
182
- import { CheckoutWidget } from '@quantaroute/checkout';
183
-
184
- function App() {
185
- return (
186
- <CheckoutWidget
187
- apiKey={import.meta.env.VITE_QR_API_KEY}
188
- onComplete={(addr) => console.log('Saved:', addr)}
189
- />
190
- );
191
- }
192
- ```
193
-
194
- ### Vanilla JS (UMD / script tag)
35
+ Paste this before `</body>`. Set `data-trigger` to the CSS selector of your own Checkout button.
195
36
 
196
37
  ```html
197
- <link rel="stylesheet" href="https://unpkg.com/maplibre-gl/dist/maplibre-gl.css" />
198
- <link rel="stylesheet" href="https://unpkg.com/@quantaroute/checkout/dist/style.css" />
199
-
200
- <div id="checkout-root"></div>
201
-
202
- <script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
203
- <script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
204
- <script src="https://unpkg.com/maplibre-gl/dist/maplibre-gl.js"></script>
205
- <script src="https://unpkg.com/@quantaroute/checkout/dist/lib/quantaroute-checkout.umd.js"></script>
206
- <script>
207
- ReactDOM.createRoot(document.getElementById('checkout-root')).render(
208
- React.createElement(QuantaRouteCheckout.CheckoutWidget, {
209
- apiKey: 'YOUR_KEY',
210
- onComplete: (addr) => console.log('Done:', addr),
211
- })
212
- );
38
+ <script
39
+ src="https://cdn.jsdelivr.net/npm/@quantaroute/checkout@1/dist/embed/quantaroute-checkout.js"
40
+ data-merchant-id="YOUR_MERCHANT_ID"
41
+ data-api-key="dp_YOUR_PUBLIC_KEY"
42
+ data-trigger="#checkout-button"
43
+ data-redirect-url="https://yourshop.com/pay?session={sessionId}">
213
44
  </script>
214
45
  ```
215
46
 
216
- ---
47
+ When a shopper clicks the button, the checkout opens in a modal and your own click handler doesn't run. When they finish, the page goes to `data-redirect-url`.
217
48
 
218
- ## Native (Expo / React Native — iOS & Android)
49
+ - **Redirect placeholders:** `{sessionId}`, `{digipin}`, `{pincode}`, `{state}`, `{district}`, `{locality}`, `{lat}`, `{lng}`, `{formattedAddress}` and `{addressId}`. Each one is URL-encoded.
50
+ - **Optional attributes:** `data-brand-color`, `data-logo-url`, `data-theme` (`light` or `dark`), `data-title`, and `data-auth` (`email`, `phone` or `none`).
219
51
 
220
- > **Requires a [development build](https://docs.expo.dev/develop/development-builds/introduction/).**
221
- > This does NOT work in Expo Go — `expo-osm-sdk` uses native modules.
52
+ If you'd rather handle the result in JavaScript, call `init` yourself:
222
53
 
223
- ### 1 · Install
224
-
225
- ```bash
226
- npm install @quantaroute/checkout expo-osm-sdk expo-location
227
- ```
228
-
229
- ### 2 · Add the config plugin to `app.json`
230
-
231
- ```json
232
- {
233
- "expo": {
234
- "plugins": [
235
- ["@quantaroute/checkout/plugin", {
236
- "locationPermissionText": "Allow access to your location to place the delivery pin on the map."
237
- }]
238
- ]
239
- }
240
- }
54
+ ```js
55
+ const checkout = QuantaRouteCheckout.init({
56
+ merchantId: 'YOUR_MERCHANT_ID',
57
+ apiKey: 'dp_YOUR_PUBLIC_KEY',
58
+ triggers: '#checkout-button',
59
+ onComplete(address) { goToPayment(address.sessionId); },
60
+ onClose() {},
61
+ onEvent(event) {},
62
+ });
63
+ // checkout.open() · close() · destroy() · getSessionId()
241
64
  ```
242
65
 
243
- This single plugin automatically configures:
244
-
245
-
246
- | What | iOS | Android |
247
- | ------------------- | ------------------------------------- | ---------------------- |
248
- | MapLibre native SDK | `expo-osm-sdk/plugin` | `expo-osm-sdk/plugin` |
249
- | Location permission | `NSLocationWhenInUseUsageDescription` | `ACCESS_FINE_LOCATION` |
250
- | Internet permission | – | `INTERNET` |
251
-
252
-
253
- ### 3 · Rebuild your dev client
66
+ The embed also fires these as `window` events: `quantaroute:open`, `quantaroute:close`, `quantaroute:complete` and `quantaroute:event`.
254
67
 
255
- ```bash
256
- npx expo run:ios
257
- # or
258
- npx expo run:android
259
- ```
260
-
261
- ### 4 · Use — identical import as web
68
+ ### React, Next.js, Vite
262
69
 
263
70
  ```tsx
264
71
  import { CheckoutWidget } from '@quantaroute/checkout';
265
- // No CSS import — styles are React Native StyleSheet objects
72
+ import '@quantaroute/checkout/style.css';
73
+ import 'maplibre-gl/dist/maplibre-gl.css';
266
74
 
267
- export default function CheckoutScreen() {
75
+ export function AddressStep() {
268
76
  return (
269
77
  <CheckoutWidget
270
- apiKey={process.env.EXPO_PUBLIC_QUANTAROUTE_KEY!}
271
- mapHeight={380}
272
- onComplete={(address) => {
273
- console.log(address.digipin); // "39J-438-TJC7"
274
- console.log(address.formattedAddress); // "Flat 4B, ..."
275
- }}
78
+ apiKey="dp_YOUR_PUBLIC_KEY"
79
+ merchantId="YOUR_MERCHANT_ID"
80
+ enableEmailAuth
81
+ onCheckoutEvent={(e) => analytics.track(e.type, e)}
82
+ onComplete={(address) => goToPayment(address)}
276
83
  />
277
84
  );
278
85
  }
279
86
  ```
280
87
 
281
- ### Demo native app
282
-
283
- A working Expo demo is in `demo-native/`:
284
-
285
- ```bash
286
- cd demo-native
287
- npm install
288
- # Set your API key in .env: EXPO_PUBLIC_QUANTAROUTE_API_KEY=your_key
289
- npx expo run:ios
290
- npx expo run:android
291
- ```
292
-
293
- ---
294
-
295
- ## Props
296
-
297
- ### Core props
298
-
299
-
300
- | Prop | Type | Default | Platform |
301
- | ------------------ | -------------------------------------- | ----------------------------- | -------- |
302
- | `apiKey` | `string` | **required** | all |
303
- | `onComplete` | `(addr: CompleteAddress) => void` | **required** | all |
304
- | `apiBaseUrl` | `string` | `https://api.quantaroute.com` | all |
305
- | `onError` | `(err: Error) => void` | – | all |
306
- | `defaultLat` | `number` | India center | all |
307
- | `defaultLng` | `number` | India center | all |
308
- | `theme` | `'light' | 'dark'` | `'light'` | all |
309
- | `mapHeight` | `string | number` | `'380px'` / `380` | all |
310
- | `title` | `string` | `'Add Delivery Address'` | all |
311
- | `className` | `string` | – | web only |
312
- | `style` | `CSSProperties | StyleProp<ViewStyle>` | – | all |
313
- | `indiaBoundaryUrl` | `string` | – | web only |
314
-
315
-
316
- ### Search bar
317
-
318
-
319
- | Prop | Type | Default | Platform |
320
- | -------------- | --------- | ------- | -------- |
321
- | `enableSearch` | `boolean` | `true` | all |
322
-
323
-
324
- When `enableSearch` is true, a unified search bar appears above the map. It handles two modes automatically:
325
-
326
- - **Address search** — calls `/v1/digipin/autocomplete` (debounced 400 ms, location-biased)
327
- - **DigiPin input** — decoded **100 % offline**, zero API cost, instant map flyTo
328
-
329
- As India Post promotes DigiPin nationally, buyers can paste their 10-character code and land on their exact ±4 m location.
330
-
331
- ### Phone OTP + saved addresses (D2C checkout)
332
-
333
-
334
- | Prop | Type | Default | Platform |
335
- | ------------------------- | --------- | ------- | -------- |
336
- | `enablePhoneAuth` | `boolean` | `false` | all |
337
- | `merchantId` | `string` | – | all |
338
- | `supabaseFunctionBaseUrl` | `string` | – | all |
339
-
340
-
341
- When `enablePhoneAuth` is true the widget starts with a phone-entry step. Returning buyers can pick a previously saved address from any brand in the network instead of dropping the pin again.
342
-
343
- On the address details step, buyers choose a **Home / Work / Other** label before saving. The label is stored in the checkout-addresses API and returned on `CompleteAddress.label`.
344
-
345
- **Requires:**
346
-
347
- 1. A merchant account — sign up at [developers.quantaroute.com/onboarding](https://developers.quantaroute.com/onboarding/merchant) to get your `merchantId` and `supabaseFunctionBaseUrl`.
348
- 2. The `checkout-otp` and `checkout-addresses` Edge Functions deployed (see [Supabase setup](#supabase-setup)).
349
-
350
- ```tsx
351
- <CheckoutWidget
352
- apiKey={process.env.NEXT_PUBLIC_QUANTAROUTE_KEY!}
353
- merchantId="your-merchant-uuid"
354
- supabaseFunctionBaseUrl="https://<project>.supabase.co/functions/v1"
355
- enablePhoneAuth={true}
356
- enableSearch={true}
357
- onComplete={(addr) => console.log(addr)}
358
- />
359
- ```
360
-
361
- ### Email OTP auth (`enableEmailAuth`)
362
-
363
-
364
- | Prop | Type | Default | Platform |
365
- | ------------------------- | --------- | ------- | -------- |
366
- | `enableEmailAuth` | `boolean` | `false` | all |
367
- | `merchantId` | `string` | – | all |
368
- | `supabaseFunctionBaseUrl` | `string` | – | all |
369
-
370
-
371
- When `enableEmailAuth` is true the widget starts with an email-entry step. The buyer receives a 6-digit OTP via **Resend**. On success a checkout session is created and saved addresses are shown if available.
372
-
373
- > If both `enablePhoneAuth` and `enableEmailAuth` are set, phone OTP takes precedence.
374
-
375
- ```tsx
376
- <CheckoutWidget
377
- apiKey={process.env.NEXT_PUBLIC_QUANTAROUTE_KEY!}
378
- merchantId="your-merchant-uuid"
379
- supabaseFunctionBaseUrl="https://<project>.supabase.co/functions/v1"
380
- enableEmailAuth={true}
381
- onComplete={(addr) => console.log(addr)}
382
- onCheckoutEvent={(event) => {
383
- // email-specific events: email_step_viewed | email_otp_sent | email_verified
384
- console.log('[checkout]', event.type, event);
385
- }}
386
- />
387
- ```
388
-
389
- **Client-side events emitted during email auth:**
390
-
391
-
392
- | Event type | When |
393
- | ------------------- | ----------------------------- |
394
- | `email_step_viewed` | Email input screen rendered |
395
- | `email_otp_sent` | OTP dispatched via Resend |
396
- | `email_verified` | OTP correct → session created |
397
-
398
-
399
- ---
400
-
401
- ### Merchant courier serviceability
402
-
403
- QuantaRoute still validates that a pincode exists in the India Post database, but India Post "Non Delivery" is treated as **reference data**, not the final merchant delivery decision. Most D2C stores ship through Shiprocket, Delhivery, ClickPost, or direct courier contracts, so the buyer-facing serviceability check should come from the merchant.
404
-
405
-
406
- | Prop | Type | Default | Platform |
407
- | ------------------------------ | --------- | ---------------- | -------- |
408
- | `enableServiceabilityCheck` | `boolean` | `false` | all |
409
- | `showIndiaPostDeliveryWarning` | `boolean` | `false` | all |
410
- | `serviceabilityBlockCheckout` | `boolean` | merchant setting | all |
411
-
412
-
413
- When `enableServiceabilityCheck` is true and the buyer has a checkout session, the widget calls `checkout-addresses` with `action: "serviceability_check"`. The Edge Function calls the merchant's configured courier endpoint server-side and fails open if that endpoint is unavailable.
414
-
415
- ```tsx
416
- <CheckoutWidget
417
- apiKey={process.env.NEXT_PUBLIC_QUANTAROUTE_KEY!}
418
- merchantId={process.env.NEXT_PUBLIC_MERCHANT_ID!}
419
- supabaseFunctionBaseUrl={process.env.NEXT_PUBLIC_SUPABASE_FUNCTION_URL!}
420
- enableEmailAuth={true}
421
- enableServiceabilityCheck={true}
422
- onComplete={(addr) => console.log(addr)}
423
- />
424
- ```
425
-
426
- Merchant configuration lives on `checkout.merchants`:
427
-
428
-
429
- | Column | Meaning |
430
- | ---------------------------------- | ------------------------------------------------- |
431
- | `serviceability_enabled` | Enables the merchant courier check |
432
- | `serviceability_webhook_url` | Merchant endpoint called by QuantaRoute |
433
- | `serviceability_webhook_secret` | Shared HMAC secret for outbound calls |
434
- | `serviceability_block_checkout` | If true, `serviceable: false` blocks address save |
435
- | `show_india_post_delivery_warning` | Optional soft India Post info banner fallback |
436
-
437
-
438
- Merchant endpoint contract:
439
-
440
- ```http
441
- POST /checkout/serviceability
442
- Content-Type: application/json
443
- X-QuantaRoute-Timestamp: 1782000000000
444
- X-QuantaRoute-Signature: v1=<hmac_sha256(timestamp + "." + body)>
445
- ```
446
-
447
- ```json
448
- {
449
- "merchant_id": "merchant-uuid",
450
- "pincode": "110011",
451
- "lat": 28.6139,
452
- "lng": 77.209,
453
- "requested_at": "2026-06-21T00:00:00.000Z"
454
- }
455
- ```
456
-
457
- Expected response:
88
+ In the Next.js App Router, put the widget in a `'use client'` component. MapLibre needs the browser.
458
89
 
459
- ```json
460
- { "serviceable": true, "message": "Delivery available in 3-5 days" }
461
- ```
90
+ ### iOS and Android: Expo
462
91
 
463
- or:
92
+ This needs an [Expo development build](https://docs.expo.dev/develop/development-builds/introduction/). It doesn't run in Expo Go.
464
93
 
465
94
  ```json
466
- { "serviceable": false, "message": "We do not currently ship to this pincode" }
467
- ```
468
-
469
- If the merchant endpoint errors, times out, or returns an invalid response, checkout **fails open** and the buyer can continue. `showIndiaPostDeliveryWarning` is opt-in and only shows a soft informational banner: "Courier partners may still deliver to this pincode."
470
-
471
- ---
472
-
473
- #### Setting up Resend (required for `enableEmailAuth`)
474
-
475
- > **Hosted merchants (recommended):** If you onboarded at [developers.quantaroute.com](https://developers.quantaroute.com), QuantaRoute already runs Resend on shared infrastructure. Skip steps 1–5 below — just set `enableEmailAuth={true}` and register your domain in the portal. The steps below apply only when **self-hosting** the `checkout-email-otp` Edge Function in your own Supabase project.
476
-
477
- 1. **Create a Resend account** at [resend.com](https://resend.com) — free tier covers ~3 000 emails / month.
478
- 2. **Verify your sending domain** (e.g. `checkout.yourbrand.com` or `yourbrand.com`):
479
- - Go to **Resend → Domains → Add domain**
480
- - Add the DNS records shown (SPF, DKIM, DMARC) to your DNS provider
481
- - Wait for "Verified" status (usually under 5 minutes with Cloudflare; up to 48 h with others)
482
- 3. **Get an API key** — Resend → API Keys → Create. Restrict it to **Send access** only.
483
- 4. **Set secrets on the `checkout-email-otp` Edge Function:**
484
- In [Supabase Dashboard](https://supabase.com/dashboard) → your project → Edge Functions → Secrets:
485
-
486
- | Secret | Value |
487
- | ------------------- | -------------------------------------------------------- |
488
- | `RESEND_API_KEY` | `re_...` from Resend |
489
- | `RESEND_FROM_EMAIL` | A verified sender address, e.g. `checkout@yourbrand.com` |
490
-
491
- 5. **Deploy the Edge Function** (if not already done):
492
- ```bash
493
- supabase functions deploy checkout-email-otp --project-ref <your-project-ref> --no-verify-jwt
494
- ```
495
-
496
- **Required env vars (frontend):**
497
-
498
- ```env
499
- NEXT_PUBLIC_QUANTAROUTE_KEY=dp_...
500
- NEXT_PUBLIC_MERCHANT_ID=your-uuid-from-developer-portal
501
- NEXT_PUBLIC_SUPABASE_FUNCTION_URL=https://<project-ref>.supabase.co/functions/v1
95
+ // app.json
96
+ { "expo": { "plugins": [["@quantaroute/checkout/plugin", {
97
+ "locationPermissionText": "Allow location access to place your delivery pin."
98
+ }]] } }
502
99
  ```
503
100
 
504
- ---
505
-
506
- #### Per-merchant email template customisation
507
-
508
- Set these columns directly on your `checkout.merchants` row (SQL or Supabase Table Editor). All are optional — omitting any falls back to the QuantaRoute default.
509
-
510
-
511
- | Column | Type | Default | Effect |
512
- | ------------------------ | ------ | ---------------------------------------- | --------------------------------------------------------------------------------------------- |
513
- | `email_from_name` | `text` | `"{brand} Checkout"` | "From" display name in the inbox, e.g. `"Fabindia"` |
514
- | `email_logo_url` | `text` | *(text brand name)* | HTTPS URL of your logo (PNG/SVG, 180 × 48 px recommended) shown at the top of every OTP email |
515
- | `email_subject_template` | `text` | `"{code} is your {brand} checkout code"` | Subject line; supports `{code}` and `{brand}` placeholders |
516
-
517
-
518
- **Example SQL:**
519
-
520
- ```sql
521
- UPDATE checkout.merchants
522
- SET
523
- email_from_name = 'Fabindia',
524
- email_logo_url = 'https://cdn.fabindia.com/logo-email.png',
525
- email_subject_template = '{code} — verify your Fabindia order'
526
- WHERE id = 'your-merchant-uuid';
527
- ```
528
-
529
- ---
530
-
531
- ### Branding
532
-
533
-
534
- | Prop | Type | Default | Platform |
535
- | -------------- | -------------- | --------- | -------- |
536
- | `brandColor` | `string` (hex) | `#0ea5e9` | all |
537
- | `logoUrl` | `string` (URL) | – | all |
538
- | `headerBanner` | `ReactNode` | – | web only |
539
- | `mobilePresentation` | `'auto' \| 'sheet' \| 'card'` | `'auto'` | web |
540
- | `mobileStepLabels` | `{ auth?: string; address?: string; payment?: string }` | Mobile/Address/Pay | web |
541
-
542
-
543
101
  ```tsx
544
- <CheckoutWidget
545
- apiKey="..."
546
- brandColor="#7c3aed"
547
- logoUrl="https://yourbrand.com/logo.png"
548
- headerBanner={<p>🚚 Free shipping on orders over ₹499</p>}
549
- mobilePresentation="sheet"
550
- mobileStepLabels={{ auth: 'Mobile', address: 'Address', payment: 'Pay' }}
551
- onComplete={...}
552
- />
553
- ```
554
-
555
- ### Mobile-first storefront shells
556
-
557
- Use `mobilePresentation="sheet"` when the widget is mounted inside a mobile drawer or storefront modal. It keeps the package focused on auth, saved addresses, DigiPin verification, and optional payment while your host app owns cart-specific UI.
102
+ import { CheckoutWidget } from '@quantaroute/checkout'; // same import as on web, and no CSS
558
103
 
559
- ```tsx
560
104
  <CheckoutWidget
561
- apiKey={geocodingKey}
562
- merchantId={merchantId}
563
- supabaseFunctionBaseUrl={functionsUrl}
564
- enablePhoneAuth
565
- enablePayment={merchantPaymentMode === 'byo_razorpay'}
566
- paymentAmountPaise={cartTotalPaiseAfterDiscounts}
567
- codCartTotalPaise={cartTotalPaiseAfterDiscounts}
568
- mobilePresentation="sheet"
569
- mobileStepLabels={{ auth: 'Mobile', address: 'Address', payment: 'Pay' }}
570
- onCheckoutEvent={(event) => syncHostShellStep(event.step)}
571
- onComplete={(address) => saveDeliveryAddress(address)}
572
- onPaymentComplete={(result) => completeOrder(result)}
105
+ apiKey={process.env.EXPO_PUBLIC_QUANTAROUTE_KEY!}
106
+ onComplete={(address) => save(address)}
573
107
  />
574
108
  ```
575
109
 
576
- The host app should keep order summary, product lines, coupons, cart state, platform APIs, and checkout-button interception outside this package. Pass only the final totals and callbacks into the widget.
577
-
578
- ### Analytics (client-side)
579
-
580
-
581
- | Prop | Type | Default | Platform |
582
- | ----------------- | -------------------------------- | ------- | -------- |
583
- | `onCheckoutEvent` | `(event: CheckoutEvent) => void` | – | all |
584
-
585
-
586
- Called on every step transition. Use it to forward events to MoEngage, Clevertap, GTM, or your own backend — no server-side integration required.
587
-
588
- ```tsx
589
- <CheckoutWidget
590
- apiKey="..."
591
- onCheckoutEvent={(event) => {
592
- // event.type — e.g. 'phone_verified', 'location_confirmed', 'address_completed'
593
- // event.step — widget step the user moved INTO
594
- // event.buyerId — internal buyer UUID (after phone verification)
595
- // event.digipin — DigiPin of the confirmed location
596
- // event.timestamp — ISO 8601 timestamp
597
-
598
- // MoEngage example:
599
- Moengage.track_event(event.type, {
600
- step: event.step,
601
- buyerId: event.buyerId,
602
- digipin: event.digipin,
603
- });
604
-
605
- // GTM example:
606
- window.dataLayer?.push({ event: event.type, ...event });
607
- }}
608
- onComplete={...}
609
- />
610
- ```
611
-
612
- **All event types:**
613
-
614
-
615
- | Event | When fired | Auth channel |
616
- | ------------------------ | --------------------------------------- | ------------ |
617
- | `phone_step_viewed` | Phone entry screen rendered | Phone |
618
- | `otp_sent` | OTP dispatched via MSG91 | Phone |
619
- | `phone_verified` | SMS OTP correct; session created | Phone |
620
- | `email_step_viewed` | Email input screen rendered | Email |
621
- | `email_otp_sent` | OTP dispatched via Resend | Email |
622
- | `email_verified` | Email OTP correct; session created | Email |
623
- | `auth_skipped` | Buyer tapped "Skip" | Both |
624
- | `saved_addresses_viewed` | Saved address list rendered | – |
625
- | `saved_address_selected` | Buyer chose a saved address (skips map) | – |
626
- | `map_step_viewed` | Map pin step rendered | – |
627
- | `location_confirmed` | Buyer tapped "Confirm location" | – |
628
- | `form_step_viewed` | Address detail form rendered | – |
629
- | `address_completed` | Full address submitted | – |
630
- | `widget_reset` | Buyer tapped "Change address" | – |
631
-
632
-
633
- ---
634
-
635
- ## `CompleteAddress` output
636
-
637
- ```ts
638
- interface CompleteAddress {
639
- digipin: string; // "39J-438-TJC7"
640
- lat: number; // 28.61390
641
- lng: number; // 77.20900
642
-
643
- // Auto-filled from QuantaRoute API
644
- state: string; // "Delhi"
645
- district: string; // "New Delhi"
646
- division: string; // "New Delhi Central"
647
- locality: string; // "Nirman Bhawan SO"
648
- pincode: string; // "110011"
649
- delivery: string; // "Delivery" | "Non Delivery"
650
- country: string; // "India"
651
-
652
- // Manual entry by user
653
- flatNumber: string; // "4B"
654
- floorNumber: string; // "3rd"
655
- buildingName: string; // "Sunshine Apartments" (OSM pre-filled)
656
- streetName: string; // "MG Road, Action Area" (OSM pre-filled)
657
-
658
- formattedAddress: string; // "4B, 3rd Floor, Sunshine Apartments, MG Road, ..."
659
- label?: 'home' | 'work' | 'other'; // chosen on address form; defaults to home
660
- }
661
- ```
662
-
663
- When `enablePhoneAuth` or `enableEmailAuth` is on, the widget persists the address via `createAddress()` using this label.
664
-
665
- ```ts
666
- type AddressLabel = 'home' | 'work' | 'other';
667
- ```
668
-
669
- ---
670
-
671
- ## Advanced usage
672
-
673
- ### Use sub-components individually (web + native)
674
-
675
- ```tsx
676
- import { MapPinSelector, AddressForm, getDigiPin, isWithinIndia } from '@quantaroute/checkout';
677
-
678
- // Offline DigiPin — no API call, ~0.1 ms
679
- const dp = getDigiPin(28.6139, 77.2090); // "39J-438-TJC7"
680
- const ok = isWithinIndia(28.6139, 77.2090); // true
681
-
682
- // Custom two-step flow
683
- function MyCheckout() {
684
- const [loc, setLoc] = useState<{ lat: number; lng: number; digipin: string } | null>(null);
685
-
686
- return loc == null
687
- ? <MapPinSelector onLocationConfirm={(lat, lng, digipin) => setLoc({ lat, lng, digipin })} />
688
- : <AddressForm
689
- lat={loc.lat}
690
- lng={loc.lng}
691
- digipin={loc.digipin}
692
- apiKey="..."
693
- onAddressComplete={(addr) => console.log(addr)}
694
- onBack={() => setLoc(null)}
695
- />;
696
- }
697
- ```
698
-
699
- ### Dark mode (web)
700
-
701
- ```tsx
702
- <CheckoutWidget apiKey="..." theme="dark" onComplete={...} />
703
- ```
704
-
705
- ### Custom web theme via CSS variables
706
-
707
- ```css
708
- .qr-checkout {
709
- --qr-primary: #6366f1;
710
- --qr-primary-dark: #4f46e5;
711
- --qr-radius: 8px;
712
- --qr-font: 'Poppins', sans-serif;
713
- }
714
- ```
715
-
716
- ### India boundary overlay (web only)
717
-
718
- ```tsx
719
- <CheckoutWidget
720
- apiKey="..."
721
- indiaBoundaryUrl="https://maps.quantaroute.com/geojson/india.geojson"
722
- onComplete={...}
723
- />
724
- ```
725
-
726
- ---
727
-
728
- ## Supabase setup
110
+ Run `npx expo run:ios` or `npx expo run:android` after you add the plugin.
729
111
 
730
- > Only needed when using `**enablePhoneAuth**`. Skip this section for the basic map-only widget.
112
+ The native widget does the map, DigiPin, search, address form and COD check. Shopper sign-in, saved addresses and server-verifiable sessions are **web only**. In an app, use your own login and send the address to your backend.
731
113
 
732
- ### 1 · Get your merchant credentials
114
+ ## 3. Verify on your server
733
115
 
734
- Sign up at **[developers.quantaroute.com/onboarding/merchant](https://developers.quantaroute.com/onboarding/merchant)**. The wizard auto-provisions:
735
-
736
- - `merchant_id` — your UUID in `checkout.merchants`
737
- - Geocoding API key (for address search and reverse-geocoding)
738
- - Integration snippet with all values filled in
739
-
740
- ### 2 · Deploy Edge Functions
741
-
742
- The Edge Functions live in `supabase/functions/` inside this repo. Deploy all of them:
116
+ Anything the browser sends you can be edited by the shopper. Before you ship an order, read the session back with your **admin key**:
743
117
 
744
118
  ```bash
745
- # Address CRUD + COD eligibility
746
- supabase functions deploy checkout-addresses --project-ref <your-project-ref> --no-verify-jwt
747
-
748
- # Email OTP auth (Resend — no TRAI dependency, ship now)
749
- supabase functions deploy checkout-email-otp --project-ref <your-project-ref> --no-verify-jwt
750
-
751
- # Phone OTP auth (MSG91 + TRAI DLT — deploy now, enable when DLT is ready)
752
- supabase functions deploy checkout-otp --project-ref <your-project-ref> --no-verify-jwt
753
-
754
- # Session expiry — fires session.expired webhooks; runs every 10 min via pg_cron
755
- supabase functions deploy checkout-session-expiry --project-ref <your-project-ref> --no-verify-jwt
119
+ curl "https://ikfiewesidedxozotmrl.supabase.co/functions/v1/checkout-admin?action=session&session_id=SESSION_ID" \
120
+ -H "x-api-key: qca_YOUR_ADMIN_KEY"
756
121
  ```
757
122
 
758
- ### 3 · Set Edge Function secrets
759
-
760
- In the [Supabase Dashboard](https://supabase.com/dashboard) → your project → Edge Functions → Secrets:
761
-
762
- `**checkout-email-otp` (required for email auth):**
763
-
764
-
765
- | Secret | Value |
766
- | ------------------- | ------------------------------------------------------ |
767
- | `RESEND_API_KEY` | `re_...` — from [resend.com](https://resend.com) |
768
- | `RESEND_FROM_EMAIL` | Verified sender address, e.g. `checkout@yourbrand.com` |
769
-
123
+ The response has the session status, the buyer's email or phone, and the verified address. Compare it with the order before you fulfil.
770
124
 
771
- `**checkout-otp` (required for phone/SMS auth — set when TRAI DLT is approved):**
125
+ ## Main props (React and native)
772
126
 
127
+ | Prop | Default | Notes |
128
+ | --- | --- | --- |
129
+ | `apiKey` | required | Public `dp_` key |
130
+ | `onComplete(address)` | required | Gets a `CompleteAddress` (see below) |
131
+ | `merchantId` | – | Turns on sessions, saved addresses, COD and funnel events |
132
+ | `enableEmailAuth` / `enablePhoneAuth` | `false` | Shopper sign-in (web) |
133
+ | `onCheckoutEvent(event)` | – | One event per funnel step |
134
+ | `enableCod`, `codCartTotalPaise` | `false` | Cash-on-delivery eligibility by pincode |
135
+ | `enableServiceabilityCheck` | `false` | Calls your courier serviceability webhook |
136
+ | `brandColor`, `logoUrl`, `title`, `theme` | – | Branding: `light` or `dark` |
137
+ | `mapTheme` | `pro` | `pro`, `light` or `dark` QuantaRoute basemap (web) |
138
+ | `defaultLat`, `defaultLng`, `mapHeight` | India | Initial map view |
139
+ | `mobilePresentation` | `auto` | `sheet` inside a drawer or modal (web) |
773
140
 
774
- | Secret | Value |
775
- | ------------------- | ----------------------------------------------------------------------------------------------------------------------- |
776
- | `MSG91_AUTHKEY` | Your MSG91 AuthKey ([setup guide](./docs/MSG91_INDIA_OTP_SETUP.md)) — must match the Edge Function env var name exactly |
777
- | `MSG91_TEMPLATE_ID` | Your approved DLT OTP template ID |
141
+ All the props are typed. Hover over `CheckoutWidgetProps` in your editor to see them.
778
142
 
143
+ ## Funnel events
779
144
 
780
- ### 4 · Add your domain to the allowed list
145
+ `onCheckoutEvent` (or `onEvent` in the embed) receives `{ type, sessionId?, authChannel?, deviceType, platform, timestamp, … }`. The event types are:
781
146
 
782
- In the developer portal at **[developers.quantaroute.com/dashboard/checkout](https://developers.quantaroute.com/dashboard/checkout)**, add your storefront's domain (e.g. `yourbrand.com`). The `checkout-email-otp` and `checkout-otp` Edge Functions enforce this list — requests from unlisted origins receive `403 Origin not allowed`.
783
-
784
- ### Minimal Next.js integration
785
-
786
- #### Email OTP (available now — no TRAI paperwork)
787
-
788
- ```tsx
789
- // app/checkout/page.tsx
790
- 'use client';
791
- import dynamic from 'next/dynamic';
792
-
793
- const CheckoutWidget = dynamic(
794
- () => import('@quantaroute/checkout').then((m) => m.CheckoutWidget),
795
- { ssr: false }
796
- );
797
-
798
- export default function CheckoutPage() {
799
- return (
800
- <CheckoutWidget
801
- apiKey={process.env.NEXT_PUBLIC_QUANTAROUTE_KEY!}
802
- merchantId={process.env.NEXT_PUBLIC_MERCHANT_ID!}
803
- supabaseFunctionBaseUrl={process.env.NEXT_PUBLIC_SUPABASE_FUNCTION_URL!}
804
- enableEmailAuth={true} {/* ← email OTP via Resend */}
805
- enableSearch={true}
806
- brandColor="#your-brand-hex"
807
- logoUrl="https://yourbrand.com/logo.png"
808
- onComplete={(address) => {
809
- // address.digipin, address.formattedAddress, address.pincode, ...
810
- // → pass to your backend / payment gateway
811
- }}
812
- onCheckoutEvent={(event) => {
813
- // email_step_viewed | email_otp_sent | email_verified | address_completed | ...
814
- console.log('[checkout]', event.type, event);
815
- }}
816
- />
817
- );
818
- }
819
147
  ```
820
-
821
- #### Phone OTP (enable when TRAI DLT is approved — same widget, one prop swap)
822
-
823
- ```tsx
824
- <CheckoutWidget
825
- ...
826
- enablePhoneAuth={true} {/* swap enableEmailAuth → enablePhoneAuth when SMS is ready */}
827
- enableEmailAuth={false}
828
- />
829
- ```
830
-
831
- **Required env vars:**
832
-
833
- ```env
834
- NEXT_PUBLIC_QUANTAROUTE_KEY=dp_...
835
- NEXT_PUBLIC_MERCHANT_ID=your-uuid-from-developer-portal
836
- NEXT_PUBLIC_SUPABASE_FUNCTION_URL=https://<project-ref>.supabase.co/functions/v1
837
- ```
838
-
839
- ---
840
-
841
- ## Architecture
842
-
843
- ```
844
- @quantaroute/checkout/
845
- ├── src/
846
- │ ├── components/
847
- │ │ ├── CheckoutWidget.tsx ← web (MapLibre GL JS)
848
- │ │ ├── CheckoutWidget.native.tsx ← native (SafeAreaView)
849
- │ │ ├── MapPinSelector.tsx ← web (MapLibre marker)
850
- │ │ ├── MapPinSelector.native.tsx ← native (expo-osm-sdk OSMView)
851
- │ │ ├── AddressForm.tsx ← web (HTML form)
852
- │ │ └── AddressForm.native.tsx ← native (TextInput / Modal)
853
- │ ├── core/
854
- │ │ ├── digipin.ts ← offline DigiPin algorithm (shared, no DOM)
855
- │ │ ├── api.ts ← QuantaRoute API client (shared, fetch)
856
- │ │ └── types.ts ← TypeScript types (shared)
857
- │ ├── hooks/
858
- │ │ ├── useGeolocation.ts ← web (navigator.geolocation)
859
- │ │ ├── useGeolocation.native.ts ← native (expo-location)
860
- │ │ └── useDigiPin.ts ← shared (pure math)
861
- │ └── styles/
862
- │ ├── checkout.css ← web styles
863
- │ └── checkout.native.ts ← native StyleSheet.create()
864
- ├── expo-plugin.js ← Expo config plugin
865
- ├── babel.config.js ← Metro/Babel config
866
- └── dist/ ← web build output (Vite)
867
- ```
868
-
869
- **Platform resolution:**
870
-
871
- ```
872
- Metro (Expo app) → "react-native" export → src/index.ts
873
- → MapPinSelector.native.tsx (expo-osm-sdk)
874
- → useGeolocation.native.ts (expo-location)
875
-
876
- Vite / Webpack / Next.js → "import" export → dist/lib/quantaroute-checkout.es.js
877
- → MapPinSelector.tsx (MapLibre GL JS)
878
- → useGeolocation.ts (navigator.geolocation)
879
- ```
880
-
881
- ---
882
-
883
- ## Map tile license
884
-
885
- Uses **Carto Positron** vector tiles (Carto Voyager on native):
886
-
887
- - Free for commercial use — attribution required
888
- - Attribution: `© OpenStreetMap contributors © CARTO`
889
- - No API key required for Carto basemaps
890
-
891
- ---
892
-
893
- ## DigiPin license
894
-
895
- The offline DigiPin algorithm is the official India Post implementation:
896
-
897
- - **Source:** [github.com/INDIAPOST-gov/digipin](https://github.com/INDIAPOST-gov/digipin)
898
- - **Developed by:** India Post, IIT Hyderabad, ISRO NRSC
899
- - **License:** Apache 2.0
900
-
901
- ---
902
-
903
- ## Documentation
904
-
905
-
906
- | Doc | Description |
907
- | ---------------------------------------------------------- | ------------------------------------------------ |
908
- | [Changelog](./CHANGELOG.md) | Version history and release notes |
909
- | [Checkout roadmap](./docs/CHECKOUT_ROADMAP.md) | Feature phases and implementation status |
910
- | [Merchant onboarding](./docs/merchant-onboarding.md) | Payment modes A/B/C, Razorpay setup (Mode B) |
911
- | [BYO payment gateway](./docs/byo-payment-gateway.md) | Mode A — PayU/Cashfree/Paytm/Shopify integration |
912
- | [Hosted payments roadmap](./docs/hosted-payments-roadmap.md) | Mode C — QuantaRoute Payments (coming soon) |
913
- | [Razorpay E2E setup](./docs/razorpay-e2e-setup.md) | Test-mode verification checklist (Mode B) |
914
- | [Customer migration playbook](./docs/customer-migration-playbook.md) | Merchant-facing import + lazy DigiPin story |
915
- | [Portal payment wizard spec](./docs/portal-payment-wizard-spec.md) | Developer portal — `/checkout/payments` spec |
916
- | [Portal migration wizard spec](./docs/portal-migration-wizard-spec.md) | Developer portal — `/checkout/migrate` spec |
917
- | [MSG91 OTP setup](./docs/MSG91_INDIA_OTP_SETUP.md) | India SMS / DLT configuration for phone OTP |
918
-
919
-
920
- ---
921
-
922
- ## Security & integration
923
-
924
- ### What ships in the npm package
925
-
926
- The published tarball contains **no secrets** — only client-side widget code:
927
-
928
-
929
- | Included | Excluded |
930
- | ------------------------------------------ | ----------------------------------------- |
931
- | `dist/lib/*.js` (Terser-minified ES + UMD) | `supabase/`, Edge Functions, migrations |
932
- | `dist/lib/index.d.ts` | `demo/`, `docs/`, `openapi.yaml`, `.env*` |
933
- | `dist/style.css` | `vite.config.ts`, dev tooling |
934
- | `src/` (required for React Native / Metro) | `node_modules/` |
935
-
936
-
937
- - **Geocoding `apiKey`** (`dp_…`) is designed for the browser bundle — rate-limited, scoped to your merchant plan.
938
- - **Admin API key** (`qca_…`) must **never** ship in frontend code. Use it server-side only (`x-api-key` on `checkout-admin`).
939
- - OTP delivery (Resend) and session minting run on **QuantaRoute-hosted Edge Functions**, not inside the npm bundle.
940
- - **Consistent email OTP:** the same 6-digit code is stored per `(email, merchant)` and reused for up to **10 successful logins** (not single-use). Repeat send requests skip Resend when the code is still active. This reduces email cost but is weaker than banking-grade OTP — document for your shoppers if required by policy.
941
-
942
- Verify before every publish:
943
-
944
- ```bash
945
- npm run type-check && npm run build:lib
946
- npm pack --dry-run # confirm 36 files, no .env / supabase / demo
947
- rg -i 're_|sk_|service.role|password' dist/ # should return no matches
148
+ email_step_viewed email_otp_sent email_verified phone_step_viewed otp_sent phone_verified auth_skipped
149
+ saved_addresses_viewed saved_address_selected map_step_viewed location_confirmed
150
+ form_step_viewed address_completed address_risk_scored widget_reset session_abandoned
948
151
  ```
949
152
 
950
- ### Merchant integration checklist (email OTP on web)
153
+ The same funnel appears in your dashboard with no extra code.
951
154
 
952
- Use this when embedding `@quantaroute/checkout` on a **hosted QuantaRoute** storefront (onboarded via [developers.quantaroute.com](https://developers.quantaroute.com)):
155
+ ## `CompleteAddress`
953
156
 
954
- 1. **Onboard** — complete [merchant onboarding](https://developers.quantaroute.com/onboarding/merchant); copy `merchantId`, geocoding `apiKey`, and `supabaseFunctionBaseUrl` from the wizard or [Checkout dashboard](https://developers.quantaroute.com/dashboard/checkout).
955
- 2. **Install** — `npm install @quantaroute/checkout maplibre-gl` (+ CSS imports).
956
- 3. **Env vars** — expose only public values (`NEXT_PUBLIC_QUANTAROUTE_KEY`, `NEXT_PUBLIC_MERCHANT_ID`, `NEXT_PUBLIC_SUPABASE_FUNCTION_URL`). Never commit `.env` to git.
957
- 4. **Allowed domains** — in the developer portal, add every origin that will host the widget (e.g. `yourbrand.com`, `www.yourbrand.com`, `*.yourbrand.com` for subdomains). Both `checkout-otp` and `checkout-email-otp` reject requests from unlisted origins.
958
- 5. **Enable auth** — set `enableEmailAuth={true}` with `merchantId` and `supabaseFunctionBaseUrl`. Auth is **opt-in** and **web-only** today (React Native widget does not include the email OTP steps).
959
- 6. **Optional branding** — `brandColor`, `logoUrl`; per-merchant email template columns (`email_from_name`, `email_logo_url`, `email_subject_template`) in the portal.
960
- 7. **Handle completion** — implement `onComplete` to pass the `CompleteAddress` to your cart / payment gateway. Built-in payment (`enablePayment`) and COD (`enableCod`) are separate opt-in props.
961
-
962
- > **Resend is platform-managed for hosted merchants.** QuantaRouHMACte operates the shared `checkout-email-otp` Edge Function and Resend sender (`RESEND_API_KEY`, `RESEND_FROM_EMAIL`). Merchants do **not** need their own Resend account for the hosted MVP. See [Setting up Resend](#setting-up-resend-required-for-enableemailauth) only if you self-host the Edge Functions.
963
-
964
- ### Platform responsibilities (QuantaRoute)
965
-
966
-
967
- | Item | Owner |
968
- | -------------------------------------------------------------------------------------------------------------- | ----------------------------------- |
969
- | Deploy & operate `checkout-email-otp`, `checkout-addresses`, `checkout-session-expiry` | QuantaRoute |
970
- | `RESEND_API_KEY`, `RESEND_FROM_EMAIL`, Supabase service role | QuantaRoute (Edge Function secrets) |
971
- | `checkout.merchants` provisioning, `allowed_domains`, email template columns | QuantaRoute portal + DB |
972
- | Buyer OTP consistent reuse (10 logins per code), fresh-code limit (3 / 24h), verify lockout (5 fails → 15 min) | Edge Function |
973
- | Geocoding API key issuance & plan rate limits | QuantaRoute |
974
-
975
-
976
- ### Maintainer publish checklist
977
-
978
- When publishing a new version to npm (maintainers only):
979
-
980
- 1. Enable **npm 2FA** on the `@quantaroute` org account (publish + modify).
981
- 2. Run `npm run type-check && npm run build:lib && npm pack --dry-run` — confirm tarball contents.
982
- 3. Confirm no `.env`, `.pem`, or `supabase/` paths in the pack list.
983
- 4. Publish from a **clean git tag** with provenance: `npm publish --provenance --access public`.
984
- 5. Do **not** bump version in the same change unless releasing; current version is `1.4.5`.
985
-
986
- ---
987
-
988
- ## Development
989
-
990
- ```bash
991
- git clone https://github.com/quantaroute/checkout.git
992
- cd quantaroute-checkout
993
- npm install
994
-
995
- # Web dev server
996
- npm run dev # http://localhost:5173
997
-
998
- # Type checks
999
- npm run type-check # web (Vite tsconfig)
1000
- npm run type-check:native # native (RN tsconfig)
1001
-
1002
- # Build
1003
- npm run build:lib # library → dist/lib/
1004
- npm run build # library + demo
157
+ ```ts
158
+ {
159
+ digipin: '39J-438-TJC7', lat: 28.6139, lng: 77.209,
160
+ state: 'Delhi', district: 'New Delhi', locality: 'Nirman Bhawan SO', pincode: '110011',
161
+ delivery: 'Delivery', country: 'India',
162
+ flatNumber: '4B', floorNumber: '3rd', buildingName: 'Sunshine Apartments', streetName: 'MG Road',
163
+ formattedAddress: '4B, 3rd Floor, Sunshine Apartments, MG Road, …',
164
+ label: 'home', // 'home' | 'work' | 'other'
165
+ // The embed also returns sessionId and addressId.
166
+ }
1005
167
  ```
1006
168
 
1007
- **Native demo:**
1008
-
1009
- ```bash
1010
- cd demo-native
1011
- npm install
1012
- npx expo run:ios # requires Xcode
1013
- npx expo run:android # requires Android Studio
1014
- ```
169
+ ## Security
1015
170
 
1016
- ---
171
+ - Only public values go in the browser or app: the merchant ID and the `dp_` key. The `qca_` admin key belongs on your server only.
172
+ - Sign-in only works from domains on your allowed list.
173
+ - Verify the session on your server before you trust an address. See [step 3](#3-verify-on-your-server).
174
+ - The npm package has no secrets and no server code.
1017
175
 
1018
- ## Changelog
176
+ ## Maps
1019
177
 
1020
- See [CHANGELOG.md](./CHANGELOG.md) for version history. Current release: **v1.4.5**.
178
+ Maps use the QuantaRoute India basemap at `maps.quantaroute.com`, with your `dp_` key. Keep the "© OpenStreetMap contributors" attribution visible. In the native widget, when no key is given, the map falls back to Carto Positron.
1021
179
 
1022
- ---
180
+ ## Links
1023
181
 
1024
- **Made with ❤️ in India · Powered by [QuantaRoute](https://quantaroute.com)**
182
+ - [Developer portal and docs](https://developers.quantaroute.com)
183
+ - [Changelog](./CHANGELOG.md)
184
+ - The DigiPin algorithm is [India Post's](https://github.com/INDIAPOST-gov/digipin) (Apache 2.0)
185
+ - License: MIT