@tagadapay/plugin-sdk 2.2.3 → 2.2.4
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,511 +1,511 @@
|
|
|
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
|
-
- **[Google Autocomplete](./docs/README-google-autocomplete.md)** - Address autocomplete with Google Places API
|
|
19
|
-
- **[ISO Data](./docs/README-iso-data.md)** - Country and region data with Google integration
|
|
20
|
-
|
|
21
|
-
### Examples
|
|
22
|
-
|
|
23
|
-
- **[Vite Checkout Demo](../checkout-vite)** - Complete checkout implementation
|
|
24
|
-
|
|
25
|
-
## 🏗️ Building a Plugin
|
|
26
|
-
|
|
27
|
-
### Plugin Structure
|
|
28
|
-
|
|
29
|
-
Every TagadaPay plugin follows this simple structure:
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
my-plugin/
|
|
33
|
-
├── plugin.manifest.json # Plugin metadata & routing
|
|
34
|
-
├── .local.json # Local dev config (auto-injected in production)
|
|
35
|
-
├── config/ # Optional deployment configs
|
|
36
|
-
│ ├── theme-green.json # Config variant A
|
|
37
|
-
│ └── theme-blue.json # Config variant B
|
|
38
|
-
├── src/
|
|
39
|
-
│ └── App.tsx # Your plugin code
|
|
40
|
-
└── dist/ # Built plugin files
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### Configuration Flow
|
|
44
|
-
|
|
45
|
-
```mermaid
|
|
46
|
-
graph TD
|
|
47
|
-
A[🛠️ Local Development] --> B[.local.json]
|
|
48
|
-
A --> C[config/*.json]
|
|
49
|
-
B --> D[usePluginConfig()]
|
|
50
|
-
C --> D
|
|
51
|
-
|
|
52
|
-
E[🚀 Production] --> F[Platform Injection]
|
|
53
|
-
F --> G[HTTP Headers & Meta Tags]
|
|
54
|
-
G --> D
|
|
55
|
-
|
|
56
|
-
D --> H[Your Plugin Component]
|
|
57
|
-
|
|
58
|
-
style A fill:#e1f5fe
|
|
59
|
-
style E fill:#f3e5f5
|
|
60
|
-
style D fill:#fff3e0
|
|
61
|
-
style H fill:#e8f5e8
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### Essential Files
|
|
65
|
-
|
|
66
|
-
#### 1. **`plugin.manifest.json`** - Plugin Metadata
|
|
67
|
-
|
|
68
|
-
```json
|
|
69
|
-
{
|
|
70
|
-
"pluginId": "my-awesome-plugin",
|
|
71
|
-
"name": "My Awesome Plugin",
|
|
72
|
-
"version": "1.0.0",
|
|
73
|
-
"mode": "direct-mode",
|
|
74
|
-
"router": {
|
|
75
|
-
"basePath": "/",
|
|
76
|
-
"matcher": ".*",
|
|
77
|
-
"excluder": "/checkout"
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
#### 2. **`.local.json`** - Local Development Context
|
|
83
|
-
|
|
84
|
-
```json
|
|
85
|
-
{
|
|
86
|
-
"storeId": "store_abc123",
|
|
87
|
-
"accountId": "acc_xyz789",
|
|
88
|
-
"basePath": "/"
|
|
89
|
-
}
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
> ⚠️ **Auto-managed**: This file is only for local dev. In production, the platform injects this data automatically.
|
|
93
|
-
|
|
94
|
-
#### 3. **`config/my-theme.json`** - Optional Deployment Config
|
|
95
|
-
|
|
96
|
-
```json
|
|
97
|
-
{
|
|
98
|
-
"configName": "green-theme",
|
|
99
|
-
"branding": {
|
|
100
|
-
"primaryColor": "#059669",
|
|
101
|
-
"companyName": "My Store",
|
|
102
|
-
"logoUrl": "https://example.com/logo.png"
|
|
103
|
-
},
|
|
104
|
-
"features": {
|
|
105
|
-
"enableChat": true,
|
|
106
|
-
"maxItems": 10
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
> 📝 **Note**: Config can contain any keys you need - the SDK doesn't enforce a specific structure.
|
|
112
|
-
|
|
113
|
-
## 🚀 Quick Start
|
|
114
|
-
|
|
115
|
-
### Installation
|
|
116
|
-
|
|
117
|
-
```bash
|
|
118
|
-
npm install @tagadapay/plugin-sdk
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### Basic Plugin Setup
|
|
122
|
-
|
|
123
|
-
```tsx
|
|
124
|
-
import React from 'react';
|
|
125
|
-
import {
|
|
126
|
-
TagadaProvider,
|
|
127
|
-
usePluginConfig,
|
|
128
|
-
useGoogleAutocomplete,
|
|
129
|
-
useISOData,
|
|
130
|
-
} from '@tagadapay/plugin-sdk/react';
|
|
131
|
-
|
|
132
|
-
function MyPlugin() {
|
|
133
|
-
const { storeId, accountId, basePath, config, loading } = usePluginConfig();
|
|
134
|
-
|
|
135
|
-
// Optional: Add address autocomplete
|
|
136
|
-
const { searchPlaces, predictions } = useGoogleAutocomplete({
|
|
137
|
-
apiKey: config?.googleMapsApiKey || 'YOUR_API_KEY',
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
// Optional: Add country/region data
|
|
141
|
-
const { countries } = useISOData('en');
|
|
142
|
-
|
|
143
|
-
if (loading) return <div>Loading...</div>;
|
|
144
|
-
|
|
145
|
-
return (
|
|
146
|
-
<div style={{ '--primary': config?.branding?.primaryColor }}>
|
|
147
|
-
<h1>Welcome to {config?.branding?.companyName}</h1>
|
|
148
|
-
<p>Store: {storeId}</p>
|
|
149
|
-
<p>Base Path: {basePath}</p>
|
|
150
|
-
<p>Available Countries: {Object.keys(countries).length}</p>
|
|
151
|
-
</div>
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Wrap your plugin with TagadaProvider
|
|
156
|
-
function App() {
|
|
157
|
-
return (
|
|
158
|
-
<TagadaProvider>
|
|
159
|
-
<MyPlugin />
|
|
160
|
-
</TagadaProvider>
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export default App;
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
### Development vs Production
|
|
168
|
-
|
|
169
|
-
| Environment | Store/Account ID | Deployment Config | How it Works |
|
|
170
|
-
| -------------- | ---------------- | ----------------- | ------------------ |
|
|
171
|
-
| **Local Dev** | `.local.json` | `config/*.json` | Files on disk |
|
|
172
|
-
| **Production** | HTTP Headers | Meta Tags | Platform injection |
|
|
173
|
-
|
|
174
|
-
```tsx
|
|
175
|
-
// ✅ ALWAYS use hooks - works in both environments
|
|
176
|
-
const { storeId, accountId, basePath, config } = usePluginConfig();
|
|
177
|
-
|
|
178
|
-
// ❌ NEVER access directly
|
|
179
|
-
// const config = window.__PLUGIN_CONFIG__; // Doesn't exist!
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
## 🎯 Key Features
|
|
183
|
-
|
|
184
|
-
### 🔧 **Plugin Configuration System**
|
|
185
|
-
|
|
186
|
-
- **Automatic Context Injection** - Store ID, Account ID, and custom config
|
|
187
|
-
- **Development & Production** - Seamless environment switching
|
|
188
|
-
- **Generic Configuration** - Support for any JSON structure
|
|
189
|
-
- **React Hooks** - Clean, type-safe configuration access
|
|
190
|
-
|
|
191
|
-
### 💳 **Payment Processing**
|
|
192
|
-
|
|
193
|
-
- Secure tokenized payments
|
|
194
|
-
- Multiple payment method support
|
|
195
|
-
- Real-time validation
|
|
196
|
-
- PCI compliance
|
|
197
|
-
|
|
198
|
-
### 🌍 **Address & Location**
|
|
199
|
-
|
|
200
|
-
- **Google Places Autocomplete** - Automatic API loading and address parsing
|
|
201
|
-
- **ISO Country/Region Data** - Complete ISO 3166-1/3166-2 database
|
|
202
|
-
- **Address Validation** - Structured component extraction
|
|
203
|
-
- **Multi-language Support** - 11+ languages for international users
|
|
204
|
-
|
|
205
|
-
### 🛒 **E-commerce Features**
|
|
206
|
-
|
|
207
|
-
- Dynamic pricing and promotional offers
|
|
208
|
-
- Cart management and tax calculations
|
|
209
|
-
- Currency conversion and formatting
|
|
210
|
-
- Customer profile management
|
|
211
|
-
|
|
212
|
-
### 🎨 **UI & Development**
|
|
213
|
-
|
|
214
|
-
- Pre-built React components
|
|
215
|
-
- Customizable themes with configuration
|
|
216
|
-
- Mobile-optimized and accessible
|
|
217
|
-
- TypeScript support throughout
|
|
218
|
-
|
|
219
|
-
## 📖 API Reference
|
|
220
|
-
|
|
221
|
-
### Core Hooks
|
|
222
|
-
|
|
223
|
-
#### useCheckout()
|
|
224
|
-
|
|
225
|
-
Primary hook for checkout state management.
|
|
226
|
-
|
|
227
|
-
```typescript
|
|
228
|
-
const {
|
|
229
|
-
customer, // Customer information
|
|
230
|
-
cart, // Shopping cart state
|
|
231
|
-
payment, // Payment details
|
|
232
|
-
shipping, // Shipping information
|
|
233
|
-
loading, // Loading states
|
|
234
|
-
errors, // Error handling
|
|
235
|
-
} = useCheckout();
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
#### useOffers()
|
|
239
|
-
|
|
240
|
-
Hook for managing dynamic offers and pricing.
|
|
241
|
-
|
|
242
|
-
```typescript
|
|
243
|
-
const {
|
|
244
|
-
offers, // Available offers
|
|
245
|
-
applyOffer, // Apply offer function
|
|
246
|
-
removeOffer, // Remove offer function
|
|
247
|
-
total, // Calculated total
|
|
248
|
-
} = useOffers();
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
### Utility Functions
|
|
252
|
-
|
|
253
|
-
#### setCheckoutInfo()
|
|
254
|
-
|
|
255
|
-
Update checkout information with validation.
|
|
256
|
-
|
|
257
|
-
```typescript
|
|
258
|
-
await setCheckoutInfo({
|
|
259
|
-
customer: {
|
|
260
|
-
email: 'user@example.com',
|
|
261
|
-
firstName: 'John',
|
|
262
|
-
lastName: 'Doe',
|
|
263
|
-
},
|
|
264
|
-
payment: {
|
|
265
|
-
method: 'card',
|
|
266
|
-
token: 'pm_token_123',
|
|
267
|
-
},
|
|
268
|
-
});
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
#### Money utilities
|
|
272
|
-
|
|
273
|
-
Format and calculate monetary values.
|
|
274
|
-
|
|
275
|
-
```typescript
|
|
276
|
-
import { formatMoney, convertCurrency } from '@tagadapay/plugin-sdk';
|
|
277
|
-
|
|
278
|
-
const formatted = formatMoney(2999, 'USD'); // "$29.99"
|
|
279
|
-
const converted = convertCurrency(2999, 'USD', 'EUR'); // 2699
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
## 🛠️ Development
|
|
283
|
-
|
|
284
|
-
### Local Development
|
|
285
|
-
|
|
286
|
-
```bash
|
|
287
|
-
# Install dependencies
|
|
288
|
-
npm install
|
|
289
|
-
|
|
290
|
-
# Start development server
|
|
291
|
-
npm run dev
|
|
292
|
-
|
|
293
|
-
# Build for production
|
|
294
|
-
npm run build
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
### Testing
|
|
298
|
-
|
|
299
|
-
```bash
|
|
300
|
-
# Run tests
|
|
301
|
-
npm test
|
|
302
|
-
|
|
303
|
-
# Run tests with coverage
|
|
304
|
-
npm run test:coverage
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
### Linting
|
|
308
|
-
|
|
309
|
-
```bash
|
|
310
|
-
# Check code style
|
|
311
|
-
npm run lint
|
|
312
|
-
|
|
313
|
-
# Fix linting issues
|
|
314
|
-
npm run lint:fix
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
## 📦 Build & Deploy
|
|
318
|
-
|
|
319
|
-
### Building Your Plugin
|
|
320
|
-
|
|
321
|
-
```bash
|
|
322
|
-
# Build optimized bundle
|
|
323
|
-
npm run build
|
|
324
|
-
|
|
325
|
-
# Analyze bundle size
|
|
326
|
-
npm run analyze
|
|
327
|
-
```
|
|
328
|
-
|
|
329
|
-
### Deployment
|
|
330
|
-
|
|
331
|
-
```bash
|
|
332
|
-
# Deploy using TagadaPay CLI
|
|
333
|
-
npx @tagadapay/plugin-cli deploy
|
|
334
|
-
|
|
335
|
-
# Deploy specific environment
|
|
336
|
-
npx @tagadapay/plugin-cli deploy --env production
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
## 🔧 Configuration
|
|
340
|
-
|
|
341
|
-
### Plugin Configuration
|
|
342
|
-
|
|
343
|
-
```json
|
|
344
|
-
{
|
|
345
|
-
"name": "My Checkout Plugin",
|
|
346
|
-
"version": "1.0.0",
|
|
347
|
-
"description": "Custom checkout experience",
|
|
348
|
-
"main": "dist/index.js",
|
|
349
|
-
"tagadapay": {
|
|
350
|
-
"type": "checkout",
|
|
351
|
-
"mode": "direct",
|
|
352
|
-
"framework": "react"
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
```
|
|
356
|
-
|
|
357
|
-
## 🔐 Security
|
|
358
|
-
|
|
359
|
-
### Best Practices
|
|
360
|
-
|
|
361
|
-
- Never store sensitive payment data
|
|
362
|
-
- Always validate user inputs
|
|
363
|
-
- Use HTTPS in production
|
|
364
|
-
- Implement proper error handling
|
|
365
|
-
- Follow PCI DSS guidelines
|
|
366
|
-
|
|
367
|
-
### Token Management
|
|
368
|
-
|
|
369
|
-
```typescript
|
|
370
|
-
// ✅ Good: Use tokenized payments
|
|
371
|
-
const paymentToken = await tokenizePayment(cardData);
|
|
372
|
-
await processPayment({ token: paymentToken });
|
|
373
|
-
|
|
374
|
-
// ❌ Bad: Never store raw card data
|
|
375
|
-
// const cardNumber = '4111111111111111'; // Don't do this
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
## 📱 Mobile Optimization
|
|
379
|
-
|
|
380
|
-
### Responsive Design
|
|
381
|
-
|
|
382
|
-
```css
|
|
383
|
-
.checkout-container {
|
|
384
|
-
max-width: 600px;
|
|
385
|
-
margin: 0 auto;
|
|
386
|
-
padding: 16px;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
@media (max-width: 768px) {
|
|
390
|
-
.checkout-container {
|
|
391
|
-
padding: 8px;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
.checkout-form {
|
|
395
|
-
font-size: 16px; /* Prevent zoom on iOS */
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
```
|
|
399
|
-
|
|
400
|
-
### Touch Interactions
|
|
401
|
-
|
|
402
|
-
```typescript
|
|
403
|
-
const handleTouchStart = (e) => {
|
|
404
|
-
// Optimize for touch devices
|
|
405
|
-
e.preventDefault();
|
|
406
|
-
// Handle touch interaction
|
|
407
|
-
};
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
## 🌐 Internationalization
|
|
411
|
-
|
|
412
|
-
### Multi-language Support
|
|
413
|
-
|
|
414
|
-
```typescript
|
|
415
|
-
import { useTranslation } from '@tagadapay/plugin-sdk';
|
|
416
|
-
|
|
417
|
-
function CheckoutForm() {
|
|
418
|
-
const { t } = useTranslation();
|
|
419
|
-
|
|
420
|
-
return (
|
|
421
|
-
<form>
|
|
422
|
-
<label>{t('checkout.email')}</label>
|
|
423
|
-
<input type="email" placeholder={t('checkout.email_placeholder')} />
|
|
424
|
-
</form>
|
|
425
|
-
);
|
|
426
|
-
}
|
|
427
|
-
```
|
|
428
|
-
|
|
429
|
-
### Currency Support
|
|
430
|
-
|
|
431
|
-
```typescript
|
|
432
|
-
import { useCurrency } from '@tagadapay/plugin-sdk';
|
|
433
|
-
|
|
434
|
-
function PriceDisplay({ amount }) {
|
|
435
|
-
const { formatPrice, currency } = useCurrency();
|
|
436
|
-
|
|
437
|
-
return <span>{formatPrice(amount, currency)}</span>;
|
|
438
|
-
}
|
|
439
|
-
```
|
|
440
|
-
|
|
441
|
-
## 📊 Analytics & Monitoring
|
|
442
|
-
|
|
443
|
-
### Event Tracking
|
|
444
|
-
|
|
445
|
-
```typescript
|
|
446
|
-
import { trackEvent } from '@tagadapay/plugin-sdk';
|
|
447
|
-
|
|
448
|
-
// Track user interactions
|
|
449
|
-
trackEvent('checkout_started', {
|
|
450
|
-
product_id: 'prod_123',
|
|
451
|
-
value: 2999,
|
|
452
|
-
currency: 'USD',
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
// Track conversions
|
|
456
|
-
trackEvent('purchase_completed', {
|
|
457
|
-
transaction_id: 'txn_456',
|
|
458
|
-
value: 2999,
|
|
459
|
-
currency: 'USD',
|
|
460
|
-
});
|
|
461
|
-
```
|
|
462
|
-
|
|
463
|
-
### Performance Monitoring
|
|
464
|
-
|
|
465
|
-
```typescript
|
|
466
|
-
import { performance } from '@tagadapay/plugin-sdk';
|
|
467
|
-
|
|
468
|
-
// Measure load times
|
|
469
|
-
performance.mark('checkout-start');
|
|
470
|
-
// ... checkout logic
|
|
471
|
-
performance.mark('checkout-end');
|
|
472
|
-
performance.measure('checkout-duration', 'checkout-start', 'checkout-end');
|
|
473
|
-
```
|
|
474
|
-
|
|
475
|
-
## 🤝 Contributing
|
|
476
|
-
|
|
477
|
-
### Development Setup
|
|
478
|
-
|
|
479
|
-
```bash
|
|
480
|
-
# Clone the repository
|
|
481
|
-
git clone https://github.com/tagadapay/plugin-sdk.git
|
|
482
|
-
|
|
483
|
-
# Install dependencies
|
|
484
|
-
npm install
|
|
485
|
-
|
|
486
|
-
# Start development
|
|
487
|
-
npm run dev
|
|
488
|
-
```
|
|
489
|
-
|
|
490
|
-
### Submitting Changes
|
|
491
|
-
|
|
492
|
-
1. Fork the repository
|
|
493
|
-
2. Create a feature branch
|
|
494
|
-
3. Make your changes
|
|
495
|
-
4. Add tests
|
|
496
|
-
5. Submit a pull request
|
|
497
|
-
|
|
498
|
-
## 📄 License
|
|
499
|
-
|
|
500
|
-
MIT License - see [LICENSE](./LICENSE) for details.
|
|
501
|
-
|
|
502
|
-
## 🆘 Support
|
|
503
|
-
|
|
504
|
-
- **Documentation**: [docs.tagadapay.com](https://docs.tagadapay.com)
|
|
505
|
-
- **Discord**: [discord.gg/tagadapay](https://discord.gg/tagadapay)
|
|
506
|
-
- **Email**: support@tagadapay.com
|
|
507
|
-
- **GitHub Issues**: [github.com/tagadapay/plugin-sdk/issues](https://github.com/tagadapay/plugin-sdk/issues)
|
|
508
|
-
|
|
509
|
-
---
|
|
510
|
-
|
|
511
|
-
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
|
+
- **[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
|
+
- **[Google Autocomplete](./docs/README-google-autocomplete.md)** - Address autocomplete with Google Places API
|
|
19
|
+
- **[ISO Data](./docs/README-iso-data.md)** - Country and region data with Google integration
|
|
20
|
+
|
|
21
|
+
### Examples
|
|
22
|
+
|
|
23
|
+
- **[Vite Checkout Demo](../checkout-vite)** - Complete checkout implementation
|
|
24
|
+
|
|
25
|
+
## 🏗️ Building a Plugin
|
|
26
|
+
|
|
27
|
+
### Plugin Structure
|
|
28
|
+
|
|
29
|
+
Every TagadaPay plugin follows this simple structure:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
my-plugin/
|
|
33
|
+
├── plugin.manifest.json # Plugin metadata & routing
|
|
34
|
+
├── .local.json # Local dev config (auto-injected in production)
|
|
35
|
+
├── config/ # Optional deployment configs
|
|
36
|
+
│ ├── theme-green.json # Config variant A
|
|
37
|
+
│ └── theme-blue.json # Config variant B
|
|
38
|
+
├── src/
|
|
39
|
+
│ └── App.tsx # Your plugin code
|
|
40
|
+
└── dist/ # Built plugin files
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Configuration Flow
|
|
44
|
+
|
|
45
|
+
```mermaid
|
|
46
|
+
graph TD
|
|
47
|
+
A[🛠️ Local Development] --> B[.local.json]
|
|
48
|
+
A --> C[config/*.json]
|
|
49
|
+
B --> D[usePluginConfig()]
|
|
50
|
+
C --> D
|
|
51
|
+
|
|
52
|
+
E[🚀 Production] --> F[Platform Injection]
|
|
53
|
+
F --> G[HTTP Headers & Meta Tags]
|
|
54
|
+
G --> D
|
|
55
|
+
|
|
56
|
+
D --> H[Your Plugin Component]
|
|
57
|
+
|
|
58
|
+
style A fill:#e1f5fe
|
|
59
|
+
style E fill:#f3e5f5
|
|
60
|
+
style D fill:#fff3e0
|
|
61
|
+
style H fill:#e8f5e8
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Essential Files
|
|
65
|
+
|
|
66
|
+
#### 1. **`plugin.manifest.json`** - Plugin Metadata
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"pluginId": "my-awesome-plugin",
|
|
71
|
+
"name": "My Awesome Plugin",
|
|
72
|
+
"version": "1.0.0",
|
|
73
|
+
"mode": "direct-mode",
|
|
74
|
+
"router": {
|
|
75
|
+
"basePath": "/",
|
|
76
|
+
"matcher": ".*",
|
|
77
|
+
"excluder": "/checkout"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
#### 2. **`.local.json`** - Local Development Context
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"storeId": "store_abc123",
|
|
87
|
+
"accountId": "acc_xyz789",
|
|
88
|
+
"basePath": "/"
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
> ⚠️ **Auto-managed**: This file is only for local dev. In production, the platform injects this data automatically.
|
|
93
|
+
|
|
94
|
+
#### 3. **`config/my-theme.json`** - Optional Deployment Config
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"configName": "green-theme",
|
|
99
|
+
"branding": {
|
|
100
|
+
"primaryColor": "#059669",
|
|
101
|
+
"companyName": "My Store",
|
|
102
|
+
"logoUrl": "https://example.com/logo.png"
|
|
103
|
+
},
|
|
104
|
+
"features": {
|
|
105
|
+
"enableChat": true,
|
|
106
|
+
"maxItems": 10
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
> 📝 **Note**: Config can contain any keys you need - the SDK doesn't enforce a specific structure.
|
|
112
|
+
|
|
113
|
+
## 🚀 Quick Start
|
|
114
|
+
|
|
115
|
+
### Installation
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
npm install @tagadapay/plugin-sdk
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Basic Plugin Setup
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
import React from 'react';
|
|
125
|
+
import {
|
|
126
|
+
TagadaProvider,
|
|
127
|
+
usePluginConfig,
|
|
128
|
+
useGoogleAutocomplete,
|
|
129
|
+
useISOData,
|
|
130
|
+
} from '@tagadapay/plugin-sdk/react';
|
|
131
|
+
|
|
132
|
+
function MyPlugin() {
|
|
133
|
+
const { storeId, accountId, basePath, config, loading } = usePluginConfig();
|
|
134
|
+
|
|
135
|
+
// Optional: Add address autocomplete
|
|
136
|
+
const { searchPlaces, predictions } = useGoogleAutocomplete({
|
|
137
|
+
apiKey: config?.googleMapsApiKey || 'YOUR_API_KEY',
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Optional: Add country/region data
|
|
141
|
+
const { countries } = useISOData('en');
|
|
142
|
+
|
|
143
|
+
if (loading) return <div>Loading...</div>;
|
|
144
|
+
|
|
145
|
+
return (
|
|
146
|
+
<div style={{ '--primary': config?.branding?.primaryColor }}>
|
|
147
|
+
<h1>Welcome to {config?.branding?.companyName}</h1>
|
|
148
|
+
<p>Store: {storeId}</p>
|
|
149
|
+
<p>Base Path: {basePath}</p>
|
|
150
|
+
<p>Available Countries: {Object.keys(countries).length}</p>
|
|
151
|
+
</div>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Wrap your plugin with TagadaProvider
|
|
156
|
+
function App() {
|
|
157
|
+
return (
|
|
158
|
+
<TagadaProvider>
|
|
159
|
+
<MyPlugin />
|
|
160
|
+
</TagadaProvider>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export default App;
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Development vs Production
|
|
168
|
+
|
|
169
|
+
| Environment | Store/Account ID | Deployment Config | How it Works |
|
|
170
|
+
| -------------- | ---------------- | ----------------- | ------------------ |
|
|
171
|
+
| **Local Dev** | `.local.json` | `config/*.json` | Files on disk |
|
|
172
|
+
| **Production** | HTTP Headers | Meta Tags | Platform injection |
|
|
173
|
+
|
|
174
|
+
```tsx
|
|
175
|
+
// ✅ ALWAYS use hooks - works in both environments
|
|
176
|
+
const { storeId, accountId, basePath, config } = usePluginConfig();
|
|
177
|
+
|
|
178
|
+
// ❌ NEVER access directly
|
|
179
|
+
// const config = window.__PLUGIN_CONFIG__; // Doesn't exist!
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## 🎯 Key Features
|
|
183
|
+
|
|
184
|
+
### 🔧 **Plugin Configuration System**
|
|
185
|
+
|
|
186
|
+
- **Automatic Context Injection** - Store ID, Account ID, and custom config
|
|
187
|
+
- **Development & Production** - Seamless environment switching
|
|
188
|
+
- **Generic Configuration** - Support for any JSON structure
|
|
189
|
+
- **React Hooks** - Clean, type-safe configuration access
|
|
190
|
+
|
|
191
|
+
### 💳 **Payment Processing**
|
|
192
|
+
|
|
193
|
+
- Secure tokenized payments
|
|
194
|
+
- Multiple payment method support
|
|
195
|
+
- Real-time validation
|
|
196
|
+
- PCI compliance
|
|
197
|
+
|
|
198
|
+
### 🌍 **Address & Location**
|
|
199
|
+
|
|
200
|
+
- **Google Places Autocomplete** - Automatic API loading and address parsing
|
|
201
|
+
- **ISO Country/Region Data** - Complete ISO 3166-1/3166-2 database
|
|
202
|
+
- **Address Validation** - Structured component extraction
|
|
203
|
+
- **Multi-language Support** - 11+ languages for international users
|
|
204
|
+
|
|
205
|
+
### 🛒 **E-commerce Features**
|
|
206
|
+
|
|
207
|
+
- Dynamic pricing and promotional offers
|
|
208
|
+
- Cart management and tax calculations
|
|
209
|
+
- Currency conversion and formatting
|
|
210
|
+
- Customer profile management
|
|
211
|
+
|
|
212
|
+
### 🎨 **UI & Development**
|
|
213
|
+
|
|
214
|
+
- Pre-built React components
|
|
215
|
+
- Customizable themes with configuration
|
|
216
|
+
- Mobile-optimized and accessible
|
|
217
|
+
- TypeScript support throughout
|
|
218
|
+
|
|
219
|
+
## 📖 API Reference
|
|
220
|
+
|
|
221
|
+
### Core Hooks
|
|
222
|
+
|
|
223
|
+
#### useCheckout()
|
|
224
|
+
|
|
225
|
+
Primary hook for checkout state management.
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
const {
|
|
229
|
+
customer, // Customer information
|
|
230
|
+
cart, // Shopping cart state
|
|
231
|
+
payment, // Payment details
|
|
232
|
+
shipping, // Shipping information
|
|
233
|
+
loading, // Loading states
|
|
234
|
+
errors, // Error handling
|
|
235
|
+
} = useCheckout();
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
#### useOffers()
|
|
239
|
+
|
|
240
|
+
Hook for managing dynamic offers and pricing.
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
const {
|
|
244
|
+
offers, // Available offers
|
|
245
|
+
applyOffer, // Apply offer function
|
|
246
|
+
removeOffer, // Remove offer function
|
|
247
|
+
total, // Calculated total
|
|
248
|
+
} = useOffers();
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Utility Functions
|
|
252
|
+
|
|
253
|
+
#### setCheckoutInfo()
|
|
254
|
+
|
|
255
|
+
Update checkout information with validation.
|
|
256
|
+
|
|
257
|
+
```typescript
|
|
258
|
+
await setCheckoutInfo({
|
|
259
|
+
customer: {
|
|
260
|
+
email: 'user@example.com',
|
|
261
|
+
firstName: 'John',
|
|
262
|
+
lastName: 'Doe',
|
|
263
|
+
},
|
|
264
|
+
payment: {
|
|
265
|
+
method: 'card',
|
|
266
|
+
token: 'pm_token_123',
|
|
267
|
+
},
|
|
268
|
+
});
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
#### Money utilities
|
|
272
|
+
|
|
273
|
+
Format and calculate monetary values.
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
import { formatMoney, convertCurrency } from '@tagadapay/plugin-sdk';
|
|
277
|
+
|
|
278
|
+
const formatted = formatMoney(2999, 'USD'); // "$29.99"
|
|
279
|
+
const converted = convertCurrency(2999, 'USD', 'EUR'); // 2699
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
## 🛠️ Development
|
|
283
|
+
|
|
284
|
+
### Local Development
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
# Install dependencies
|
|
288
|
+
npm install
|
|
289
|
+
|
|
290
|
+
# Start development server
|
|
291
|
+
npm run dev
|
|
292
|
+
|
|
293
|
+
# Build for production
|
|
294
|
+
npm run build
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Testing
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
# Run tests
|
|
301
|
+
npm test
|
|
302
|
+
|
|
303
|
+
# Run tests with coverage
|
|
304
|
+
npm run test:coverage
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Linting
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
# Check code style
|
|
311
|
+
npm run lint
|
|
312
|
+
|
|
313
|
+
# Fix linting issues
|
|
314
|
+
npm run lint:fix
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
## 📦 Build & Deploy
|
|
318
|
+
|
|
319
|
+
### Building Your Plugin
|
|
320
|
+
|
|
321
|
+
```bash
|
|
322
|
+
# Build optimized bundle
|
|
323
|
+
npm run build
|
|
324
|
+
|
|
325
|
+
# Analyze bundle size
|
|
326
|
+
npm run analyze
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### Deployment
|
|
330
|
+
|
|
331
|
+
```bash
|
|
332
|
+
# Deploy using TagadaPay CLI
|
|
333
|
+
npx @tagadapay/plugin-cli deploy
|
|
334
|
+
|
|
335
|
+
# Deploy specific environment
|
|
336
|
+
npx @tagadapay/plugin-cli deploy --env production
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
## 🔧 Configuration
|
|
340
|
+
|
|
341
|
+
### Plugin Configuration
|
|
342
|
+
|
|
343
|
+
```json
|
|
344
|
+
{
|
|
345
|
+
"name": "My Checkout Plugin",
|
|
346
|
+
"version": "1.0.0",
|
|
347
|
+
"description": "Custom checkout experience",
|
|
348
|
+
"main": "dist/index.js",
|
|
349
|
+
"tagadapay": {
|
|
350
|
+
"type": "checkout",
|
|
351
|
+
"mode": "direct",
|
|
352
|
+
"framework": "react"
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
## 🔐 Security
|
|
358
|
+
|
|
359
|
+
### Best Practices
|
|
360
|
+
|
|
361
|
+
- Never store sensitive payment data
|
|
362
|
+
- Always validate user inputs
|
|
363
|
+
- Use HTTPS in production
|
|
364
|
+
- Implement proper error handling
|
|
365
|
+
- Follow PCI DSS guidelines
|
|
366
|
+
|
|
367
|
+
### Token Management
|
|
368
|
+
|
|
369
|
+
```typescript
|
|
370
|
+
// ✅ Good: Use tokenized payments
|
|
371
|
+
const paymentToken = await tokenizePayment(cardData);
|
|
372
|
+
await processPayment({ token: paymentToken });
|
|
373
|
+
|
|
374
|
+
// ❌ Bad: Never store raw card data
|
|
375
|
+
// const cardNumber = '4111111111111111'; // Don't do this
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
## 📱 Mobile Optimization
|
|
379
|
+
|
|
380
|
+
### Responsive Design
|
|
381
|
+
|
|
382
|
+
```css
|
|
383
|
+
.checkout-container {
|
|
384
|
+
max-width: 600px;
|
|
385
|
+
margin: 0 auto;
|
|
386
|
+
padding: 16px;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
@media (max-width: 768px) {
|
|
390
|
+
.checkout-container {
|
|
391
|
+
padding: 8px;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
.checkout-form {
|
|
395
|
+
font-size: 16px; /* Prevent zoom on iOS */
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
### Touch Interactions
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
const handleTouchStart = (e) => {
|
|
404
|
+
// Optimize for touch devices
|
|
405
|
+
e.preventDefault();
|
|
406
|
+
// Handle touch interaction
|
|
407
|
+
};
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
## 🌐 Internationalization
|
|
411
|
+
|
|
412
|
+
### Multi-language Support
|
|
413
|
+
|
|
414
|
+
```typescript
|
|
415
|
+
import { useTranslation } from '@tagadapay/plugin-sdk';
|
|
416
|
+
|
|
417
|
+
function CheckoutForm() {
|
|
418
|
+
const { t } = useTranslation();
|
|
419
|
+
|
|
420
|
+
return (
|
|
421
|
+
<form>
|
|
422
|
+
<label>{t('checkout.email')}</label>
|
|
423
|
+
<input type="email" placeholder={t('checkout.email_placeholder')} />
|
|
424
|
+
</form>
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
### Currency Support
|
|
430
|
+
|
|
431
|
+
```typescript
|
|
432
|
+
import { useCurrency } from '@tagadapay/plugin-sdk';
|
|
433
|
+
|
|
434
|
+
function PriceDisplay({ amount }) {
|
|
435
|
+
const { formatPrice, currency } = useCurrency();
|
|
436
|
+
|
|
437
|
+
return <span>{formatPrice(amount, currency)}</span>;
|
|
438
|
+
}
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
## 📊 Analytics & Monitoring
|
|
442
|
+
|
|
443
|
+
### Event Tracking
|
|
444
|
+
|
|
445
|
+
```typescript
|
|
446
|
+
import { trackEvent } from '@tagadapay/plugin-sdk';
|
|
447
|
+
|
|
448
|
+
// Track user interactions
|
|
449
|
+
trackEvent('checkout_started', {
|
|
450
|
+
product_id: 'prod_123',
|
|
451
|
+
value: 2999,
|
|
452
|
+
currency: 'USD',
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
// Track conversions
|
|
456
|
+
trackEvent('purchase_completed', {
|
|
457
|
+
transaction_id: 'txn_456',
|
|
458
|
+
value: 2999,
|
|
459
|
+
currency: 'USD',
|
|
460
|
+
});
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
### Performance Monitoring
|
|
464
|
+
|
|
465
|
+
```typescript
|
|
466
|
+
import { performance } from '@tagadapay/plugin-sdk';
|
|
467
|
+
|
|
468
|
+
// Measure load times
|
|
469
|
+
performance.mark('checkout-start');
|
|
470
|
+
// ... checkout logic
|
|
471
|
+
performance.mark('checkout-end');
|
|
472
|
+
performance.measure('checkout-duration', 'checkout-start', 'checkout-end');
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
## 🤝 Contributing
|
|
476
|
+
|
|
477
|
+
### Development Setup
|
|
478
|
+
|
|
479
|
+
```bash
|
|
480
|
+
# Clone the repository
|
|
481
|
+
git clone https://github.com/tagadapay/plugin-sdk.git
|
|
482
|
+
|
|
483
|
+
# Install dependencies
|
|
484
|
+
npm install
|
|
485
|
+
|
|
486
|
+
# Start development
|
|
487
|
+
npm run dev
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
### Submitting Changes
|
|
491
|
+
|
|
492
|
+
1. Fork the repository
|
|
493
|
+
2. Create a feature branch
|
|
494
|
+
3. Make your changes
|
|
495
|
+
4. Add tests
|
|
496
|
+
5. Submit a pull request
|
|
497
|
+
|
|
498
|
+
## 📄 License
|
|
499
|
+
|
|
500
|
+
MIT License - see [LICENSE](./LICENSE) for details.
|
|
501
|
+
|
|
502
|
+
## 🆘 Support
|
|
503
|
+
|
|
504
|
+
- **Documentation**: [docs.tagadapay.com](https://docs.tagadapay.com)
|
|
505
|
+
- **Discord**: [discord.gg/tagadapay](https://discord.gg/tagadapay)
|
|
506
|
+
- **Email**: support@tagadapay.com
|
|
507
|
+
- **GitHub Issues**: [github.com/tagadapay/plugin-sdk/issues](https://github.com/tagadapay/plugin-sdk/issues)
|
|
508
|
+
|
|
509
|
+
---
|
|
510
|
+
|
|
511
|
+
Built with ❤️ by the TagadaPay team
|
|
@@ -188,51 +188,24 @@ export interface CheckoutSessionPreview {
|
|
|
188
188
|
totalAdjustedAmount: number;
|
|
189
189
|
totalPromotionAmount: number;
|
|
190
190
|
}
|
|
191
|
-
export interface CheckoutSummaryItem {
|
|
192
|
-
id: string;
|
|
193
|
-
productId: string;
|
|
194
|
-
variantId: string;
|
|
195
|
-
priceId: string;
|
|
196
|
-
product: {
|
|
197
|
-
name: string;
|
|
198
|
-
description: string;
|
|
199
|
-
};
|
|
200
|
-
variant: {
|
|
201
|
-
name: string;
|
|
202
|
-
description: string;
|
|
203
|
-
imageUrl: string;
|
|
204
|
-
grams: number;
|
|
205
|
-
};
|
|
206
|
-
sku: string;
|
|
207
|
-
unitAmount: number;
|
|
208
|
-
quantity: number;
|
|
209
|
-
amount: number;
|
|
210
|
-
adjustedAmount: number;
|
|
211
|
-
currency: string;
|
|
212
|
-
adjustments: any[];
|
|
213
|
-
recurring: boolean;
|
|
214
|
-
interval?: 'day' | 'week' | 'month' | 'year';
|
|
215
|
-
intervalCount?: number;
|
|
216
|
-
totalBillingCycles?: number;
|
|
217
|
-
unitAmountAfterFirstCycle?: number;
|
|
218
|
-
orderLineItemProduct: {
|
|
219
|
-
name: string;
|
|
220
|
-
};
|
|
221
|
-
orderLineItemVariant: {
|
|
222
|
-
name: string;
|
|
223
|
-
imageUrl: string;
|
|
224
|
-
};
|
|
225
|
-
metadata: {
|
|
226
|
-
originalIds: string[];
|
|
227
|
-
isConsolidated: boolean;
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
191
|
export interface CheckoutSummary {
|
|
231
192
|
currency: string;
|
|
232
193
|
totalAmount: number;
|
|
233
194
|
totalAdjustedAmount: number;
|
|
234
195
|
totalPromotionAmount: number;
|
|
235
|
-
items:
|
|
196
|
+
items: {
|
|
197
|
+
id: string;
|
|
198
|
+
name: string;
|
|
199
|
+
description: string | null;
|
|
200
|
+
imageUrl: string | null;
|
|
201
|
+
quantity: number;
|
|
202
|
+
unitAmount: number;
|
|
203
|
+
amount: number;
|
|
204
|
+
adjustedAmount: number;
|
|
205
|
+
currency: string;
|
|
206
|
+
isOrderBump: boolean;
|
|
207
|
+
orderBumpType?: string;
|
|
208
|
+
}[];
|
|
236
209
|
adjustments: {
|
|
237
210
|
type: string;
|
|
238
211
|
description: string;
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* - Store ID, Account ID, Base Path: from .local.json (dev) or headers (production)
|
|
6
6
|
* - Deployment Config: from config/*.json (dev) or meta tags (production)
|
|
7
7
|
*/
|
|
8
|
-
export interface PluginConfig
|
|
8
|
+
export interface PluginConfig {
|
|
9
9
|
storeId?: string;
|
|
10
10
|
accountId?: string;
|
|
11
11
|
basePath?: string;
|
|
12
|
-
config?:
|
|
12
|
+
config?: Record<string, any>;
|
|
13
13
|
}
|
|
14
14
|
export interface LocalDevConfig {
|
|
15
15
|
storeId: string;
|
|
@@ -25,11 +25,11 @@ export declare const loadPluginConfig: (configVariant?: string) => Promise<Plugi
|
|
|
25
25
|
* Main hook for plugin configuration
|
|
26
26
|
* Gets config from TagadaProvider context (no parameters needed)
|
|
27
27
|
*/
|
|
28
|
-
export declare const usePluginConfig:
|
|
28
|
+
export declare const usePluginConfig: () => {
|
|
29
29
|
storeId: string | undefined;
|
|
30
30
|
accountId: string | undefined;
|
|
31
31
|
basePath: string;
|
|
32
|
-
config:
|
|
32
|
+
config: Record<string, any>;
|
|
33
33
|
loading: boolean;
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
@@ -16,7 +16,12 @@ let configPromise = null;
|
|
|
16
16
|
const loadLocalDevConfig = async (configVariant = 'default') => {
|
|
17
17
|
try {
|
|
18
18
|
// Only try to load local config in development
|
|
19
|
-
|
|
19
|
+
// Use hostname-based detection for better Vite compatibility
|
|
20
|
+
const isLocalDev = typeof window !== 'undefined' &&
|
|
21
|
+
(window.location.hostname === 'localhost' ||
|
|
22
|
+
window.location.hostname.includes('.localhost') ||
|
|
23
|
+
window.location.hostname.includes('127.0.0.1'));
|
|
24
|
+
if (!isLocalDev) {
|
|
20
25
|
return null;
|
|
21
26
|
}
|
|
22
27
|
// Load local store/account config
|
|
@@ -176,7 +181,12 @@ export const clearPluginConfigCache = () => {
|
|
|
176
181
|
* Development helper to log current configuration
|
|
177
182
|
*/
|
|
178
183
|
export const debugPluginConfig = async (configVariant = 'default') => {
|
|
179
|
-
|
|
184
|
+
// Use hostname-based detection for better Vite compatibility
|
|
185
|
+
const isLocalDev = typeof window !== 'undefined' &&
|
|
186
|
+
(window.location.hostname === 'localhost' ||
|
|
187
|
+
window.location.hostname.includes('.localhost') ||
|
|
188
|
+
window.location.hostname.includes('127.0.0.1'));
|
|
189
|
+
if (!isLocalDev) {
|
|
180
190
|
return;
|
|
181
191
|
}
|
|
182
192
|
const config = await getPluginConfig(configVariant);
|
|
@@ -38,11 +38,11 @@ const InitializationLoader = () => (_jsxs("div", { style: {
|
|
|
38
38
|
borderTop: '1.5px solid #9ca3af',
|
|
39
39
|
borderRadius: '50%',
|
|
40
40
|
animation: 'tagada-spin 1s linear infinite',
|
|
41
|
-
} }), _jsx("span", { children: "Loading..." }), _jsx("style", { children: `
|
|
42
|
-
@keyframes tagada-spin {
|
|
43
|
-
0% { transform: rotate(0deg); }
|
|
44
|
-
100% { transform: rotate(360deg); }
|
|
45
|
-
}
|
|
41
|
+
} }), _jsx("span", { children: "Loading..." }), _jsx("style", { children: `
|
|
42
|
+
@keyframes tagada-spin {
|
|
43
|
+
0% { transform: rotate(0deg); }
|
|
44
|
+
100% { transform: rotate(360deg); }
|
|
45
|
+
}
|
|
46
46
|
` })] }));
|
|
47
47
|
const TagadaContext = createContext(null);
|
|
48
48
|
export function TagadaProvider({ children, environment, customApiConfig, debugMode, // Remove default, will be set based on environment
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tagadapay/plugin-sdk",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.4",
|
|
4
4
|
"description": "Modern React SDK for building Tagada Pay plugins",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,6 +16,24 @@
|
|
|
16
16
|
"require": "./dist/react/index.js"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"clean": "rm -rf dist",
|
|
22
|
+
"lint": "echo \"No linting configured\"",
|
|
23
|
+
"test": "echo \"No tests yet\" && exit 0",
|
|
24
|
+
"dev": "tsc --watch",
|
|
25
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
26
|
+
"publish:patch": "npm version patch && npm publish",
|
|
27
|
+
"publish:minor": "npm version minor && npm publish",
|
|
28
|
+
"publish:major": "npm version major && npm publish",
|
|
29
|
+
"publish:beta": "npm version prerelease --preid=beta && npm publish --tag beta",
|
|
30
|
+
"publish:alpha": "npm version prerelease --preid=alpha && npm publish --tag alpha",
|
|
31
|
+
"version:patch": "npm version patch",
|
|
32
|
+
"version:minor": "npm version minor",
|
|
33
|
+
"version:major": "npm version major",
|
|
34
|
+
"version:beta": "npm version prerelease --preid=beta",
|
|
35
|
+
"version:alpha": "npm version prerelease --preid=alpha"
|
|
36
|
+
},
|
|
19
37
|
"keywords": [
|
|
20
38
|
"tagadapay",
|
|
21
39
|
"cms",
|
|
@@ -56,22 +74,5 @@
|
|
|
56
74
|
"bugs": {
|
|
57
75
|
"url": "https://github.com/tagadapay/plugin-sdk/issues"
|
|
58
76
|
},
|
|
59
|
-
"homepage": "https://github.com/tagadapay/plugin-sdk#readme"
|
|
60
|
-
|
|
61
|
-
"build": "tsc",
|
|
62
|
-
"clean": "rm -rf dist",
|
|
63
|
-
"lint": "echo \"No linting configured\"",
|
|
64
|
-
"test": "echo \"No tests yet\" && exit 0",
|
|
65
|
-
"dev": "tsc --watch",
|
|
66
|
-
"publish:patch": "npm version patch && npm publish",
|
|
67
|
-
"publish:minor": "npm version minor && npm publish",
|
|
68
|
-
"publish:major": "npm version major && npm publish",
|
|
69
|
-
"publish:beta": "npm version prerelease --preid=beta && npm publish --tag beta",
|
|
70
|
-
"publish:alpha": "npm version prerelease --preid=alpha && npm publish --tag alpha",
|
|
71
|
-
"version:patch": "npm version patch",
|
|
72
|
-
"version:minor": "npm version minor",
|
|
73
|
-
"version:major": "npm version major",
|
|
74
|
-
"version:beta": "npm version prerelease --preid=beta",
|
|
75
|
-
"version:alpha": "npm version prerelease --preid=alpha"
|
|
76
|
-
}
|
|
77
|
-
}
|
|
77
|
+
"homepage": "https://github.com/tagadapay/plugin-sdk#readme"
|
|
78
|
+
}
|