@tagadapay/plugin-sdk 2.3.3 → 2.3.5

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