@tagadapay/plugin-sdk 1.0.22 → 1.0.25

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,414 +1,414 @@
1
- # TagadaPay Plugin SDK
2
-
3
- A comprehensive SDK for building checkout plugins on the TagadaPay platform. Create custom checkout experiences with React components, payment processing, and advanced features.
4
-
5
- ## 📚 Documentation
6
-
7
- ### Core APIs
8
-
9
- - **[useCheckout](./README-useCheckout.md)** - Checkout state management and flow control
10
- - **[setCheckoutInfo](./README-setCheckoutInfo.md)** - Customer information and validation
11
- - **[useOffers](./README-useOffers.md)** - Dynamic pricing and promotional offers
12
- - **[Money utilities](./README-money.md)** - Currency formatting and calculations
13
- - **[URL utilities](./README-urlUtils.md)** - Navigation and routing helpers
14
-
15
- ### Examples
16
-
17
- - **[Vite Checkout Demo](../checkout-vite)** - Complete checkout implementation
18
-
19
- ## 🚀 Quick Start
20
-
21
- ### Installation
22
-
23
- ```bash
24
- npm install @tagadapay/plugin-sdk
25
- ```
26
-
27
- ### Basic Usage
28
-
29
- ```typescript
30
- import { useCheckout, setCheckoutInfo } from '@tagadapay/plugin-sdk';
31
-
32
- function CheckoutPage() {
33
- const { customer, cart, payment } = useCheckout();
34
-
35
- const handleSubmit = async (data) => {
36
- await setCheckoutInfo({
37
- customer: data.customer,
38
- payment: data.payment
39
- });
40
- };
41
-
42
- return (
43
- <div>
44
- {/* Your checkout UI */}
45
- </div>
46
- );
47
- }
48
- ```
49
-
50
- ## 🎯 Key Features
51
-
52
- ### Payment Processing
53
-
54
- - Secure tokenized payments
55
- - Multiple payment method support
56
- - Real-time validation
57
- - PCI compliance
58
-
59
- ### Customer Management
60
-
61
- - Profile management
62
- - Address validation
63
- - Order history
64
- - Preferences
65
-
66
- ### Cart & Pricing
67
-
68
- - Dynamic pricing
69
- - Promotional offers
70
- - Tax calculations
71
- - Currency conversion
72
-
73
- ### UI Components
74
-
75
- - Pre-built checkout components
76
- - Customizable themes
77
- - Mobile-optimized
78
- - Accessibility features
79
-
80
- ## 📖 API Reference
81
-
82
- ### Core Hooks
83
-
84
- #### useCheckout()
85
-
86
- Primary hook for checkout state management.
87
-
88
- ```typescript
89
- const {
90
- customer, // Customer information
91
- cart, // Shopping cart state
92
- payment, // Payment details
93
- shipping, // Shipping information
94
- loading, // Loading states
95
- errors, // Error handling
96
- } = useCheckout();
97
- ```
98
-
99
- #### useOffers()
100
-
101
- Hook for managing dynamic offers and pricing.
102
-
103
- ```typescript
104
- const {
105
- offers, // Available offers
106
- applyOffer, // Apply offer function
107
- removeOffer, // Remove offer function
108
- total, // Calculated total
109
- } = useOffers();
110
- ```
111
-
112
- ### Utility Functions
113
-
114
- #### setCheckoutInfo()
115
-
116
- Update checkout information with validation.
117
-
118
- ```typescript
119
- await setCheckoutInfo({
120
- customer: {
121
- email: 'user@example.com',
122
- firstName: 'John',
123
- lastName: 'Doe',
124
- },
125
- payment: {
126
- method: 'card',
127
- token: 'pm_token_123',
128
- },
129
- });
130
- ```
131
-
132
- #### Money utilities
133
-
134
- Format and calculate monetary values.
135
-
136
- ```typescript
137
- import { formatMoney, convertCurrency } from '@tagadapay/plugin-sdk';
138
-
139
- const formatted = formatMoney(2999, 'USD'); // "$29.99"
140
- const converted = convertCurrency(2999, 'USD', 'EUR'); // 2699
141
- ```
142
-
143
- ## 🛠️ Development
144
-
145
- ### Local Development
146
-
147
- ```bash
148
- # Install dependencies
149
- npm install
150
-
151
- # Start development server
152
- npm run dev
153
-
154
- # Build for production
155
- npm run build
156
- ```
157
-
158
- ### Testing
159
-
160
- ```bash
161
- # Run tests
162
- npm test
163
-
164
- # Run tests with coverage
165
- npm run test:coverage
166
- ```
167
-
168
- ### Linting
169
-
170
- ```bash
171
- # Check code style
172
- npm run lint
173
-
174
- # Fix linting issues
175
- npm run lint:fix
176
- ```
177
-
178
- ## 📦 Build & Deploy
179
-
180
- ### Building Your Plugin
181
-
182
- ```bash
183
- # Build optimized bundle
184
- npm run build
185
-
186
- # Analyze bundle size
187
- npm run analyze
188
- ```
189
-
190
- ### Deployment
191
-
192
- ```bash
193
- # Deploy using TagadaPay CLI
194
- npx @tagadapay/plugin-cli deploy
195
-
196
- # Deploy specific environment
197
- npx @tagadapay/plugin-cli deploy --env production
198
- ```
199
-
200
- ## 🔧 Configuration
201
-
202
- ### Plugin Configuration
203
-
204
- ```json
205
- {
206
- "name": "My Checkout Plugin",
207
- "version": "1.0.0",
208
- "description": "Custom checkout experience",
209
- "main": "dist/index.js",
210
- "tagadapay": {
211
- "type": "checkout",
212
- "mode": "direct",
213
- "framework": "react"
214
- }
215
- }
216
- ```
217
-
218
- ### Environment Variables
219
-
220
- ```env
221
- TAGADAPAY_API_KEY=your_api_key
222
- TAGADAPAY_ENVIRONMENT=sandbox
223
- TAGADAPAY_STORE_ID=your_store_id
224
- ```
225
-
226
- ## 🎨 Styling & Themes
227
-
228
- ### CSS Custom Properties
229
-
230
- ```css
231
- :root {
232
- --tagada-primary: #007bff;
233
- --tagada-secondary: #6c757d;
234
- --tagada-success: #28a745;
235
- --tagada-danger: #dc3545;
236
- --tagada-border-radius: 4px;
237
- --tagada-font-family: -apple-system, BlinkMacSystemFont, sans-serif;
238
- }
239
- ```
240
-
241
- ### Component Styling
242
-
243
- ```typescript
244
- import { styled } from '@tagadapay/plugin-sdk';
245
-
246
- const StyledButton = styled.button`
247
- background: var(--tagada-primary);
248
- color: white;
249
- border-radius: var(--tagada-border-radius);
250
- padding: 12px 24px;
251
- border: none;
252
- cursor: pointer;
253
-
254
- &:hover {
255
- opacity: 0.9;
256
- }
257
- `;
258
- ```
259
-
260
- ## 🔐 Security
261
-
262
- ### Best Practices
263
-
264
- - Never store sensitive payment data
265
- - Always validate user inputs
266
- - Use HTTPS in production
267
- - Implement proper error handling
268
- - Follow PCI DSS guidelines
269
-
270
- ### Token Management
271
-
272
- ```typescript
273
- // ✅ Good: Use tokenized payments
274
- const paymentToken = await tokenizePayment(cardData);
275
- await processPayment({ token: paymentToken });
276
-
277
- // ❌ Bad: Never store raw card data
278
- // const cardNumber = '4111111111111111'; // Don't do this
279
- ```
280
-
281
- ## 📱 Mobile Optimization
282
-
283
- ### Responsive Design
284
-
285
- ```css
286
- .checkout-container {
287
- max-width: 600px;
288
- margin: 0 auto;
289
- padding: 16px;
290
- }
291
-
292
- @media (max-width: 768px) {
293
- .checkout-container {
294
- padding: 8px;
295
- }
296
-
297
- .checkout-form {
298
- font-size: 16px; /* Prevent zoom on iOS */
299
- }
300
- }
301
- ```
302
-
303
- ### Touch Interactions
304
-
305
- ```typescript
306
- const handleTouchStart = (e) => {
307
- // Optimize for touch devices
308
- e.preventDefault();
309
- // Handle touch interaction
310
- };
311
- ```
312
-
313
- ## 🌐 Internationalization
314
-
315
- ### Multi-language Support
316
-
317
- ```typescript
318
- import { useTranslation } from '@tagadapay/plugin-sdk';
319
-
320
- function CheckoutForm() {
321
- const { t } = useTranslation();
322
-
323
- return (
324
- <form>
325
- <label>{t('checkout.email')}</label>
326
- <input type="email" placeholder={t('checkout.email_placeholder')} />
327
- </form>
328
- );
329
- }
330
- ```
331
-
332
- ### Currency Support
333
-
334
- ```typescript
335
- import { useCurrency } from '@tagadapay/plugin-sdk';
336
-
337
- function PriceDisplay({ amount }) {
338
- const { formatPrice, currency } = useCurrency();
339
-
340
- return <span>{formatPrice(amount, currency)}</span>;
341
- }
342
- ```
343
-
344
- ## 📊 Analytics & Monitoring
345
-
346
- ### Event Tracking
347
-
348
- ```typescript
349
- import { trackEvent } from '@tagadapay/plugin-sdk';
350
-
351
- // Track user interactions
352
- trackEvent('checkout_started', {
353
- product_id: 'prod_123',
354
- value: 2999,
355
- currency: 'USD',
356
- });
357
-
358
- // Track conversions
359
- trackEvent('purchase_completed', {
360
- transaction_id: 'txn_456',
361
- value: 2999,
362
- currency: 'USD',
363
- });
364
- ```
365
-
366
- ### Performance Monitoring
367
-
368
- ```typescript
369
- import { performance } from '@tagadapay/plugin-sdk';
370
-
371
- // Measure load times
372
- performance.mark('checkout-start');
373
- // ... checkout logic
374
- performance.mark('checkout-end');
375
- performance.measure('checkout-duration', 'checkout-start', 'checkout-end');
376
- ```
377
-
378
- ## 🤝 Contributing
379
-
380
- ### Development Setup
381
-
382
- ```bash
383
- # Clone the repository
384
- git clone https://github.com/tagadapay/plugin-sdk.git
385
-
386
- # Install dependencies
387
- npm install
388
-
389
- # Start development
390
- npm run dev
391
- ```
392
-
393
- ### Submitting Changes
394
-
395
- 1. Fork the repository
396
- 2. Create a feature branch
397
- 3. Make your changes
398
- 4. Add tests
399
- 5. Submit a pull request
400
-
401
- ## 📄 License
402
-
403
- MIT License - see [LICENSE](./LICENSE) for details.
404
-
405
- ## 🆘 Support
406
-
407
- - **Documentation**: [docs.tagadapay.com](https://docs.tagadapay.com)
408
- - **Discord**: [discord.gg/tagadapay](https://discord.gg/tagadapay)
409
- - **Email**: support@tagadapay.com
410
- - **GitHub Issues**: [github.com/tagadapay/plugin-sdk/issues](https://github.com/tagadapay/plugin-sdk/issues)
411
-
412
- ---
413
-
414
- Built with ❤️ by the TagadaPay team
1
+ # TagadaPay Plugin SDK
2
+
3
+ A comprehensive SDK for building checkout plugins on the TagadaPay platform. Create custom checkout experiences with React components, payment processing, and advanced features.
4
+
5
+ ## 📚 Documentation
6
+
7
+ ### Core APIs
8
+
9
+ - **[useCheckout](./README-useCheckout.md)** - Checkout state management and flow control
10
+ - **[setCheckoutInfo](./README-setCheckoutInfo.md)** - Customer information and validation
11
+ - **[useOffers](./README-useOffers.md)** - Dynamic pricing and promotional offers
12
+ - **[Money utilities](./README-money.md)** - Currency formatting and calculations
13
+ - **[URL utilities](./README-urlUtils.md)** - Navigation and routing helpers
14
+
15
+ ### Examples
16
+
17
+ - **[Vite Checkout Demo](../checkout-vite)** - Complete checkout implementation
18
+
19
+ ## 🚀 Quick Start
20
+
21
+ ### Installation
22
+
23
+ ```bash
24
+ npm install @tagadapay/plugin-sdk
25
+ ```
26
+
27
+ ### Basic Usage
28
+
29
+ ```typescript
30
+ import { useCheckout, setCheckoutInfo } from '@tagadapay/plugin-sdk';
31
+
32
+ function CheckoutPage() {
33
+ const { customer, cart, payment } = useCheckout();
34
+
35
+ const handleSubmit = async (data) => {
36
+ await setCheckoutInfo({
37
+ customer: data.customer,
38
+ payment: data.payment
39
+ });
40
+ };
41
+
42
+ return (
43
+ <div>
44
+ {/* Your checkout UI */}
45
+ </div>
46
+ );
47
+ }
48
+ ```
49
+
50
+ ## 🎯 Key Features
51
+
52
+ ### Payment Processing
53
+
54
+ - Secure tokenized payments
55
+ - Multiple payment method support
56
+ - Real-time validation
57
+ - PCI compliance
58
+
59
+ ### Customer Management
60
+
61
+ - Profile management
62
+ - Address validation
63
+ - Order history
64
+ - Preferences
65
+
66
+ ### Cart & Pricing
67
+
68
+ - Dynamic pricing
69
+ - Promotional offers
70
+ - Tax calculations
71
+ - Currency conversion
72
+
73
+ ### UI Components
74
+
75
+ - Pre-built checkout components
76
+ - Customizable themes
77
+ - Mobile-optimized
78
+ - Accessibility features
79
+
80
+ ## 📖 API Reference
81
+
82
+ ### Core Hooks
83
+
84
+ #### useCheckout()
85
+
86
+ Primary hook for checkout state management.
87
+
88
+ ```typescript
89
+ const {
90
+ customer, // Customer information
91
+ cart, // Shopping cart state
92
+ payment, // Payment details
93
+ shipping, // Shipping information
94
+ loading, // Loading states
95
+ errors, // Error handling
96
+ } = useCheckout();
97
+ ```
98
+
99
+ #### useOffers()
100
+
101
+ Hook for managing dynamic offers and pricing.
102
+
103
+ ```typescript
104
+ const {
105
+ offers, // Available offers
106
+ applyOffer, // Apply offer function
107
+ removeOffer, // Remove offer function
108
+ total, // Calculated total
109
+ } = useOffers();
110
+ ```
111
+
112
+ ### Utility Functions
113
+
114
+ #### setCheckoutInfo()
115
+
116
+ Update checkout information with validation.
117
+
118
+ ```typescript
119
+ await setCheckoutInfo({
120
+ customer: {
121
+ email: 'user@example.com',
122
+ firstName: 'John',
123
+ lastName: 'Doe',
124
+ },
125
+ payment: {
126
+ method: 'card',
127
+ token: 'pm_token_123',
128
+ },
129
+ });
130
+ ```
131
+
132
+ #### Money utilities
133
+
134
+ Format and calculate monetary values.
135
+
136
+ ```typescript
137
+ import { formatMoney, convertCurrency } from '@tagadapay/plugin-sdk';
138
+
139
+ const formatted = formatMoney(2999, 'USD'); // "$29.99"
140
+ const converted = convertCurrency(2999, 'USD', 'EUR'); // 2699
141
+ ```
142
+
143
+ ## 🛠️ Development
144
+
145
+ ### Local Development
146
+
147
+ ```bash
148
+ # Install dependencies
149
+ npm install
150
+
151
+ # Start development server
152
+ npm run dev
153
+
154
+ # Build for production
155
+ npm run build
156
+ ```
157
+
158
+ ### Testing
159
+
160
+ ```bash
161
+ # Run tests
162
+ npm test
163
+
164
+ # Run tests with coverage
165
+ npm run test:coverage
166
+ ```
167
+
168
+ ### Linting
169
+
170
+ ```bash
171
+ # Check code style
172
+ npm run lint
173
+
174
+ # Fix linting issues
175
+ npm run lint:fix
176
+ ```
177
+
178
+ ## 📦 Build & Deploy
179
+
180
+ ### Building Your Plugin
181
+
182
+ ```bash
183
+ # Build optimized bundle
184
+ npm run build
185
+
186
+ # Analyze bundle size
187
+ npm run analyze
188
+ ```
189
+
190
+ ### Deployment
191
+
192
+ ```bash
193
+ # Deploy using TagadaPay CLI
194
+ npx @tagadapay/plugin-cli deploy
195
+
196
+ # Deploy specific environment
197
+ npx @tagadapay/plugin-cli deploy --env production
198
+ ```
199
+
200
+ ## 🔧 Configuration
201
+
202
+ ### Plugin Configuration
203
+
204
+ ```json
205
+ {
206
+ "name": "My Checkout Plugin",
207
+ "version": "1.0.0",
208
+ "description": "Custom checkout experience",
209
+ "main": "dist/index.js",
210
+ "tagadapay": {
211
+ "type": "checkout",
212
+ "mode": "direct",
213
+ "framework": "react"
214
+ }
215
+ }
216
+ ```
217
+
218
+ ### Environment Variables
219
+
220
+ ```env
221
+ TAGADAPAY_API_KEY=your_api_key
222
+ TAGADAPAY_ENVIRONMENT=sandbox
223
+ TAGADAPAY_STORE_ID=your_store_id
224
+ ```
225
+
226
+ ## 🎨 Styling & Themes
227
+
228
+ ### CSS Custom Properties
229
+
230
+ ```css
231
+ :root {
232
+ --tagada-primary: #007bff;
233
+ --tagada-secondary: #6c757d;
234
+ --tagada-success: #28a745;
235
+ --tagada-danger: #dc3545;
236
+ --tagada-border-radius: 4px;
237
+ --tagada-font-family: -apple-system, BlinkMacSystemFont, sans-serif;
238
+ }
239
+ ```
240
+
241
+ ### Component Styling
242
+
243
+ ```typescript
244
+ import { styled } from '@tagadapay/plugin-sdk';
245
+
246
+ const StyledButton = styled.button`
247
+ background: var(--tagada-primary);
248
+ color: white;
249
+ border-radius: var(--tagada-border-radius);
250
+ padding: 12px 24px;
251
+ border: none;
252
+ cursor: pointer;
253
+
254
+ &:hover {
255
+ opacity: 0.9;
256
+ }
257
+ `;
258
+ ```
259
+
260
+ ## 🔐 Security
261
+
262
+ ### Best Practices
263
+
264
+ - Never store sensitive payment data
265
+ - Always validate user inputs
266
+ - Use HTTPS in production
267
+ - Implement proper error handling
268
+ - Follow PCI DSS guidelines
269
+
270
+ ### Token Management
271
+
272
+ ```typescript
273
+ // ✅ Good: Use tokenized payments
274
+ const paymentToken = await tokenizePayment(cardData);
275
+ await processPayment({ token: paymentToken });
276
+
277
+ // ❌ Bad: Never store raw card data
278
+ // const cardNumber = '4111111111111111'; // Don't do this
279
+ ```
280
+
281
+ ## 📱 Mobile Optimization
282
+
283
+ ### Responsive Design
284
+
285
+ ```css
286
+ .checkout-container {
287
+ max-width: 600px;
288
+ margin: 0 auto;
289
+ padding: 16px;
290
+ }
291
+
292
+ @media (max-width: 768px) {
293
+ .checkout-container {
294
+ padding: 8px;
295
+ }
296
+
297
+ .checkout-form {
298
+ font-size: 16px; /* Prevent zoom on iOS */
299
+ }
300
+ }
301
+ ```
302
+
303
+ ### Touch Interactions
304
+
305
+ ```typescript
306
+ const handleTouchStart = (e) => {
307
+ // Optimize for touch devices
308
+ e.preventDefault();
309
+ // Handle touch interaction
310
+ };
311
+ ```
312
+
313
+ ## 🌐 Internationalization
314
+
315
+ ### Multi-language Support
316
+
317
+ ```typescript
318
+ import { useTranslation } from '@tagadapay/plugin-sdk';
319
+
320
+ function CheckoutForm() {
321
+ const { t } = useTranslation();
322
+
323
+ return (
324
+ <form>
325
+ <label>{t('checkout.email')}</label>
326
+ <input type="email" placeholder={t('checkout.email_placeholder')} />
327
+ </form>
328
+ );
329
+ }
330
+ ```
331
+
332
+ ### Currency Support
333
+
334
+ ```typescript
335
+ import { useCurrency } from '@tagadapay/plugin-sdk';
336
+
337
+ function PriceDisplay({ amount }) {
338
+ const { formatPrice, currency } = useCurrency();
339
+
340
+ return <span>{formatPrice(amount, currency)}</span>;
341
+ }
342
+ ```
343
+
344
+ ## 📊 Analytics & Monitoring
345
+
346
+ ### Event Tracking
347
+
348
+ ```typescript
349
+ import { trackEvent } from '@tagadapay/plugin-sdk';
350
+
351
+ // Track user interactions
352
+ trackEvent('checkout_started', {
353
+ product_id: 'prod_123',
354
+ value: 2999,
355
+ currency: 'USD',
356
+ });
357
+
358
+ // Track conversions
359
+ trackEvent('purchase_completed', {
360
+ transaction_id: 'txn_456',
361
+ value: 2999,
362
+ currency: 'USD',
363
+ });
364
+ ```
365
+
366
+ ### Performance Monitoring
367
+
368
+ ```typescript
369
+ import { performance } from '@tagadapay/plugin-sdk';
370
+
371
+ // Measure load times
372
+ performance.mark('checkout-start');
373
+ // ... checkout logic
374
+ performance.mark('checkout-end');
375
+ performance.measure('checkout-duration', 'checkout-start', 'checkout-end');
376
+ ```
377
+
378
+ ## 🤝 Contributing
379
+
380
+ ### Development Setup
381
+
382
+ ```bash
383
+ # Clone the repository
384
+ git clone https://github.com/tagadapay/plugin-sdk.git
385
+
386
+ # Install dependencies
387
+ npm install
388
+
389
+ # Start development
390
+ npm run dev
391
+ ```
392
+
393
+ ### Submitting Changes
394
+
395
+ 1. Fork the repository
396
+ 2. Create a feature branch
397
+ 3. Make your changes
398
+ 4. Add tests
399
+ 5. Submit a pull request
400
+
401
+ ## 📄 License
402
+
403
+ MIT License - see [LICENSE](./LICENSE) for details.
404
+
405
+ ## 🆘 Support
406
+
407
+ - **Documentation**: [docs.tagadapay.com](https://docs.tagadapay.com)
408
+ - **Discord**: [discord.gg/tagadapay](https://discord.gg/tagadapay)
409
+ - **Email**: support@tagadapay.com
410
+ - **GitHub Issues**: [github.com/tagadapay/plugin-sdk/issues](https://github.com/tagadapay/plugin-sdk/issues)
411
+
412
+ ---
413
+
414
+ Built with ❤️ by the TagadaPay team
@@ -277,25 +277,25 @@ export function useAddress(options = {}) {
277
277
  // Custom styles for Google Places dropdown
278
278
  useEffect(() => {
279
279
  if (enableGooglePlaces && !document.getElementById('google-places-custom-styles')) {
280
- const autocompleteStyles = `
281
- .pac-container {
282
- border-radius: 8px;
283
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
284
- border: 1px solid #e2e8f0;
285
- margin-top: 4px;
286
- font-family: inherit;
287
- z-index: 9999;
288
- }
289
- .pac-item {
290
- padding: 10px 12px;
291
- font-size: 14px;
292
- cursor: pointer;
293
- border-top: 1px solid #f3f4f6;
294
- }
295
- .pac-item:first-child { border-top: none; }
296
- .pac-item:hover { background-color: #f8fafc; }
297
- .pac-item-selected, .pac-item-selected:hover { background-color: #eef2ff; }
298
- .pac-matched { font-weight: 600; }
280
+ const autocompleteStyles = `
281
+ .pac-container {
282
+ border-radius: 8px;
283
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
284
+ border: 1px solid #e2e8f0;
285
+ margin-top: 4px;
286
+ font-family: inherit;
287
+ z-index: 9999;
288
+ }
289
+ .pac-item {
290
+ padding: 10px 12px;
291
+ font-size: 14px;
292
+ cursor: pointer;
293
+ border-top: 1px solid #f3f4f6;
294
+ }
295
+ .pac-item:first-child { border-top: none; }
296
+ .pac-item:hover { background-color: #f8fafc; }
297
+ .pac-item-selected, .pac-item-selected:hover { background-color: #eef2ff; }
298
+ .pac-matched { font-weight: 600; }
299
299
  `;
300
300
  const styleElement = document.createElement('style');
301
301
  styleElement.id = 'google-places-custom-styles';
@@ -135,6 +135,59 @@ export interface CheckoutSession {
135
135
  adjustments: any;
136
136
  }[];
137
137
  }
138
+ export interface CheckoutSessionPreviewAdjustment {
139
+ type: 'Promotion' | 'Tax' | 'Shipping';
140
+ description: string;
141
+ level: 'Order' | 'LineItem';
142
+ sourceId: string;
143
+ amount: number;
144
+ currency: string;
145
+ }
146
+ export interface CheckoutSessionPreviewItem {
147
+ id: string;
148
+ productId: string;
149
+ product: {
150
+ name: string;
151
+ description: string;
152
+ };
153
+ variantId: string;
154
+ variant: {
155
+ name: string;
156
+ description: string;
157
+ imageUrl: string;
158
+ grams: number;
159
+ };
160
+ priceId: string;
161
+ sku: string;
162
+ unitAmount: number;
163
+ quantity: number;
164
+ amount: number;
165
+ adjustedAmount: number;
166
+ currency: string;
167
+ adjustments: CheckoutSessionPreviewAdjustment[];
168
+ recurring?: boolean;
169
+ rebillMode?: 'auth' | 'capture';
170
+ rebillStepIntervalMs?: number;
171
+ interval?: 'day' | 'week' | 'month' | 'year';
172
+ intervalCount?: number;
173
+ totalBillingCycles?: number;
174
+ unitAmountAfterFirstCycle?: number;
175
+ subscriptionSettings?: any;
176
+ orderLineItemProduct: {
177
+ name: string | null;
178
+ } | null;
179
+ orderLineItemVariant: {
180
+ name: string | null;
181
+ imageUrl: string | null;
182
+ } | null;
183
+ }
184
+ export interface CheckoutSessionPreview {
185
+ items: CheckoutSessionPreviewItem[];
186
+ adjustments: CheckoutSessionPreviewAdjustment[];
187
+ totalAmount: number;
188
+ totalAdjustedAmount: number;
189
+ totalPromotionAmount: number;
190
+ }
138
191
  export interface CheckoutSummary {
139
192
  currency: string;
140
193
  totalAmount: number;
@@ -279,6 +332,10 @@ export interface UseCheckoutResult {
279
332
  currency: string;
280
333
  error?: any;
281
334
  }>;
335
+ previewCheckoutSession: (lineItems: CheckoutLineItem[], promotionIds?: string[]) => Promise<{
336
+ success: boolean;
337
+ preview: CheckoutSessionPreview;
338
+ }>;
282
339
  clear: () => void;
283
340
  }
284
341
  export declare function useCheckout(options?: UseCheckoutOptions): UseCheckoutResult;
@@ -3,7 +3,7 @@ import { useTagadaContext } from '../providers/TagadaProvider';
3
3
  import { getCheckoutToken } from '../utils/urlUtils';
4
4
  import { useCurrency } from '../hooks/useCurrency';
5
5
  export function useCheckout(options = {}) {
6
- const { apiService, updateCheckoutDebugData, refreshCoordinator } = useTagadaContext();
6
+ const { apiService, updateCheckoutDebugData, refreshCoordinator, store, currency } = useTagadaContext();
7
7
  const { code: currentCurrency } = useCurrency();
8
8
  const [checkout, setCheckout] = useState(null);
9
9
  const [isLoading, setIsLoading] = useState(false);
@@ -409,6 +409,24 @@ export function useCheckout(options = {}) {
409
409
  };
410
410
  }
411
411
  }, [apiService, checkout?.checkoutSession.id, checkout?.summary?.currency]);
412
+ const previewCheckoutSession = useCallback(async (lineItems, promotionIds) => {
413
+ try {
414
+ const response = await apiService.fetch('/api/v1/checkout-sessions/preview', {
415
+ method: 'POST',
416
+ body: {
417
+ lineItems,
418
+ storeId: store?.id,
419
+ currency: currency.code,
420
+ promotionIds: promotionIds || [],
421
+ },
422
+ });
423
+ return response;
424
+ }
425
+ catch (err) {
426
+ const error = err instanceof Error ? err : new Error('Failed to preview checkout session');
427
+ throw error;
428
+ }
429
+ }, [apiService, checkout?.checkoutSession.storeId, checkout?.summary?.currency]);
412
430
  const clear = useCallback(() => {
413
431
  setCheckout(null);
414
432
  setError(null);
@@ -465,6 +483,7 @@ export function useCheckout(options = {}) {
465
483
  updateCustomer,
466
484
  updateCustomerAndSessionInfo,
467
485
  previewOrderSummary,
486
+ previewCheckoutSession,
468
487
  clear,
469
488
  };
470
489
  }
@@ -95,5 +95,15 @@ export interface UseOffersResult {
95
95
  * Get total savings across all offers
96
96
  */
97
97
  getTotalSavings: () => number;
98
+ /**
99
+ * Pay for an offer with a checkout session
100
+ */
101
+ payWithCheckoutSession: (checkoutSessionId: string, orderId?: string) => Promise<void>;
102
+ /**
103
+ * Initialize a checkout session
104
+ */
105
+ initCheckoutSession: (offerId: string, orderId: string) => Promise<{
106
+ checkoutSessionId: string;
107
+ }>;
98
108
  }
99
109
  export declare function useOffers(options: UseOffersOptions): UseOffersResult;
@@ -12,17 +12,16 @@ export function useOffers(options) {
12
12
  setIsLoading(true);
13
13
  setError(null);
14
14
  try {
15
- const response = await fetch(`${environment.apiConfig.baseUrl}/api/v1/stores/${apiService.getStoredStoreId()}/offers`, {
15
+ const responseData = await apiService.fetch(`/api/v1/stores/${apiService.getStoredStoreId()}/offers`, {
16
16
  method: 'GET',
17
17
  headers: {
18
18
  'Content-Type': 'application/json',
19
19
  },
20
20
  });
21
- if (!response.ok) {
22
- throw new Error(`Failed to fetch offers: ${response.statusText}`);
23
- }
24
- const fetchedOffers = await response.json();
25
- setOffers(fetchedOffers);
21
+ const allOffers = responseData.offers || [];
22
+ // Filter offers by the provided offerIds if any are specified
23
+ const filteredOffers = offerIds.length > 0 ? allOffers.filter((offer) => offerIds.includes(offer.id)) : allOffers;
24
+ setOffers(filteredOffers);
26
25
  }
27
26
  catch (err) {
28
27
  const error = err instanceof Error ? err : new Error('Failed to fetch offers');
@@ -32,9 +31,21 @@ export function useOffers(options) {
32
31
  finally {
33
32
  setIsLoading(false);
34
33
  }
35
- }, [environment.apiConfig.baseUrl, offerIds, enabled]);
34
+ }, [apiService, environment.apiConfig.baseUrl, offerIds, enabled]);
35
+ const initCheckoutSession = useCallback(async (offerId, orderId) => {
36
+ const response = await apiService.fetch(`/api/v1/checkout/offer/init`, {
37
+ method: 'POST',
38
+ body: JSON.stringify({
39
+ offerId: offerId,
40
+ returnUrl: window.location.href,
41
+ customerId: '',
42
+ orderId,
43
+ }),
44
+ });
45
+ return response;
46
+ }, [apiService]);
36
47
  const createCheckoutSession = useCallback(async (offerId, sessionOptions) => {
37
- const response = await fetch(`${environment.apiConfig.baseUrl}/api/v1/offers/${offerId}/checkout`, {
48
+ const response = await apiService.fetch(`${environment.apiConfig.baseUrl}/api/v1/offers/${offerId}/checkout`, {
38
49
  method: 'POST',
39
50
  headers: {
40
51
  'Content-Type': 'application/json',
@@ -43,13 +54,29 @@ export function useOffers(options) {
43
54
  returnUrl: sessionOptions?.returnUrl || returnUrl || window.location.origin,
44
55
  }),
45
56
  });
46
- if (!response.ok) {
47
- throw new Error(`Failed to create checkout session: ${response.statusText}`);
48
- }
49
57
  return response.json();
50
58
  }, [apiService, environment.apiConfig.baseUrl, returnUrl]);
51
- const payOffer = useCallback(async (offerId) => {
52
- const response = await fetch(`${environment.apiConfig.baseUrl}/api/v1/offers/${offerId}/pay`, {
59
+ const payWithCheckoutSession = useCallback(async (checkoutSessionId, orderId) => {
60
+ const response = await apiService.fetch(`/api/v1/checkout-sessions/${checkoutSessionId}/pay`, {
61
+ method: 'POST',
62
+ body: JSON.stringify({
63
+ checkoutSessionId,
64
+ metadata: {
65
+ comingFromPostPurchase: true,
66
+ postOrder: orderId,
67
+ },
68
+ }),
69
+ });
70
+ }, [apiService]);
71
+ const payOffer = useCallback(async (offerId, orderId) => {
72
+ const response = await apiService.fetch(`/api/v1/offers/${offerId}/pay`, {
73
+ body: {
74
+ offerId,
75
+ metadata: orderId && {
76
+ comingFromPostPurchase: true,
77
+ postOrder: orderId,
78
+ },
79
+ },
53
80
  method: 'POST',
54
81
  headers: {
55
82
  'Content-Type': 'application/json',
@@ -104,5 +131,7 @@ export function useOffers(options) {
104
131
  getOffer,
105
132
  getTotalValue,
106
133
  getTotalSavings,
134
+ payWithCheckoutSession,
135
+ initCheckoutSession,
107
136
  };
108
137
  }
@@ -22,11 +22,11 @@ const InitializationLoader = () => (_jsx("div", { style: {
22
22
  backgroundSize: '200% 100%',
23
23
  animation: 'tagada-loading 1.5s ease-in-out infinite',
24
24
  zIndex: 9999,
25
- }, children: _jsx("style", { children: `
26
- @keyframes tagada-loading {
27
- 0% { background-position: 200% 0; }
28
- 100% { background-position: -200% 0; }
29
- }
25
+ }, children: _jsx("style", { children: `
26
+ @keyframes tagada-loading {
27
+ 0% { background-position: 200% 0; }
28
+ 100% { background-position: -200% 0; }
29
+ }
30
30
  ` }) }));
31
31
  const TagadaContext = createContext(null);
32
32
  export function TagadaProvider({ children, environment, customApiConfig, debugMode, // Remove default, will be set based on environment
package/package.json CHANGED
@@ -1,66 +1,66 @@
1
- {
2
- "name": "@tagadapay/plugin-sdk",
3
- "version": "1.0.22",
4
- "description": "Modern React SDK for building Tagada Pay plugins",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "scripts": {
8
- "build": "tsc",
9
- "clean": "rm -rf dist",
10
- "lint": "echo \"No linting configured\"",
11
- "test": "echo \"No tests yet\" && exit 0",
12
- "dev": "tsc --watch",
13
- "prepublishOnly": "npm run clean && npm run build",
14
- "publish:patch": "npm version patch && npm publish",
15
- "publish:minor": "npm version minor && npm publish",
16
- "publish:major": "npm version major && npm publish",
17
- "publish:beta": "npm version prerelease --preid=beta && npm publish --tag beta",
18
- "publish:alpha": "npm version prerelease --preid=alpha && npm publish --tag alpha",
19
- "version:patch": "npm version patch",
20
- "version:minor": "npm version minor",
21
- "version:major": "npm version major",
22
- "version:beta": "npm version prerelease --preid=beta",
23
- "version:alpha": "npm version prerelease --preid=alpha"
24
- },
25
- "keywords": [
26
- "tagadapay",
27
- "cms",
28
- "plugin",
29
- "sdk",
30
- "react",
31
- "typescript"
32
- ],
33
- "author": "Tagada Pay",
34
- "license": "MIT",
35
- "dependencies": {
36
- "@basis-theory/apple-pay-js": "^2.0.2",
37
- "@basis-theory/basis-theory-js": "^4.30.0",
38
- "@basis-theory/basis-theory-react": "^1.32.5",
39
- "@basis-theory/web-threeds": "^1.0.1",
40
- "axios": "^1.6.0",
41
- "react-google-autocomplete": "^2.7.3",
42
- "react-intl": "^7.1.11"
43
- },
44
- "devDependencies": {
45
- "@types/node": "^18.0.0",
46
- "@types/react": "^19",
47
- "@types/react-dom": "^19",
48
- "typescript": "^5.0.0"
49
- },
50
- "peerDependencies": {
51
- "react": "^18.0.0 || ^19.0.0",
52
- "react-dom": "^18.0.0 || ^19.0.0"
53
- },
54
- "files": [
55
- "dist/**/*",
56
- "README.md"
57
- ],
58
- "repository": {
59
- "type": "git",
60
- "url": "git+https://github.com/tagadapay/plugin-sdk.git"
61
- },
62
- "bugs": {
63
- "url": "https://github.com/tagadapay/plugin-sdk/issues"
64
- },
65
- "homepage": "https://github.com/tagadapay/plugin-sdk#readme"
66
- }
1
+ {
2
+ "name": "@tagadapay/plugin-sdk",
3
+ "version": "1.0.25",
4
+ "description": "Modern React SDK for building Tagada Pay plugins",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "clean": "rm -rf dist",
10
+ "lint": "echo \"No linting configured\"",
11
+ "test": "echo \"No tests yet\" && exit 0",
12
+ "dev": "tsc --watch",
13
+ "prepublishOnly": "npm run clean && npm run build",
14
+ "publish:patch": "npm version patch && npm publish",
15
+ "publish:minor": "npm version minor && npm publish",
16
+ "publish:major": "npm version major && npm publish",
17
+ "publish:beta": "npm version prerelease --preid=beta && npm publish --tag beta",
18
+ "publish:alpha": "npm version prerelease --preid=alpha && npm publish --tag alpha",
19
+ "version:patch": "npm version patch",
20
+ "version:minor": "npm version minor",
21
+ "version:major": "npm version major",
22
+ "version:beta": "npm version prerelease --preid=beta",
23
+ "version:alpha": "npm version prerelease --preid=alpha"
24
+ },
25
+ "keywords": [
26
+ "tagadapay",
27
+ "cms",
28
+ "plugin",
29
+ "sdk",
30
+ "react",
31
+ "typescript"
32
+ ],
33
+ "author": "Tagada Pay",
34
+ "license": "MIT",
35
+ "dependencies": {
36
+ "@basis-theory/apple-pay-js": "^2.0.2",
37
+ "@basis-theory/basis-theory-js": "^4.30.0",
38
+ "@basis-theory/basis-theory-react": "^1.32.5",
39
+ "@basis-theory/web-threeds": "^1.0.1",
40
+ "axios": "^1.6.0",
41
+ "react-google-autocomplete": "^2.7.3",
42
+ "react-intl": "^7.1.11"
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "^18.0.0",
46
+ "@types/react": "^19",
47
+ "@types/react-dom": "^19",
48
+ "typescript": "^5.0.0"
49
+ },
50
+ "peerDependencies": {
51
+ "react": "^18.0.0 || ^19.0.0",
52
+ "react-dom": "^18.0.0 || ^19.0.0"
53
+ },
54
+ "files": [
55
+ "dist/**/*",
56
+ "README.md"
57
+ ],
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "git+https://github.com/tagadapay/plugin-sdk.git"
61
+ },
62
+ "bugs": {
63
+ "url": "https://github.com/tagadapay/plugin-sdk/issues"
64
+ },
65
+ "homepage": "https://github.com/tagadapay/plugin-sdk#readme"
66
+ }