@tagadapay/plugin-sdk 2.6.2 → 2.6.6

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.
Files changed (55) hide show
  1. package/README.md +1090 -623
  2. package/dist/react/components/GooglePayButton.d.ts +12 -0
  3. package/dist/react/components/GooglePayButton.js +340 -0
  4. package/dist/react/components/index.d.ts +3 -2
  5. package/dist/react/components/index.js +3 -2
  6. package/dist/react/hooks/useApplePay.js +38 -10
  7. package/dist/react/hooks/{useExpressPayment.d.ts → useExpressPaymentMethods.d.ts} +13 -10
  8. package/dist/react/hooks/{useExpressPayment.js → useExpressPaymentMethods.js} +17 -8
  9. package/dist/react/hooks/useGoogleAutocomplete.d.ts +2 -0
  10. package/dist/react/hooks/useGoogleAutocomplete.js +18 -2
  11. package/dist/react/hooks/useGooglePay.d.ts +22 -0
  12. package/dist/react/hooks/useGooglePay.js +32 -0
  13. package/dist/react/index.d.ts +9 -7
  14. package/dist/react/index.js +8 -5
  15. package/dist/react/providers/TagadaProvider.js +5 -5
  16. package/dist/react/types/apple-pay.d.ts +0 -25
  17. package/dist/v2/core/googleAutocomplete.d.ts +2 -0
  18. package/dist/v2/core/googleAutocomplete.js +23 -4
  19. package/dist/v2/core/resources/checkout.d.ts +70 -2
  20. package/dist/v2/core/resources/discounts.d.ts +53 -0
  21. package/dist/v2/core/resources/discounts.js +29 -0
  22. package/dist/v2/core/resources/expressPaymentMethods.d.ts +56 -0
  23. package/dist/v2/core/resources/expressPaymentMethods.js +27 -0
  24. package/dist/v2/core/resources/index.d.ts +7 -4
  25. package/dist/v2/core/resources/index.js +7 -4
  26. package/dist/v2/core/resources/shippingRates.d.ts +36 -0
  27. package/dist/v2/core/resources/shippingRates.js +23 -0
  28. package/dist/v2/core/resources/vipOffers.d.ts +37 -0
  29. package/dist/v2/core/resources/vipOffers.js +27 -0
  30. package/dist/v2/core/utils/order.d.ts +1 -0
  31. package/dist/v2/core/utils/pluginConfig.d.ts +6 -6
  32. package/dist/v2/index.d.ts +12 -9
  33. package/dist/v2/index.js +3 -3
  34. package/dist/v2/react/components/ApplePayButton.d.ts +141 -0
  35. package/dist/v2/react/components/ApplePayButton.js +320 -0
  36. package/dist/v2/react/components/GooglePayButton.d.ts +19 -0
  37. package/dist/v2/react/components/GooglePayButton.js +355 -0
  38. package/dist/v2/react/hooks/useApiQuery.d.ts +4 -1
  39. package/dist/v2/react/hooks/useApiQuery.js +4 -1
  40. package/dist/v2/react/hooks/useDiscountsQuery.d.ts +30 -0
  41. package/dist/v2/react/hooks/useDiscountsQuery.js +175 -0
  42. package/dist/v2/react/hooks/useExpressPaymentMethods.d.ts +12 -0
  43. package/dist/v2/react/hooks/useExpressPaymentMethods.js +17 -0
  44. package/dist/v2/react/hooks/useGoogleAutocomplete.d.ts +2 -0
  45. package/dist/v2/react/hooks/useGoogleAutocomplete.js +18 -2
  46. package/dist/v2/react/hooks/useShippingRatesQuery.d.ts +22 -0
  47. package/dist/v2/react/hooks/useShippingRatesQuery.js +134 -0
  48. package/dist/v2/react/hooks/useVipOffersQuery.d.ts +72 -0
  49. package/dist/v2/react/hooks/useVipOffersQuery.js +140 -0
  50. package/dist/v2/react/index.d.ts +30 -17
  51. package/dist/v2/react/index.js +18 -10
  52. package/dist/v2/react/providers/ExpressPaymentMethodsProvider.d.ts +59 -0
  53. package/dist/v2/react/providers/ExpressPaymentMethodsProvider.js +165 -0
  54. package/dist/v2/react/providers/TagadaProvider.js +5 -5
  55. package/package.json +90 -90
package/README.md CHANGED
@@ -1,623 +1,1090 @@
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.
4
+
5
+ > **🚀 V2 Now Available!** The new V2 architecture features TanStack Query integration, improved TypeScript support, and better performance. [See V2 Architecture](#-v2-architecture) for details.
6
+ >
7
+ > **Recommended**: Use `@tagadapay/plugin-sdk/v2` for new projects. V1 (`/react`) is still supported for existing projects.
8
+
9
+ ## 📚 Documentation
10
+
11
+ ### V2 Core APIs (Recommended)
12
+
13
+ - **[V2 Architecture](#-v2-architecture)** - New TanStack Query-based architecture
14
+ - **[V2 Examples](#-v2-examples)** - Complete examples using the new V2 hooks
15
+ - **[useCheckout (V2)](#usecheckout)** - TanStack Query-based checkout management
16
+ - **[useOffers (V2)](#useoffers)** - Dynamic pricing with automatic caching
17
+ - **[useProducts (V2)](#useproducts)** - Product data management
18
+ - **[usePayment (V2)](#usepayment)** - Payment processing with 3DS support
19
+ - **[V2 Utility Functions](#v2-utility-functions--advanced-features)** - Enhanced utilities and TanStack Query integration
20
+
21
+ ### Legacy V1 APIs (Still Supported)
22
+
23
+ - **[useCheckout (V1)](./docs/README-useCheckout.md)** - Legacy checkout state management
24
+ - **[setCheckoutInfo](./docs/README-setCheckoutInfo.md)** - Customer information and validation
25
+ - **[useOffers (V1)](./docs/README-useOffers.md)** - Legacy dynamic pricing
26
+ - **[usePromotionCodes](./docs/README-usePromotionCodes.md)** - Legacy promotion code management
27
+ - **[Money utilities](./docs/README-money.md)** - Currency formatting and calculations
28
+ - **[URL utilities](./docs/README-urlUtils.md)** - Navigation and routing helpers
29
+
30
+ ### Plugin Development
31
+
32
+ - **[Plugin Configuration](./docs/PLUGIN_CONFIG.md)** - How to access store context, config, and branding
33
+ - **[Initialization Modes](#-initialization-modes)** - Choose between blocking and non-blocking initialization
34
+ - **[Google Autocomplete](./docs/README-google-autocomplete.md)** - Address autocomplete with Google Places API
35
+ - **[ISO Data](./docs/README-iso-data.md)** - Country and region data with Google integration
36
+
37
+ ### Examples
38
+
39
+ - **[Vite Checkout Demo](../checkout-vite)** - Complete checkout implementation
40
+
41
+ ## 🏗️ Building a Plugin
42
+
43
+ ### Plugin Structure
44
+
45
+ Every TagadaPay plugin follows this simple structure:
46
+
47
+ ```
48
+ my-plugin/
49
+ ├── plugin.manifest.json # Plugin metadata & routing
50
+ ├── .local.json # Local dev config (auto-injected in production)
51
+ ├── config/ # Optional deployment configs
52
+ │ ├── theme-green.json # Config variant A
53
+ │ └── theme-blue.json # Config variant B
54
+ ├── src/
55
+ │ └── App.tsx # Your plugin code
56
+ └── dist/ # Built plugin files
57
+ ```
58
+
59
+ ### Configuration Flow
60
+
61
+ ```mermaid
62
+ graph TD
63
+ A[🛠️ Local Development] --> B[.local.json]
64
+ A --> C[config/*.json]
65
+ B --> D[usePluginConfig()]
66
+ C --> D
67
+
68
+ E[🚀 Production] --> F[Platform Injection]
69
+ F --> G[HTTP Headers & Meta Tags]
70
+ G --> D
71
+
72
+ D --> H[Your Plugin Component]
73
+
74
+ style A fill:#e1f5fe
75
+ style E fill:#f3e5f5
76
+ style D fill:#fff3e0
77
+ style H fill:#e8f5e8
78
+ ```
79
+
80
+ ### Essential Files
81
+
82
+ #### 1. **`plugin.manifest.json`** - Plugin Metadata
83
+
84
+ ```json
85
+ {
86
+ "pluginId": "my-awesome-plugin",
87
+ "name": "My Awesome Plugin",
88
+ "version": "1.0.0",
89
+ "mode": "direct-mode",
90
+ "router": {
91
+ "basePath": "/",
92
+ "matcher": ".*",
93
+ "excluder": "/checkout"
94
+ }
95
+ }
96
+ ```
97
+
98
+ #### 2. **`.local.json`** - Local Development Context
99
+
100
+ ```json
101
+ {
102
+ "storeId": "store_abc123",
103
+ "accountId": "acc_xyz789",
104
+ "basePath": "/"
105
+ }
106
+ ```
107
+
108
+ > ⚠️ **Auto-managed**: This file is only for local dev. In production, the platform injects this data automatically.
109
+
110
+ #### 3. **`config/my-theme.json`** - Optional Deployment Config
111
+
112
+ ```json
113
+ {
114
+ "configName": "green-theme",
115
+ "branding": {
116
+ "primaryColor": "#059669",
117
+ "companyName": "My Store",
118
+ "logoUrl": "https://example.com/logo.png"
119
+ },
120
+ "features": {
121
+ "enableChat": true,
122
+ "maxItems": 10
123
+ }
124
+ }
125
+ ```
126
+
127
+ > 📝 **Note**: Config can contain any keys you need - the SDK doesn't enforce a specific structure.
128
+
129
+ ## 🚀 Quick Start
130
+
131
+ ### Installation
132
+
133
+ ```bash
134
+ npm install @tagadapay/plugin-sdk
135
+ ```
136
+
137
+ ### Basic Plugin Setup
138
+
139
+ ```tsx
140
+ import React from 'react';
141
+ import {
142
+ TagadaProvider,
143
+ usePluginConfig,
144
+ useGoogleAutocomplete,
145
+ useISOData,
146
+ useCheckout,
147
+ formatMoney,
148
+ } from '@tagadapay/plugin-sdk/v2';
149
+
150
+ function MyPlugin() {
151
+ const { config, storeId, accountId, basePath, loading } = usePluginConfig();
152
+
153
+ // Optional: Add address autocomplete
154
+ const { searchPlaces, predictions } = useGoogleAutocomplete({
155
+ apiKey: config?.googleMapsApiKey || 'YOUR_API_KEY',
156
+ });
157
+
158
+ // Optional: Add country/region data
159
+ const { countries } = useISOData('en');
160
+
161
+ // V2: Use TanStack Query-based checkout hook
162
+ const { checkout, init, updateLineItems, isLoading } = useCheckout({
163
+ checkoutToken: 'your-checkout-token',
164
+ });
165
+
166
+ if (loading) return <div>Loading...</div>;
167
+
168
+ return (
169
+ <div style={{ '--primary': config?.branding?.primaryColor }}>
170
+ <h1>Welcome to {config?.branding?.companyName}</h1>
171
+ <p>Store: {storeId}</p>
172
+ <p>Base Path: {basePath}</p>
173
+ <p>Available Countries: {Object.keys(countries).length}</p>
174
+
175
+ {checkout && (
176
+ <div>
177
+ <h2>Checkout Total: {formatMoney(checkout.summary.total, checkout.currency)}</h2>
178
+ <p>Items: {checkout.lineItems.length}</p>
179
+ </div>
180
+ )}
181
+ </div>
182
+ );
183
+ }
184
+
185
+ // Wrap your plugin with TagadaProvider
186
+ function App() {
187
+ return (
188
+ <TagadaProvider>
189
+ <MyPlugin />
190
+ </TagadaProvider>
191
+ );
192
+ }
193
+
194
+ export default App;
195
+ ```
196
+
197
+ ## 🏗️ V2 Architecture
198
+
199
+ ### What's New in V2
200
+
201
+ The TagadaPay Plugin SDK v2 introduces a clean architecture with significant improvements:
202
+
203
+ #### **🔄 TanStack Query Integration**
204
+
205
+ - **Automatic Caching**: All API calls are cached and synchronized across components
206
+ - **Background Refetching**: Data stays fresh with automatic background updates
207
+ - **Optimistic Updates**: Instant UI feedback with automatic rollback on errors
208
+ - **Request Deduplication**: Multiple components can use the same data without duplicate requests
209
+
210
+ #### **🏗️ Clean Architecture**
211
+
212
+ - **Core Layer**: Pure functions and API clients without React dependencies
213
+ - **React Layer**: Hooks and components that use core functions
214
+ - **Better Testing**: Easier to test business logic separately from UI logic
215
+
216
+ #### **📦 Import Paths**
217
+
218
+ ```tsx
219
+ // V2 (Recommended)
220
+ import { useCheckout, useOffers, TagadaProvider } from '@tagadapay/plugin-sdk/v2';
221
+
222
+ // Legacy (Still supported)
223
+ import { useCheckout, useOffers, TagadaProvider } from '@tagadapay/plugin-sdk/react';
224
+ ```
225
+
226
+ #### **🔧 Enhanced Developer Experience**
227
+
228
+ - **TypeScript First**: Better type inference and autocomplete
229
+ - **Debug Tools**: Built-in debug drawer for development
230
+ - **Performance**: Reduced bundle size and better performance
231
+
232
+ ### Migration from V1
233
+
234
+ Most hooks have the same names but improved APIs:
235
+
236
+ ```tsx
237
+ // V1 Pattern
238
+ const { checkout, loading, error } = useCheckout();
239
+
240
+ // V2 Pattern (TanStack Query)
241
+ const { checkout, isLoading, error, refresh } = useCheckout({
242
+ checkoutToken: 'token',
243
+ enabled: true,
244
+ });
245
+ ```
246
+
247
+ ### 📚 V2 Examples
248
+
249
+ #### Complete Checkout Flow
250
+
251
+ ```tsx
252
+ import React, { useState } from 'react';
253
+ import {
254
+ TagadaProvider,
255
+ useCheckout,
256
+ useProducts,
257
+ usePluginConfig,
258
+ formatMoney,
259
+ } from '@tagadapay/plugin-sdk/v2';
260
+
261
+ function CheckoutPage() {
262
+ const [checkoutToken, setCheckoutToken] = useState<string>();
263
+ const { config } = usePluginConfig();
264
+
265
+ // Load products
266
+ const { products, isLoading: productsLoading } = useProducts({
267
+ storeId: config.storeId,
268
+ });
269
+
270
+ // Initialize checkout when needed
271
+ const {
272
+ checkout,
273
+ isLoading: checkoutLoading,
274
+ init,
275
+ updateLineItems,
276
+ updateCustomer,
277
+ applyPromotionCode,
278
+ } = useCheckout({
279
+ checkoutToken,
280
+ enabled: !!checkoutToken,
281
+ });
282
+
283
+ const handleInitCheckout = async () => {
284
+ if (!products?.length) return;
285
+
286
+ const result = await init({
287
+ lineItems: [
288
+ {
289
+ variantId: products[0].variants[0].id,
290
+ quantity: 1,
291
+ },
292
+ ],
293
+ });
294
+
295
+ setCheckoutToken(result.checkoutToken);
296
+ };
297
+
298
+ const handleApplyPromo = async (code: string) => {
299
+ try {
300
+ await applyPromotionCode(code);
301
+ // TanStack Query automatically refetches and updates the UI
302
+ } catch (error) {
303
+ console.error('Failed to apply promo:', error);
304
+ }
305
+ };
306
+
307
+ if (productsLoading) return <div>Loading products...</div>;
308
+
309
+ return (
310
+ <div>
311
+ <h1>Checkout</h1>
312
+
313
+ {!checkoutToken ? (
314
+ <button onClick={handleInitCheckout}>Start Checkout</button>
315
+ ) : (
316
+ <div>
317
+ {checkoutLoading ? (
318
+ <div>Loading checkout...</div>
319
+ ) : checkout ? (
320
+ <div>
321
+ <h2>Order Summary</h2>
322
+ <p>Total: {formatMoney(checkout.summary.total, checkout.currency)}</p>
323
+ <p>Items: {checkout.lineItems.length}</p>
324
+
325
+ <div>
326
+ <input
327
+ type="text"
328
+ placeholder="Promo code"
329
+ onKeyDown={(e) => {
330
+ if (e.key === 'Enter') {
331
+ handleApplyPromo(e.currentTarget.value);
332
+ }
333
+ }}
334
+ />
335
+ </div>
336
+ </div>
337
+ ) : null}
338
+ </div>
339
+ )}
340
+ </div>
341
+ );
342
+ }
343
+
344
+ function App() {
345
+ return (
346
+ <TagadaProvider>
347
+ <CheckoutPage />
348
+ </TagadaProvider>
349
+ );
350
+ }
351
+ ```
352
+
353
+ #### Multi-Component Data Sharing
354
+
355
+ ```tsx
356
+ import React from 'react';
357
+ import { TagadaProvider, useCheckout, useOffers, formatMoney } from '@tagadapay/plugin-sdk/v2';
358
+
359
+ // Component 1: Cart Summary
360
+ function CartSummary({ checkoutToken }: { checkoutToken: string }) {
361
+ const { checkout, isLoading } = useCheckout({ checkoutToken });
362
+
363
+ if (isLoading) return <div>Loading...</div>;
364
+ if (!checkout) return null;
365
+
366
+ return (
367
+ <div>
368
+ <h3>Cart ({checkout.lineItems.length} items)</h3>
369
+ <p>Total: {formatMoney(checkout.summary.total, checkout.currency)}</p>
370
+ </div>
371
+ );
372
+ }
373
+
374
+ // Component 2: Available Offers (shares same checkout data automatically)
375
+ function OffersPanel({ checkoutToken }: { checkoutToken: string }) {
376
+ const { checkout } = useCheckout({ checkoutToken }); // Same data, no extra request!
377
+ const { offers, isLoading } = useOffers({
378
+ storeId: checkout?.storeId,
379
+ });
380
+
381
+ if (isLoading) return <div>Loading offers...</div>;
382
+
383
+ return (
384
+ <div>
385
+ <h3>Special Offers</h3>
386
+ {offers?.map((offer) => (
387
+ <div key={offer.id}>
388
+ <p>{offer.title}</p>
389
+ <p>Save {formatMoney(offer.discount, checkout?.currency || 'USD')}</p>
390
+ </div>
391
+ ))}
392
+ </div>
393
+ );
394
+ }
395
+
396
+ // Main component
397
+ function CheckoutWithOffers() {
398
+ const checkoutToken = 'your-checkout-token';
399
+
400
+ return (
401
+ <div style={{ display: 'flex', gap: '20px' }}>
402
+ <CartSummary checkoutToken={checkoutToken} />
403
+ <OffersPanel checkoutToken={checkoutToken} />
404
+ </div>
405
+ );
406
+ }
407
+ ```
408
+
409
+ #### Optimistic Updates
410
+
411
+ ```tsx
412
+ import React from 'react';
413
+ import { useCheckout } from '@tagadapay/plugin-sdk/v2';
414
+
415
+ function QuantitySelector({
416
+ checkoutToken,
417
+ variantId,
418
+ currentQuantity,
419
+ }: {
420
+ checkoutToken: string;
421
+ variantId: string;
422
+ currentQuantity: number;
423
+ }) {
424
+ const { checkout, setItemQuantity, updateLineItemsOptimistic } = useCheckout({ checkoutToken });
425
+
426
+ const handleQuantityChange = async (newQuantity: number) => {
427
+ // 1. Optimistic update (instant UI feedback)
428
+ const updatedItems =
429
+ checkout?.lineItems.map((item) =>
430
+ item.variantId === variantId ? { ...item, quantity: newQuantity } : item,
431
+ ) || [];
432
+
433
+ updateLineItemsOptimistic(updatedItems);
434
+
435
+ // 2. Server update (with automatic rollback on error)
436
+ try {
437
+ await setItemQuantity(variantId, newQuantity);
438
+ // TanStack Query automatically syncs the real data
439
+ } catch (error) {
440
+ // Automatic rollback to previous state
441
+ console.error('Failed to update quantity:', error);
442
+ }
443
+ };
444
+
445
+ return (
446
+ <div>
447
+ <button onClick={() => handleQuantityChange(currentQuantity - 1)}>-</button>
448
+ <span>{currentQuantity}</span>
449
+ <button onClick={() => handleQuantityChange(currentQuantity + 1)}>+</button>
450
+ </div>
451
+ );
452
+ }
453
+ ```
454
+
455
+ ## 🚀 Initialization Modes
456
+
457
+ The TagadaProvider supports two initialization modes to give you control over when your components render:
458
+
459
+ ### Non-Blocking Mode (Default - Recommended)
460
+
461
+ ```tsx
462
+ <TagadaProvider>
463
+ {/* Children render immediately after config loads */}
464
+ <YourApp />
465
+ </TagadaProvider>
466
+
467
+ // OR explicitly
468
+ <TagadaProvider blockUntilSessionReady={false}>
469
+ <YourApp />
470
+ </TagadaProvider>
471
+ ```
472
+
473
+ **Flow:**
474
+
475
+ 1. **Phase 1 & 2** ✅ Plugin config loads → Children render immediately
476
+ 2. **Phase 3** 🔄 Session initialization runs in background
477
+ 3. **API calls** 🔄 Hooks automatically wait for session to be ready
478
+
479
+ **Benefits:**
480
+
481
+ - ⚡ **Faster rendering** - UI appears immediately
482
+ - 🎯 **Better UX** - Show loading states while session initializes
483
+ - 🔄 **Automatic waiting** - Hooks handle session timing for you
484
+
485
+ ### Blocking Mode (Legacy Behavior)
486
+
487
+ ```tsx
488
+ <TagadaProvider blockUntilSessionReady={true}>
489
+ {/* Children render only after ALL initialization completes */}
490
+ <YourApp />
491
+ </TagadaProvider>
492
+ ```
493
+
494
+ **Flow:**
495
+
496
+ 1. **All Phases** ⏳ Config + Session must complete before children render
497
+ 2. **API calls** ✅ Work immediately (no waiting needed)
498
+
499
+ **Use when:**
500
+
501
+ - 🔄 **Migrating** from older SDK versions
502
+ - 🎯 **Simple apps** that don't need progressive loading
503
+
504
+ ### Console Logs
505
+
506
+ The SDK logs help you understand which mode you're using:
507
+
508
+ **Non-blocking mode:**
509
+
510
+ ```
511
+ ✅ Phase 1 & 2 Complete - Plugin config loaded
512
+ 🚀 Non-blocking mode: Children can now render - Phase 3 will continue in background
513
+ 🔄 [useCheckout] Waiting for session initialization to complete...
514
+ ✅ Phase 3 Complete - Session initialization completed successfully
515
+ [useCheckout] Session initialized, proceeding with checkout init
516
+ ```
517
+
518
+ **Blocking mode:**
519
+
520
+ ```
521
+ ✅ Phase 1 & 2 Complete - Plugin config loaded
522
+ Blocking mode: Children will render after Phase 3 completes
523
+ ✅ Phase 3 Complete - Session initialization completed successfully
524
+ ```
525
+
526
+ ### TagadaProvider API
527
+
528
+ ```tsx
529
+ interface TagadaProviderProps {
530
+ children: ReactNode;
531
+ environment?: 'local' | 'development' | 'staging' | 'production';
532
+ customApiConfig?: Partial<EnvironmentConfig>;
533
+ debugMode?: boolean;
534
+ localConfig?: string; // LOCAL DEV ONLY: Override config variant
535
+ blockUntilSessionReady?: boolean; // Default: false
536
+
537
+ // V2 Specific Options
538
+ queryClientConfig?: QueryClientConfig; // TanStack Query configuration
539
+ enableDevtools?: boolean; // Enable React Query Devtools
540
+ }
541
+ ```
542
+
543
+ | Prop | Type | Default | Description |
544
+ | ------------------------ | ----------- | -------------------- | ------------------------------ |
545
+ | `children` | `ReactNode` | - | Your plugin components |
546
+ | `environment` | `string` | auto-detect | Override environment detection |
547
+ | `customApiConfig` | `object` | - | Custom API configuration |
548
+ | `debugMode` | `boolean` | auto (false in prod) | Enable debug features & drawer |
549
+ | `localConfig` | `string` | `'default'` | Config variant for local dev |
550
+ | `blockUntilSessionReady` | `boolean` | `false` | Use legacy blocking behavior |
551
+ | `queryClientConfig` | `object` | - | **V2**: TanStack Query config |
552
+ | `enableDevtools` | `boolean` | `false` | **V2**: React Query Devtools |
553
+
554
+ #### V2 Enhanced Provider Features
555
+
556
+ ```tsx
557
+ import { TagadaProvider } from '@tagadapay/plugin-sdk/v2';
558
+
559
+ function App() {
560
+ return (
561
+ <TagadaProvider
562
+ debugMode={true}
563
+ enableDevtools={true} // Shows React Query Devtools
564
+ queryClientConfig={{
565
+ defaultOptions: {
566
+ queries: {
567
+ staleTime: 5 * 60 * 1000, // 5 minutes
568
+ cacheTime: 10 * 60 * 1000, // 10 minutes
569
+ },
570
+ },
571
+ }}
572
+ >
573
+ <YourApp />
574
+ </TagadaProvider>
575
+ );
576
+ }
577
+ ```
578
+
579
+ > **Version Compatibility:** V2 features require `@tagadapay/plugin-sdk/v2`. The `blockUntilSessionReady` option was added in v2.3.0. For older versions, the blocking behavior was the default and only option.
580
+
581
+ ### Development vs Production
582
+
583
+ | Environment | Store/Account ID | Deployment Config | How it Works |
584
+ | -------------- | ---------------- | ----------------- | ------------------ |
585
+ | **Local Dev** | `.local.json` | `config/*.json` | Files on disk |
586
+ | **Production** | HTTP Headers | Meta Tags | Platform injection |
587
+
588
+ ```tsx
589
+ // ALWAYS use hooks - works in both environments
590
+ const { storeId, accountId, basePath, config } = usePluginConfig();
591
+
592
+ // NEVER access directly
593
+ // const config = window.__PLUGIN_CONFIG__; // Doesn't exist!
594
+ ```
595
+
596
+ ## 🎯 Key Features
597
+
598
+ ### 🔧 **Plugin Configuration System**
599
+
600
+ - **Automatic Context Injection** - Store ID, Account ID, and custom config
601
+ - **Development & Production** - Seamless environment switching
602
+ - **Generic Configuration** - Support for any JSON structure
603
+ - **React Hooks** - Clean, type-safe configuration access
604
+
605
+ ### 💳 **Payment Processing**
606
+
607
+ - Secure tokenized payments
608
+ - Multiple payment method support
609
+ - Real-time validation
610
+ - PCI compliance
611
+
612
+ ### 🌍 **Address & Location**
613
+
614
+ - **Google Places Autocomplete** - Automatic API loading and address parsing
615
+ - **ISO Country/Region Data** - Complete ISO 3166-1/3166-2 database
616
+ - **Address Validation** - Structured component extraction
617
+ - **Multi-language Support** - 11+ languages for international users
618
+
619
+ ### 🛒 **E-commerce Features**
620
+
621
+ - Dynamic pricing and promotional offers
622
+ - Cart management and tax calculations
623
+ - Currency conversion and formatting
624
+ - Customer profile management
625
+
626
+ ### 🎨 **UI & Development**
627
+
628
+ - Pre-built React components
629
+ - Customizable themes with configuration
630
+ - Mobile-optimized and accessible
631
+ - TypeScript support throughout
632
+
633
+ ## 📖 API Reference
634
+
635
+ ### V2 Core Hooks (TanStack Query-based)
636
+
637
+ #### useCheckout()
638
+
639
+ Primary hook for checkout state management using TanStack Query for automatic caching and synchronization.
640
+
641
+ ```typescript
642
+ const {
643
+ // Query data
644
+ checkout, // CheckoutData | undefined
645
+ isLoading, // boolean
646
+ error, // Error | null
647
+ isSuccess, // boolean
648
+
649
+ // Actions
650
+ init, // (params: CheckoutInitParams) => Promise<{checkoutUrl, checkoutSession, checkoutToken}>
651
+ refresh, // () => Promise<void>
652
+
653
+ // Checkout operations
654
+ updateLineItems, // (lineItems: CheckoutLineItem[]) => Promise<any>
655
+ updateLineItemsOptimistic, // (lineItems: CheckoutLineItem[]) => void
656
+ setItemQuantity, // (variantId: string, quantity: number, priceId?: string) => Promise<any>
657
+ updateCustomer, // (data: {email: string, acceptsMarketing?: boolean}) => Promise<any>
658
+ applyPromotionCode, // (code: string) => Promise<any>
659
+ removePromotion, // (promotionId: string) => Promise<any>
660
+ } = useCheckout({ checkoutToken, enabled });
661
+ ```
662
+
663
+ #### useOffers()
664
+
665
+ Hook for managing dynamic offers and pricing with automatic cache management.
666
+
667
+ ```typescript
668
+ const {
669
+ // Query data
670
+ offers, // Offer[] | undefined
671
+ isLoading, // boolean
672
+ error, // Error | null
673
+
674
+ // Actions
675
+ refresh, // () => Promise<void>
676
+ } = useOffers({ storeId, enabled });
677
+ ```
678
+
679
+ #### usePromotions()
680
+
681
+ Hook for managing promotion codes in checkout sessions with TanStack Query.
682
+
683
+ ```typescript
684
+ const {
685
+ // Query data
686
+ promotions, // Promotion[] | undefined
687
+ isLoading, // boolean
688
+ error, // Error | null
689
+
690
+ // Actions
691
+ refresh, // () => Promise<void>
692
+ } = usePromotions({ checkoutToken, enabled });
693
+ ```
694
+
695
+ #### useProducts()
696
+
697
+ Hook for product data management with caching.
698
+
699
+ ```typescript
700
+ const {
701
+ // Query data
702
+ products, // Product[] | undefined
703
+ isLoading, // boolean
704
+ error, // Error | null
705
+
706
+ // Actions
707
+ refresh, // () => Promise<void>
708
+ } = useProducts({ storeId, enabled });
709
+ ```
710
+
711
+ #### useOrder()
712
+
713
+ Hook for order management and tracking.
714
+
715
+ ```typescript
716
+ const {
717
+ // Query data
718
+ order, // Order | undefined
719
+ isLoading, // boolean
720
+ error, // Error | null
721
+
722
+ // Actions
723
+ refresh, // () => Promise<void>
724
+ } = useOrder({ orderId, enabled });
725
+ ```
726
+
727
+ #### usePostPurchases()
728
+
729
+ Hook for post-purchase offers management.
730
+
731
+ ```typescript
732
+ const {
733
+ // Query data
734
+ postPurchases, // PostPurchaseOffer[] | undefined
735
+ isLoading, // boolean
736
+ error, // Error | null
737
+
738
+ // Actions
739
+ refresh, // () => Promise<void>
740
+ } = usePostPurchases({ orderId, enabled });
741
+ ```
742
+
743
+ #### usePayment()
744
+
745
+ Hook for payment processing with 3DS support.
746
+
747
+ ```typescript
748
+ const {
749
+ // Payment methods
750
+ processPayment, // (options: PaymentOptions) => Promise<PaymentResponse>
751
+ processApplePayPayment, // (token: ApplePayToken) => Promise<PaymentResponse>
752
+
753
+ // State
754
+ isProcessing, // boolean
755
+ error, // Error | null
756
+ } = usePayment();
757
+ ```
758
+
759
+ ### V2 Utility Functions & Advanced Features
760
+
761
+ #### TanStack Query Integration
762
+
763
+ V2 provides direct access to TanStack Query features for advanced use cases:
764
+
765
+ ```typescript
766
+ import {
767
+ useApiQuery,
768
+ useApiMutation,
769
+ useInvalidateQuery,
770
+ usePreloadQuery,
771
+ queryKeys,
772
+ } from '@tagadapay/plugin-sdk/v2';
773
+
774
+ // Custom API queries
775
+ const { data, isLoading } = useApiQuery({
776
+ queryKey: ['custom', 'endpoint'],
777
+ queryFn: () => apiClient.get('/custom-endpoint'),
778
+ });
779
+
780
+ // Mutations with automatic cache updates
781
+ const mutation = useApiMutation({
782
+ mutationFn: (data) => apiClient.post('/update', data),
783
+ onSuccess: () => {
784
+ // Invalidate related queries
785
+ invalidateQuery(['checkout']);
786
+ },
787
+ });
788
+
789
+ // Preload data for better UX
790
+ const preloadCheckout = usePreloadQuery();
791
+ preloadCheckout({
792
+ queryKey: queryKeys.checkout(checkoutToken),
793
+ queryFn: () => checkoutResource.get(checkoutToken),
794
+ });
795
+ ```
796
+
797
+ #### Money Utilities
798
+
799
+ Enhanced money formatting with better TypeScript support:
800
+
801
+ ```typescript
802
+ import { formatMoney, convertCurrency, getCurrencyInfo } from '@tagadapay/plugin-sdk/v2';
803
+
804
+ // Format money with automatic currency detection
805
+ const formatted = formatMoney(2999, 'USD'); // "$29.99"
806
+ const simple = formatSimpleMoney(2999, 'EUR'); // "29.99"
807
+ const withoutSymbol = formatMoneyWithoutSymbol(2999, 'GBP'); // "29.99"
808
+
809
+ // Currency conversion (if rates available)
810
+ const converted = convertCurrency(2999, 'USD', 'EUR'); // 2699
811
+
812
+ // Get currency information
813
+ const currencyInfo = getCurrencyInfo('USD');
814
+ // { symbol: '$', code: 'USD', minorUnits: 2 }
815
+
816
+ // Convert between major and minor units
817
+ const major = minorUnitsToMajorUnits(2999); // 29.99
818
+ const minor = moneyStringOrNumberToMinorUnits('29.99'); // 2999
819
+ ```
820
+
821
+ #### Core Functions (Pure Functions)
822
+
823
+ V2 separates core business logic from React hooks:
824
+
825
+ ```typescript
826
+ import {
827
+ CheckoutResource,
828
+ ProductsResource,
829
+ PaymentsResource,
830
+ PluginConfigUtils,
831
+ } from '@tagadapay/plugin-sdk/v2';
832
+
833
+ // Use core functions directly (useful for server-side or non-React contexts)
834
+ const checkoutResource = new CheckoutResource(apiClient);
835
+ const checkout = await checkoutResource.get(checkoutToken);
836
+
837
+ // Plugin config utilities
838
+ const config = PluginConfigUtils.getPluginConfig(rawConfig, context);
839
+ const isValid = PluginConfigUtils.validateConfig(config);
840
+ ```
841
+
842
+ #### Debug Tools
843
+
844
+ V2 includes built-in debugging tools:
845
+
846
+ ```tsx
847
+ import { TagadaProvider } from '@tagadapay/plugin-sdk/v2';
848
+
849
+ function App() {
850
+ return (
851
+ <TagadaProvider
852
+ debugMode={true} // Shows debug drawer in development
853
+ environment="development"
854
+ >
855
+ <YourApp />
856
+ </TagadaProvider>
857
+ );
858
+ }
859
+ ```
860
+
861
+ ## 🛠️ Development
862
+
863
+ ### Local Development
864
+
865
+ ```bash
866
+ # Install dependencies
867
+ npm install
868
+
869
+ # Start development server
870
+ npm run dev
871
+
872
+ # Build for production
873
+ npm run build
874
+ ```
875
+
876
+ ### Testing
877
+
878
+ ```bash
879
+ # Run tests
880
+ npm test
881
+
882
+ # Run tests with coverage
883
+ npm run test:coverage
884
+ ```
885
+
886
+ ### Linting
887
+
888
+ ```bash
889
+ # Check code style
890
+ npm run lint
891
+
892
+ # Fix linting issues
893
+ npm run lint:fix
894
+ ```
895
+
896
+ ## 📦 Build & Deploy
897
+
898
+ ### Building Your Plugin
899
+
900
+ ```bash
901
+ # Build optimized bundle
902
+ npm run build
903
+
904
+ # Analyze bundle size
905
+ npm run analyze
906
+ ```
907
+
908
+ ### Deployment
909
+
910
+ ```bash
911
+ # Deploy using TagadaPay CLI
912
+ npx @tagadapay/plugin-cli deploy
913
+
914
+ # Deploy specific environment
915
+ npx @tagadapay/plugin-cli deploy --env production
916
+ ```
917
+
918
+ ## 🔧 Configuration
919
+
920
+ ### Plugin Configuration
921
+
922
+ ```json
923
+ {
924
+ "name": "My Checkout Plugin",
925
+ "version": "1.0.0",
926
+ "description": "Custom checkout experience",
927
+ "main": "dist/index.js",
928
+ "tagadapay": {
929
+ "type": "checkout",
930
+ "mode": "direct",
931
+ "framework": "react"
932
+ }
933
+ }
934
+ ```
935
+
936
+ ## 🔐 Security
937
+
938
+ ### Best Practices
939
+
940
+ - Never store sensitive payment data
941
+ - Always validate user inputs
942
+ - Use HTTPS in production
943
+ - Implement proper error handling
944
+ - Follow PCI DSS guidelines
945
+
946
+ ### Token Management
947
+
948
+ ```typescript
949
+ // ✅ Good: Use tokenized payments
950
+ const paymentToken = await tokenizePayment(cardData);
951
+ await processPayment({ token: paymentToken });
952
+
953
+ // ❌ Bad: Never store raw card data
954
+ // const cardNumber = '4111111111111111'; // Don't do this
955
+ ```
956
+
957
+ ## 📱 Mobile Optimization
958
+
959
+ ### Responsive Design
960
+
961
+ ```css
962
+ .checkout-container {
963
+ max-width: 600px;
964
+ margin: 0 auto;
965
+ padding: 16px;
966
+ }
967
+
968
+ @media (max-width: 768px) {
969
+ .checkout-container {
970
+ padding: 8px;
971
+ }
972
+
973
+ .checkout-form {
974
+ font-size: 16px; /* Prevent zoom on iOS */
975
+ }
976
+ }
977
+ ```
978
+
979
+ ### Touch Interactions
980
+
981
+ ```typescript
982
+ const handleTouchStart = (e) => {
983
+ // Optimize for touch devices
984
+ e.preventDefault();
985
+ // Handle touch interaction
986
+ };
987
+ ```
988
+
989
+ ## 🌐 Internationalization
990
+
991
+ ### Multi-language Support
992
+
993
+ ```typescript
994
+ import { useTranslation } from '@tagadapay/plugin-sdk';
995
+
996
+ function CheckoutForm() {
997
+ const { t } = useTranslation();
998
+
999
+ return (
1000
+ <form>
1001
+ <label>{t('checkout.email')}</label>
1002
+ <input type="email" placeholder={t('checkout.email_placeholder')} />
1003
+ </form>
1004
+ );
1005
+ }
1006
+ ```
1007
+
1008
+ ### Currency Support
1009
+
1010
+ ```typescript
1011
+ import { useCurrency } from '@tagadapay/plugin-sdk';
1012
+
1013
+ function PriceDisplay({ amount }) {
1014
+ const { formatPrice, currency } = useCurrency();
1015
+
1016
+ return <span>{formatPrice(amount, currency)}</span>;
1017
+ }
1018
+ ```
1019
+
1020
+ ## 📊 Analytics & Monitoring
1021
+
1022
+ ### Event Tracking
1023
+
1024
+ ```typescript
1025
+ import { trackEvent } from '@tagadapay/plugin-sdk';
1026
+
1027
+ // Track user interactions
1028
+ trackEvent('checkout_started', {
1029
+ product_id: 'prod_123',
1030
+ value: 2999,
1031
+ currency: 'USD',
1032
+ });
1033
+
1034
+ // Track conversions
1035
+ trackEvent('purchase_completed', {
1036
+ transaction_id: 'txn_456',
1037
+ value: 2999,
1038
+ currency: 'USD',
1039
+ });
1040
+ ```
1041
+
1042
+ ### Performance Monitoring
1043
+
1044
+ ```typescript
1045
+ import { performance } from '@tagadapay/plugin-sdk';
1046
+
1047
+ // Measure load times
1048
+ performance.mark('checkout-start');
1049
+ // ... checkout logic
1050
+ performance.mark('checkout-end');
1051
+ performance.measure('checkout-duration', 'checkout-start', 'checkout-end');
1052
+ ```
1053
+
1054
+ ## 🤝 Contributing
1055
+
1056
+ ### Development Setup
1057
+
1058
+ ```bash
1059
+ # Clone the repository
1060
+ git clone https://github.com/tagadapay/plugin-sdk.git
1061
+
1062
+ # Install dependencies
1063
+ npm install
1064
+
1065
+ # Start development
1066
+ npm run dev
1067
+ ```
1068
+
1069
+ ### Submitting Changes
1070
+
1071
+ 1. Fork the repository
1072
+ 2. Create a feature branch
1073
+ 3. Make your changes
1074
+ 4. Add tests
1075
+ 5. Submit a pull request
1076
+
1077
+ ## 📄 License
1078
+
1079
+ MIT License - see [LICENSE](./LICENSE) for details.
1080
+
1081
+ ## 🆘 Support
1082
+
1083
+ - **Documentation**: [docs.tagadapay.com](https://docs.tagadapay.com)
1084
+ - **Discord**: [discord.gg/tagadapay](https://discord.gg/tagadapay)
1085
+ - **Email**: support@tagadapay.com
1086
+ - **GitHub Issues**: [github.com/tagadapay/plugin-sdk/issues](https://github.com/tagadapay/plugin-sdk/issues)
1087
+
1088
+ ---
1089
+
1090
+ Built with ❤️ by the TagadaPay team