@tagadapay/plugin-sdk 2.4.34 → 2.4.36

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,623 +1,623 @@
1
- # TagadaPay Plugin SDK
2
-
3
- A comprehensive React SDK for building plugins on the TagadaPay platform. Create custom checkout experiences, landing pages, and interactive components with automatic configuration injection and advanced routing capabilities.pnpm
4
-
5
- ## 📚 Documentation
6
-
7
- ### Core APIs
8
-
9
- - **[useCheckout](./docs/README-useCheckout.md)** - Checkout state management and flow control
10
- - **[setCheckoutInfo](./docs/README-setCheckoutInfo.md)** - Customer information and validation
11
- - **[useOffers](./docs/README-useOffers.md)** - Dynamic pricing and promotional offers
12
- - **[usePromotionCodes](./docs/README-usePromotionCodes.md)** - Promotion code management
13
- - **[Money utilities](./docs/README-money.md)** - Currency formatting and calculations
14
- - **[URL utilities](./docs/README-urlUtils.md)** - Navigation and routing helpers
15
-
16
- ### Plugin Development
17
-
18
- - **[Plugin Configuration](./docs/PLUGIN_CONFIG.md)** - How to access store context, config, and branding
19
- - **[Initialization Modes](#-initialization-modes)** - Choose between blocking and non-blocking initialization
20
- - **[Google Autocomplete](./docs/README-google-autocomplete.md)** - Address autocomplete with Google Places API
21
- - **[ISO Data](./docs/README-iso-data.md)** - Country and region data with Google integration
22
-
23
- ### Examples
24
-
25
- - **[Vite Checkout Demo](../checkout-vite)** - Complete checkout implementation
26
-
27
- ## 🏗️ Building a Plugin
28
-
29
- ### Plugin Structure
30
-
31
- Every TagadaPay plugin follows this simple structure:
32
-
33
- ```
34
- my-plugin/
35
- ├── plugin.manifest.json # Plugin metadata & routing
36
- ├── .local.json # Local dev config (auto-injected in production)
37
- ├── config/ # Optional deployment configs
38
- │ ├── theme-green.json # Config variant A
39
- │ └── theme-blue.json # Config variant B
40
- ├── src/
41
- │ └── App.tsx # Your plugin code
42
- └── dist/ # Built plugin files
43
- ```
44
-
45
- ### Configuration Flow
46
-
47
- ```mermaid
48
- graph TD
49
- A[🛠️ Local Development] --> B[.local.json]
50
- A --> C[config/*.json]
51
- B --> D[usePluginConfig()]
52
- C --> D
53
-
54
- E[🚀 Production] --> F[Platform Injection]
55
- F --> G[HTTP Headers & Meta Tags]
56
- G --> D
57
-
58
- D --> H[Your Plugin Component]
59
-
60
- style A fill:#e1f5fe
61
- style E fill:#f3e5f5
62
- style D fill:#fff3e0
63
- style H fill:#e8f5e8
64
- ```
65
-
66
- ### Essential Files
67
-
68
- #### 1. **`plugin.manifest.json`** - Plugin Metadata
69
-
70
- ```json
71
- {
72
- "pluginId": "my-awesome-plugin",
73
- "name": "My Awesome Plugin",
74
- "version": "1.0.0",
75
- "mode": "direct-mode",
76
- "router": {
77
- "basePath": "/",
78
- "matcher": ".*",
79
- "excluder": "/checkout"
80
- }
81
- }
82
- ```
83
-
84
- #### 2. **`.local.json`** - Local Development Context
85
-
86
- ```json
87
- {
88
- "storeId": "store_abc123",
89
- "accountId": "acc_xyz789",
90
- "basePath": "/"
91
- }
92
- ```
93
-
94
- > ⚠️ **Auto-managed**: This file is only for local dev. In production, the platform injects this data automatically.
95
-
96
- #### 3. **`config/my-theme.json`** - Optional Deployment Config
97
-
98
- ```json
99
- {
100
- "configName": "green-theme",
101
- "branding": {
102
- "primaryColor": "#059669",
103
- "companyName": "My Store",
104
- "logoUrl": "https://example.com/logo.png"
105
- },
106
- "features": {
107
- "enableChat": true,
108
- "maxItems": 10
109
- }
110
- }
111
- ```
112
-
113
- > 📝 **Note**: Config can contain any keys you need - the SDK doesn't enforce a specific structure.
114
-
115
- ## 🚀 Quick Start
116
-
117
- ### Installation
118
-
119
- ```bash
120
- npm install @tagadapay/plugin-sdk
121
- ```
122
-
123
- ### Basic Plugin Setup
124
-
125
- ```tsx
126
- import React from 'react';
127
- import {
128
- TagadaProvider,
129
- usePluginConfig,
130
- useGoogleAutocomplete,
131
- useISOData,
132
- } from '@tagadapay/plugin-sdk/react';
133
-
134
- function MyPlugin() {
135
- const { storeId, accountId, basePath, config, loading } = usePluginConfig();
136
-
137
- // Optional: Add address autocomplete
138
- const { searchPlaces, predictions } = useGoogleAutocomplete({
139
- apiKey: config?.googleMapsApiKey || 'YOUR_API_KEY',
140
- });
141
-
142
- // Optional: Add country/region data
143
- const { countries } = useISOData('en');
144
-
145
- if (loading) return <div>Loading...</div>;
146
-
147
- return (
148
- <div style={{ '--primary': config?.branding?.primaryColor }}>
149
- <h1>Welcome to {config?.branding?.companyName}</h1>
150
- <p>Store: {storeId}</p>
151
- <p>Base Path: {basePath}</p>
152
- <p>Available Countries: {Object.keys(countries).length}</p>
153
- </div>
154
- );
155
- }
156
-
157
- // Wrap your plugin with TagadaProvider
158
- function App() {
159
- return (
160
- <TagadaProvider>
161
- <MyPlugin />
162
- </TagadaProvider>
163
- );
164
- }
165
-
166
- export default App;
167
- ```
168
-
169
- ## 🚀 Initialization Modes
170
-
171
- The TagadaProvider supports two initialization modes to give you control over when your components render:
172
-
173
- ### Non-Blocking Mode (Default - Recommended)
174
-
175
- ```tsx
176
- <TagadaProvider>
177
- {/* Children render immediately after config loads */}
178
- <YourApp />
179
- </TagadaProvider>
180
-
181
- // OR explicitly
182
- <TagadaProvider blockUntilSessionReady={false}>
183
- <YourApp />
184
- </TagadaProvider>
185
- ```
186
-
187
- **Flow:**
188
-
189
- 1. **Phase 1 & 2** ✅ Plugin config loads → Children render immediately
190
- 2. **Phase 3** 🔄 Session initialization runs in background
191
- 3. **API calls** 🔄 Hooks automatically wait for session to be ready
192
-
193
- **Benefits:**
194
-
195
- - ⚡ **Faster rendering** - UI appears immediately
196
- - 🎯 **Better UX** - Show loading states while session initializes
197
- - 🔄 **Automatic waiting** - Hooks handle session timing for you
198
-
199
- ### Blocking Mode (Legacy Behavior)
200
-
201
- ```tsx
202
- <TagadaProvider blockUntilSessionReady={true}>
203
- {/* Children render only after ALL initialization completes */}
204
- <YourApp />
205
- </TagadaProvider>
206
- ```
207
-
208
- **Flow:**
209
-
210
- 1. **All Phases** ⏳ Config + Session must complete before children render
211
- 2. **API calls** ✅ Work immediately (no waiting needed)
212
-
213
- **Use when:**
214
-
215
- - 🔄 **Migrating** from older SDK versions
216
- - 🎯 **Simple apps** that don't need progressive loading
217
-
218
- ### Console Logs
219
-
220
- The SDK logs help you understand which mode you're using:
221
-
222
- **Non-blocking mode:**
223
-
224
- ```
225
- ✅ Phase 1 & 2 Complete - Plugin config loaded
226
- 🚀 Non-blocking mode: Children can now render - Phase 3 will continue in background
227
- 🔄 [useCheckout] Waiting for session initialization to complete...
228
- ✅ Phase 3 Complete - Session initialization completed successfully
229
- ✅ [useCheckout] Session initialized, proceeding with checkout init
230
- ```
231
-
232
- **Blocking mode:**
233
-
234
- ```
235
- ✅ Phase 1 & 2 Complete - Plugin config loaded
236
- ⏳ Blocking mode: Children will render after Phase 3 completes
237
- ✅ Phase 3 Complete - Session initialization completed successfully
238
- ```
239
-
240
- ### TagadaProvider API
241
-
242
- ```tsx
243
- interface TagadaProviderProps {
244
- children: ReactNode;
245
- environment?: 'local' | 'development' | 'staging' | 'production';
246
- customApiConfig?: Partial<EnvironmentConfig>;
247
- debugMode?: boolean;
248
- localConfig?: string; // LOCAL DEV ONLY: Override config variant
249
- blockUntilSessionReady?: boolean; // Default: false
250
- }
251
- ```
252
-
253
- | Prop | Type | Default | Description |
254
- | ------------------------ | ----------- | -------------------- | ------------------------------ |
255
- | `children` | `ReactNode` | - | Your plugin components |
256
- | `environment` | `string` | auto-detect | Override environment detection |
257
- | `customApiConfig` | `object` | - | Custom API configuration |
258
- | `debugMode` | `boolean` | auto (false in prod) | Enable debug features |
259
- | `localConfig` | `string` | `'default'` | Config variant for local dev |
260
- | `blockUntilSessionReady` | `boolean` | `false` | Use legacy blocking behavior |
261
-
262
- > **Version Compatibility:** The `blockUntilSessionReady` option was added in v2.3.0. For older versions, the blocking behavior was the default and only option.
263
-
264
- ### Development vs Production
265
-
266
- | Environment | Store/Account ID | Deployment Config | How it Works |
267
- | -------------- | ---------------- | ----------------- | ------------------ |
268
- | **Local Dev** | `.local.json` | `config/*.json` | Files on disk |
269
- | **Production** | HTTP Headers | Meta Tags | Platform injection |
270
-
271
- ```tsx
272
- // ✅ ALWAYS use hooks - works in both environments
273
- const { storeId, accountId, basePath, config } = usePluginConfig();
274
-
275
- // ❌ NEVER access directly
276
- // const config = window.__PLUGIN_CONFIG__; // Doesn't exist!
277
- ```
278
-
279
- ## 🎯 Key Features
280
-
281
- ### 🔧 **Plugin Configuration System**
282
-
283
- - **Automatic Context Injection** - Store ID, Account ID, and custom config
284
- - **Development & Production** - Seamless environment switching
285
- - **Generic Configuration** - Support for any JSON structure
286
- - **React Hooks** - Clean, type-safe configuration access
287
-
288
- ### 💳 **Payment Processing**
289
-
290
- - Secure tokenized payments
291
- - Multiple payment method support
292
- - Real-time validation
293
- - PCI compliance
294
-
295
- ### 🌍 **Address & Location**
296
-
297
- - **Google Places Autocomplete** - Automatic API loading and address parsing
298
- - **ISO Country/Region Data** - Complete ISO 3166-1/3166-2 database
299
- - **Address Validation** - Structured component extraction
300
- - **Multi-language Support** - 11+ languages for international users
301
-
302
- ### 🛒 **E-commerce Features**
303
-
304
- - Dynamic pricing and promotional offers
305
- - Cart management and tax calculations
306
- - Currency conversion and formatting
307
- - Customer profile management
308
-
309
- ### 🎨 **UI & Development**
310
-
311
- - Pre-built React components
312
- - Customizable themes with configuration
313
- - Mobile-optimized and accessible
314
- - TypeScript support throughout
315
-
316
- ## 📖 API Reference
317
-
318
- ### Core Hooks
319
-
320
- #### useCheckout()
321
-
322
- Primary hook for checkout state management.
323
-
324
- ```typescript
325
- const {
326
- customer, // Customer information
327
- cart, // Shopping cart state
328
- payment, // Payment details
329
- shipping, // Shipping information
330
- loading, // Loading states
331
- errors, // Error handling
332
- } = useCheckout();
333
- ```
334
-
335
- #### useOffers()
336
-
337
- Hook for managing dynamic offers and pricing.
338
-
339
- ```typescript
340
- const {
341
- offers, // Available offers
342
- applyOffer, // Apply offer function
343
- removeOffer, // Remove offer function
344
- total, // Calculated total
345
- } = useOffers();
346
- ```
347
-
348
- #### usePromotionCodes()
349
-
350
- Hook for managing promotion codes in checkout sessions.
351
-
352
- ```typescript
353
- const {
354
- appliedPromotions, // Currently applied promotions
355
- isLoading, // Loading state
356
- isApplying, // Applying promotion state
357
- applyPromotionCode, // Apply promotion code function
358
- removePromotionCode, // Remove promotion function
359
- validatePromotionCode, // Validate code without applying
360
- } = usePromotionCodes({ checkoutSessionId });
361
- ```
362
-
363
- ### Utility Functions
364
-
365
- #### setCheckoutInfo()
366
-
367
- Update checkout information with validation.
368
-
369
- ```typescript
370
- await setCheckoutInfo({
371
- customer: {
372
- email: 'user@example.com',
373
- firstName: 'John',
374
- lastName: 'Doe',
375
- },
376
- payment: {
377
- method: 'card',
378
- token: 'pm_token_123',
379
- },
380
- });
381
- ```
382
-
383
- #### Money utilities
384
-
385
- Format and calculate monetary values.
386
-
387
- ```typescript
388
- import { formatMoney, convertCurrency } from '@tagadapay/plugin-sdk';
389
-
390
- const formatted = formatMoney(2999, 'USD'); // "$29.99"
391
- const converted = convertCurrency(2999, 'USD', 'EUR'); // 2699
392
- ```
393
-
394
- ## 🛠️ Development
395
-
396
- ### Local Development
397
-
398
- ```bash
399
- # Install dependencies
400
- npm install
401
-
402
- # Start development server
403
- npm run dev
404
-
405
- # Build for production
406
- npm run build
407
- ```
408
-
409
- ### Testing
410
-
411
- ```bash
412
- # Run tests
413
- npm test
414
-
415
- # Run tests with coverage
416
- npm run test:coverage
417
- ```
418
-
419
- ### Linting
420
-
421
- ```bash
422
- # Check code style
423
- npm run lint
424
-
425
- # Fix linting issues
426
- npm run lint:fix
427
- ```
428
-
429
- ## 📦 Build & Deploy
430
-
431
- ### Building Your Plugin
432
-
433
- ```bash
434
- # Build optimized bundle
435
- npm run build
436
-
437
- # Analyze bundle size
438
- npm run analyze
439
- ```
440
-
441
- ### Deployment
442
-
443
- ```bash
444
- # Deploy using TagadaPay CLI
445
- npx @tagadapay/plugin-cli deploy
446
-
447
- # Deploy specific environment
448
- npx @tagadapay/plugin-cli deploy --env production
449
- ```
450
-
451
- ## 🔧 Configuration
452
-
453
- ### Plugin Configuration
454
-
455
- ```json
456
- {
457
- "name": "My Checkout Plugin",
458
- "version": "1.0.0",
459
- "description": "Custom checkout experience",
460
- "main": "dist/index.js",
461
- "tagadapay": {
462
- "type": "checkout",
463
- "mode": "direct",
464
- "framework": "react"
465
- }
466
- }
467
- ```
468
-
469
- ## 🔐 Security
470
-
471
- ### Best Practices
472
-
473
- - Never store sensitive payment data
474
- - Always validate user inputs
475
- - Use HTTPS in production
476
- - Implement proper error handling
477
- - Follow PCI DSS guidelines
478
-
479
- ### Token Management
480
-
481
- ```typescript
482
- // ✅ Good: Use tokenized payments
483
- const paymentToken = await tokenizePayment(cardData);
484
- await processPayment({ token: paymentToken });
485
-
486
- // ❌ Bad: Never store raw card data
487
- // const cardNumber = '4111111111111111'; // Don't do this
488
- ```
489
-
490
- ## 📱 Mobile Optimization
491
-
492
- ### Responsive Design
493
-
494
- ```css
495
- .checkout-container {
496
- max-width: 600px;
497
- margin: 0 auto;
498
- padding: 16px;
499
- }
500
-
501
- @media (max-width: 768px) {
502
- .checkout-container {
503
- padding: 8px;
504
- }
505
-
506
- .checkout-form {
507
- font-size: 16px; /* Prevent zoom on iOS */
508
- }
509
- }
510
- ```
511
-
512
- ### Touch Interactions
513
-
514
- ```typescript
515
- const handleTouchStart = (e) => {
516
- // Optimize for touch devices
517
- e.preventDefault();
518
- // Handle touch interaction
519
- };
520
- ```
521
-
522
- ## 🌐 Internationalization
523
-
524
- ### Multi-language Support
525
-
526
- ```typescript
527
- import { useTranslation } from '@tagadapay/plugin-sdk';
528
-
529
- function CheckoutForm() {
530
- const { t } = useTranslation();
531
-
532
- return (
533
- <form>
534
- <label>{t('checkout.email')}</label>
535
- <input type="email" placeholder={t('checkout.email_placeholder')} />
536
- </form>
537
- );
538
- }
539
- ```
540
-
541
- ### Currency Support
542
-
543
- ```typescript
544
- import { useCurrency } from '@tagadapay/plugin-sdk';
545
-
546
- function PriceDisplay({ amount }) {
547
- const { formatPrice, currency } = useCurrency();
548
-
549
- return <span>{formatPrice(amount, currency)}</span>;
550
- }
551
- ```
552
-
553
- ## 📊 Analytics & Monitoring
554
-
555
- ### Event Tracking
556
-
557
- ```typescript
558
- import { trackEvent } from '@tagadapay/plugin-sdk';
559
-
560
- // Track user interactions
561
- trackEvent('checkout_started', {
562
- product_id: 'prod_123',
563
- value: 2999,
564
- currency: 'USD',
565
- });
566
-
567
- // Track conversions
568
- trackEvent('purchase_completed', {
569
- transaction_id: 'txn_456',
570
- value: 2999,
571
- currency: 'USD',
572
- });
573
- ```
574
-
575
- ### Performance Monitoring
576
-
577
- ```typescript
578
- import { performance } from '@tagadapay/plugin-sdk';
579
-
580
- // Measure load times
581
- performance.mark('checkout-start');
582
- // ... checkout logic
583
- performance.mark('checkout-end');
584
- performance.measure('checkout-duration', 'checkout-start', 'checkout-end');
585
- ```
586
-
587
- ## 🤝 Contributing
588
-
589
- ### Development Setup
590
-
591
- ```bash
592
- # Clone the repository
593
- git clone https://github.com/tagadapay/plugin-sdk.git
594
-
595
- # Install dependencies
596
- npm install
597
-
598
- # Start development
599
- npm run dev
600
- ```
601
-
602
- ### Submitting Changes
603
-
604
- 1. Fork the repository
605
- 2. Create a feature branch
606
- 3. Make your changes
607
- 4. Add tests
608
- 5. Submit a pull request
609
-
610
- ## 📄 License
611
-
612
- MIT License - see [LICENSE](./LICENSE) for details.
613
-
614
- ## 🆘 Support
615
-
616
- - **Documentation**: [docs.tagadapay.com](https://docs.tagadapay.com)
617
- - **Discord**: [discord.gg/tagadapay](https://discord.gg/tagadapay)
618
- - **Email**: support@tagadapay.com
619
- - **GitHub Issues**: [github.com/tagadapay/plugin-sdk/issues](https://github.com/tagadapay/plugin-sdk/issues)
620
-
621
- ---
622
-
623
- Built with ❤️ by the TagadaPay team
1
+ # TagadaPay Plugin SDK
2
+
3
+ A comprehensive React SDK for building plugins on the TagadaPay platform. Create custom checkout experiences, landing pages, and interactive components with automatic configuration injection and advanced routing capabilities.pnpm
4
+
5
+ ## 📚 Documentation
6
+
7
+ ### Core APIs
8
+
9
+ - **[useCheckout](./docs/README-useCheckout.md)** - Checkout state management and flow control
10
+ - **[setCheckoutInfo](./docs/README-setCheckoutInfo.md)** - Customer information and validation
11
+ - **[useOffers](./docs/README-useOffers.md)** - Dynamic pricing and promotional offers
12
+ - **[usePromotionCodes](./docs/README-usePromotionCodes.md)** - Promotion code management
13
+ - **[Money utilities](./docs/README-money.md)** - Currency formatting and calculations
14
+ - **[URL utilities](./docs/README-urlUtils.md)** - Navigation and routing helpers
15
+
16
+ ### Plugin Development
17
+
18
+ - **[Plugin Configuration](./docs/PLUGIN_CONFIG.md)** - How to access store context, config, and branding
19
+ - **[Initialization Modes](#-initialization-modes)** - Choose between blocking and non-blocking initialization
20
+ - **[Google Autocomplete](./docs/README-google-autocomplete.md)** - Address autocomplete with Google Places API
21
+ - **[ISO Data](./docs/README-iso-data.md)** - Country and region data with Google integration
22
+
23
+ ### Examples
24
+
25
+ - **[Vite Checkout Demo](../checkout-vite)** - Complete checkout implementation
26
+
27
+ ## 🏗️ Building a Plugin
28
+
29
+ ### Plugin Structure
30
+
31
+ Every TagadaPay plugin follows this simple structure:
32
+
33
+ ```
34
+ my-plugin/
35
+ ├── plugin.manifest.json # Plugin metadata & routing
36
+ ├── .local.json # Local dev config (auto-injected in production)
37
+ ├── config/ # Optional deployment configs
38
+ │ ├── theme-green.json # Config variant A
39
+ │ └── theme-blue.json # Config variant B
40
+ ├── src/
41
+ │ └── App.tsx # Your plugin code
42
+ └── dist/ # Built plugin files
43
+ ```
44
+
45
+ ### Configuration Flow
46
+
47
+ ```mermaid
48
+ graph TD
49
+ A[🛠️ Local Development] --> B[.local.json]
50
+ A --> C[config/*.json]
51
+ B --> D[usePluginConfig()]
52
+ C --> D
53
+
54
+ E[🚀 Production] --> F[Platform Injection]
55
+ F --> G[HTTP Headers & Meta Tags]
56
+ G --> D
57
+
58
+ D --> H[Your Plugin Component]
59
+
60
+ style A fill:#e1f5fe
61
+ style E fill:#f3e5f5
62
+ style D fill:#fff3e0
63
+ style H fill:#e8f5e8
64
+ ```
65
+
66
+ ### Essential Files
67
+
68
+ #### 1. **`plugin.manifest.json`** - Plugin Metadata
69
+
70
+ ```json
71
+ {
72
+ "pluginId": "my-awesome-plugin",
73
+ "name": "My Awesome Plugin",
74
+ "version": "1.0.0",
75
+ "mode": "direct-mode",
76
+ "router": {
77
+ "basePath": "/",
78
+ "matcher": ".*",
79
+ "excluder": "/checkout"
80
+ }
81
+ }
82
+ ```
83
+
84
+ #### 2. **`.local.json`** - Local Development Context
85
+
86
+ ```json
87
+ {
88
+ "storeId": "store_abc123",
89
+ "accountId": "acc_xyz789",
90
+ "basePath": "/"
91
+ }
92
+ ```
93
+
94
+ > ⚠️ **Auto-managed**: This file is only for local dev. In production, the platform injects this data automatically.
95
+
96
+ #### 3. **`config/my-theme.json`** - Optional Deployment Config
97
+
98
+ ```json
99
+ {
100
+ "configName": "green-theme",
101
+ "branding": {
102
+ "primaryColor": "#059669",
103
+ "companyName": "My Store",
104
+ "logoUrl": "https://example.com/logo.png"
105
+ },
106
+ "features": {
107
+ "enableChat": true,
108
+ "maxItems": 10
109
+ }
110
+ }
111
+ ```
112
+
113
+ > 📝 **Note**: Config can contain any keys you need - the SDK doesn't enforce a specific structure.
114
+
115
+ ## 🚀 Quick Start
116
+
117
+ ### Installation
118
+
119
+ ```bash
120
+ npm install @tagadapay/plugin-sdk
121
+ ```
122
+
123
+ ### Basic Plugin Setup
124
+
125
+ ```tsx
126
+ import React from 'react';
127
+ import {
128
+ TagadaProvider,
129
+ usePluginConfig,
130
+ useGoogleAutocomplete,
131
+ useISOData,
132
+ } from '@tagadapay/plugin-sdk/react';
133
+
134
+ function MyPlugin() {
135
+ const { storeId, accountId, basePath, config, loading } = usePluginConfig();
136
+
137
+ // Optional: Add address autocomplete
138
+ const { searchPlaces, predictions } = useGoogleAutocomplete({
139
+ apiKey: config?.googleMapsApiKey || 'YOUR_API_KEY',
140
+ });
141
+
142
+ // Optional: Add country/region data
143
+ const { countries } = useISOData('en');
144
+
145
+ if (loading) return <div>Loading...</div>;
146
+
147
+ return (
148
+ <div style={{ '--primary': config?.branding?.primaryColor }}>
149
+ <h1>Welcome to {config?.branding?.companyName}</h1>
150
+ <p>Store: {storeId}</p>
151
+ <p>Base Path: {basePath}</p>
152
+ <p>Available Countries: {Object.keys(countries).length}</p>
153
+ </div>
154
+ );
155
+ }
156
+
157
+ // Wrap your plugin with TagadaProvider
158
+ function App() {
159
+ return (
160
+ <TagadaProvider>
161
+ <MyPlugin />
162
+ </TagadaProvider>
163
+ );
164
+ }
165
+
166
+ export default App;
167
+ ```
168
+
169
+ ## 🚀 Initialization Modes
170
+
171
+ The TagadaProvider supports two initialization modes to give you control over when your components render:
172
+
173
+ ### Non-Blocking Mode (Default - Recommended)
174
+
175
+ ```tsx
176
+ <TagadaProvider>
177
+ {/* Children render immediately after config loads */}
178
+ <YourApp />
179
+ </TagadaProvider>
180
+
181
+ // OR explicitly
182
+ <TagadaProvider blockUntilSessionReady={false}>
183
+ <YourApp />
184
+ </TagadaProvider>
185
+ ```
186
+
187
+ **Flow:**
188
+
189
+ 1. **Phase 1 & 2** ✅ Plugin config loads → Children render immediately
190
+ 2. **Phase 3** 🔄 Session initialization runs in background
191
+ 3. **API calls** 🔄 Hooks automatically wait for session to be ready
192
+
193
+ **Benefits:**
194
+
195
+ - ⚡ **Faster rendering** - UI appears immediately
196
+ - 🎯 **Better UX** - Show loading states while session initializes
197
+ - 🔄 **Automatic waiting** - Hooks handle session timing for you
198
+
199
+ ### Blocking Mode (Legacy Behavior)
200
+
201
+ ```tsx
202
+ <TagadaProvider blockUntilSessionReady={true}>
203
+ {/* Children render only after ALL initialization completes */}
204
+ <YourApp />
205
+ </TagadaProvider>
206
+ ```
207
+
208
+ **Flow:**
209
+
210
+ 1. **All Phases** ⏳ Config + Session must complete before children render
211
+ 2. **API calls** ✅ Work immediately (no waiting needed)
212
+
213
+ **Use when:**
214
+
215
+ - 🔄 **Migrating** from older SDK versions
216
+ - 🎯 **Simple apps** that don't need progressive loading
217
+
218
+ ### Console Logs
219
+
220
+ The SDK logs help you understand which mode you're using:
221
+
222
+ **Non-blocking mode:**
223
+
224
+ ```
225
+ ✅ Phase 1 & 2 Complete - Plugin config loaded
226
+ 🚀 Non-blocking mode: Children can now render - Phase 3 will continue in background
227
+ 🔄 [useCheckout] Waiting for session initialization to complete...
228
+ ✅ Phase 3 Complete - Session initialization completed successfully
229
+ ✅ [useCheckout] Session initialized, proceeding with checkout init
230
+ ```
231
+
232
+ **Blocking mode:**
233
+
234
+ ```
235
+ ✅ Phase 1 & 2 Complete - Plugin config loaded
236
+ ⏳ Blocking mode: Children will render after Phase 3 completes
237
+ ✅ Phase 3 Complete - Session initialization completed successfully
238
+ ```
239
+
240
+ ### TagadaProvider API
241
+
242
+ ```tsx
243
+ interface TagadaProviderProps {
244
+ children: ReactNode;
245
+ environment?: 'local' | 'development' | 'staging' | 'production';
246
+ customApiConfig?: Partial<EnvironmentConfig>;
247
+ debugMode?: boolean;
248
+ localConfig?: string; // LOCAL DEV ONLY: Override config variant
249
+ blockUntilSessionReady?: boolean; // Default: false
250
+ }
251
+ ```
252
+
253
+ | Prop | Type | Default | Description |
254
+ | ------------------------ | ----------- | -------------------- | ------------------------------ |
255
+ | `children` | `ReactNode` | - | Your plugin components |
256
+ | `environment` | `string` | auto-detect | Override environment detection |
257
+ | `customApiConfig` | `object` | - | Custom API configuration |
258
+ | `debugMode` | `boolean` | auto (false in prod) | Enable debug features |
259
+ | `localConfig` | `string` | `'default'` | Config variant for local dev |
260
+ | `blockUntilSessionReady` | `boolean` | `false` | Use legacy blocking behavior |
261
+
262
+ > **Version Compatibility:** The `blockUntilSessionReady` option was added in v2.3.0. For older versions, the blocking behavior was the default and only option.
263
+
264
+ ### Development vs Production
265
+
266
+ | Environment | Store/Account ID | Deployment Config | How it Works |
267
+ | -------------- | ---------------- | ----------------- | ------------------ |
268
+ | **Local Dev** | `.local.json` | `config/*.json` | Files on disk |
269
+ | **Production** | HTTP Headers | Meta Tags | Platform injection |
270
+
271
+ ```tsx
272
+ // ✅ ALWAYS use hooks - works in both environments
273
+ const { storeId, accountId, basePath, config } = usePluginConfig();
274
+
275
+ // ❌ NEVER access directly
276
+ // const config = window.__PLUGIN_CONFIG__; // Doesn't exist!
277
+ ```
278
+
279
+ ## 🎯 Key Features
280
+
281
+ ### 🔧 **Plugin Configuration System**
282
+
283
+ - **Automatic Context Injection** - Store ID, Account ID, and custom config
284
+ - **Development & Production** - Seamless environment switching
285
+ - **Generic Configuration** - Support for any JSON structure
286
+ - **React Hooks** - Clean, type-safe configuration access
287
+
288
+ ### 💳 **Payment Processing**
289
+
290
+ - Secure tokenized payments
291
+ - Multiple payment method support
292
+ - Real-time validation
293
+ - PCI compliance
294
+
295
+ ### 🌍 **Address & Location**
296
+
297
+ - **Google Places Autocomplete** - Automatic API loading and address parsing
298
+ - **ISO Country/Region Data** - Complete ISO 3166-1/3166-2 database
299
+ - **Address Validation** - Structured component extraction
300
+ - **Multi-language Support** - 11+ languages for international users
301
+
302
+ ### 🛒 **E-commerce Features**
303
+
304
+ - Dynamic pricing and promotional offers
305
+ - Cart management and tax calculations
306
+ - Currency conversion and formatting
307
+ - Customer profile management
308
+
309
+ ### 🎨 **UI & Development**
310
+
311
+ - Pre-built React components
312
+ - Customizable themes with configuration
313
+ - Mobile-optimized and accessible
314
+ - TypeScript support throughout
315
+
316
+ ## 📖 API Reference
317
+
318
+ ### Core Hooks
319
+
320
+ #### useCheckout()
321
+
322
+ Primary hook for checkout state management.
323
+
324
+ ```typescript
325
+ const {
326
+ customer, // Customer information
327
+ cart, // Shopping cart state
328
+ payment, // Payment details
329
+ shipping, // Shipping information
330
+ loading, // Loading states
331
+ errors, // Error handling
332
+ } = useCheckout();
333
+ ```
334
+
335
+ #### useOffers()
336
+
337
+ Hook for managing dynamic offers and pricing.
338
+
339
+ ```typescript
340
+ const {
341
+ offers, // Available offers
342
+ applyOffer, // Apply offer function
343
+ removeOffer, // Remove offer function
344
+ total, // Calculated total
345
+ } = useOffers();
346
+ ```
347
+
348
+ #### usePromotionCodes()
349
+
350
+ Hook for managing promotion codes in checkout sessions.
351
+
352
+ ```typescript
353
+ const {
354
+ appliedPromotions, // Currently applied promotions
355
+ isLoading, // Loading state
356
+ isApplying, // Applying promotion state
357
+ applyPromotionCode, // Apply promotion code function
358
+ removePromotionCode, // Remove promotion function
359
+ validatePromotionCode, // Validate code without applying
360
+ } = usePromotionCodes({ checkoutSessionId });
361
+ ```
362
+
363
+ ### Utility Functions
364
+
365
+ #### setCheckoutInfo()
366
+
367
+ Update checkout information with validation.
368
+
369
+ ```typescript
370
+ await setCheckoutInfo({
371
+ customer: {
372
+ email: 'user@example.com',
373
+ firstName: 'John',
374
+ lastName: 'Doe',
375
+ },
376
+ payment: {
377
+ method: 'card',
378
+ token: 'pm_token_123',
379
+ },
380
+ });
381
+ ```
382
+
383
+ #### Money utilities
384
+
385
+ Format and calculate monetary values.
386
+
387
+ ```typescript
388
+ import { formatMoney, convertCurrency } from '@tagadapay/plugin-sdk';
389
+
390
+ const formatted = formatMoney(2999, 'USD'); // "$29.99"
391
+ const converted = convertCurrency(2999, 'USD', 'EUR'); // 2699
392
+ ```
393
+
394
+ ## 🛠️ Development
395
+
396
+ ### Local Development
397
+
398
+ ```bash
399
+ # Install dependencies
400
+ npm install
401
+
402
+ # Start development server
403
+ npm run dev
404
+
405
+ # Build for production
406
+ npm run build
407
+ ```
408
+
409
+ ### Testing
410
+
411
+ ```bash
412
+ # Run tests
413
+ npm test
414
+
415
+ # Run tests with coverage
416
+ npm run test:coverage
417
+ ```
418
+
419
+ ### Linting
420
+
421
+ ```bash
422
+ # Check code style
423
+ npm run lint
424
+
425
+ # Fix linting issues
426
+ npm run lint:fix
427
+ ```
428
+
429
+ ## 📦 Build & Deploy
430
+
431
+ ### Building Your Plugin
432
+
433
+ ```bash
434
+ # Build optimized bundle
435
+ npm run build
436
+
437
+ # Analyze bundle size
438
+ npm run analyze
439
+ ```
440
+
441
+ ### Deployment
442
+
443
+ ```bash
444
+ # Deploy using TagadaPay CLI
445
+ npx @tagadapay/plugin-cli deploy
446
+
447
+ # Deploy specific environment
448
+ npx @tagadapay/plugin-cli deploy --env production
449
+ ```
450
+
451
+ ## 🔧 Configuration
452
+
453
+ ### Plugin Configuration
454
+
455
+ ```json
456
+ {
457
+ "name": "My Checkout Plugin",
458
+ "version": "1.0.0",
459
+ "description": "Custom checkout experience",
460
+ "main": "dist/index.js",
461
+ "tagadapay": {
462
+ "type": "checkout",
463
+ "mode": "direct",
464
+ "framework": "react"
465
+ }
466
+ }
467
+ ```
468
+
469
+ ## 🔐 Security
470
+
471
+ ### Best Practices
472
+
473
+ - Never store sensitive payment data
474
+ - Always validate user inputs
475
+ - Use HTTPS in production
476
+ - Implement proper error handling
477
+ - Follow PCI DSS guidelines
478
+
479
+ ### Token Management
480
+
481
+ ```typescript
482
+ // ✅ Good: Use tokenized payments
483
+ const paymentToken = await tokenizePayment(cardData);
484
+ await processPayment({ token: paymentToken });
485
+
486
+ // ❌ Bad: Never store raw card data
487
+ // const cardNumber = '4111111111111111'; // Don't do this
488
+ ```
489
+
490
+ ## 📱 Mobile Optimization
491
+
492
+ ### Responsive Design
493
+
494
+ ```css
495
+ .checkout-container {
496
+ max-width: 600px;
497
+ margin: 0 auto;
498
+ padding: 16px;
499
+ }
500
+
501
+ @media (max-width: 768px) {
502
+ .checkout-container {
503
+ padding: 8px;
504
+ }
505
+
506
+ .checkout-form {
507
+ font-size: 16px; /* Prevent zoom on iOS */
508
+ }
509
+ }
510
+ ```
511
+
512
+ ### Touch Interactions
513
+
514
+ ```typescript
515
+ const handleTouchStart = (e) => {
516
+ // Optimize for touch devices
517
+ e.preventDefault();
518
+ // Handle touch interaction
519
+ };
520
+ ```
521
+
522
+ ## 🌐 Internationalization
523
+
524
+ ### Multi-language Support
525
+
526
+ ```typescript
527
+ import { useTranslation } from '@tagadapay/plugin-sdk';
528
+
529
+ function CheckoutForm() {
530
+ const { t } = useTranslation();
531
+
532
+ return (
533
+ <form>
534
+ <label>{t('checkout.email')}</label>
535
+ <input type="email" placeholder={t('checkout.email_placeholder')} />
536
+ </form>
537
+ );
538
+ }
539
+ ```
540
+
541
+ ### Currency Support
542
+
543
+ ```typescript
544
+ import { useCurrency } from '@tagadapay/plugin-sdk';
545
+
546
+ function PriceDisplay({ amount }) {
547
+ const { formatPrice, currency } = useCurrency();
548
+
549
+ return <span>{formatPrice(amount, currency)}</span>;
550
+ }
551
+ ```
552
+
553
+ ## 📊 Analytics & Monitoring
554
+
555
+ ### Event Tracking
556
+
557
+ ```typescript
558
+ import { trackEvent } from '@tagadapay/plugin-sdk';
559
+
560
+ // Track user interactions
561
+ trackEvent('checkout_started', {
562
+ product_id: 'prod_123',
563
+ value: 2999,
564
+ currency: 'USD',
565
+ });
566
+
567
+ // Track conversions
568
+ trackEvent('purchase_completed', {
569
+ transaction_id: 'txn_456',
570
+ value: 2999,
571
+ currency: 'USD',
572
+ });
573
+ ```
574
+
575
+ ### Performance Monitoring
576
+
577
+ ```typescript
578
+ import { performance } from '@tagadapay/plugin-sdk';
579
+
580
+ // Measure load times
581
+ performance.mark('checkout-start');
582
+ // ... checkout logic
583
+ performance.mark('checkout-end');
584
+ performance.measure('checkout-duration', 'checkout-start', 'checkout-end');
585
+ ```
586
+
587
+ ## 🤝 Contributing
588
+
589
+ ### Development Setup
590
+
591
+ ```bash
592
+ # Clone the repository
593
+ git clone https://github.com/tagadapay/plugin-sdk.git
594
+
595
+ # Install dependencies
596
+ npm install
597
+
598
+ # Start development
599
+ npm run dev
600
+ ```
601
+
602
+ ### Submitting Changes
603
+
604
+ 1. Fork the repository
605
+ 2. Create a feature branch
606
+ 3. Make your changes
607
+ 4. Add tests
608
+ 5. Submit a pull request
609
+
610
+ ## 📄 License
611
+
612
+ MIT License - see [LICENSE](./LICENSE) for details.
613
+
614
+ ## 🆘 Support
615
+
616
+ - **Documentation**: [docs.tagadapay.com](https://docs.tagadapay.com)
617
+ - **Discord**: [discord.gg/tagadapay](https://discord.gg/tagadapay)
618
+ - **Email**: support@tagadapay.com
619
+ - **GitHub Issues**: [github.com/tagadapay/plugin-sdk/issues](https://github.com/tagadapay/plugin-sdk/issues)
620
+
621
+ ---
622
+
623
+ Built with ❤️ by the TagadaPay team