@tagadapay/plugin-sdk 1.0.2

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 (63) hide show
  1. package/README.md +475 -0
  2. package/dist/data/currencies.json +2410 -0
  3. package/dist/index.d.ts +33 -0
  4. package/dist/index.js +37 -0
  5. package/dist/react/components/DebugDrawer.d.ts +7 -0
  6. package/dist/react/components/DebugDrawer.js +368 -0
  7. package/dist/react/components/OffersDemo.d.ts +1 -0
  8. package/dist/react/components/OffersDemo.js +50 -0
  9. package/dist/react/components/index.d.ts +1 -0
  10. package/dist/react/components/index.js +1 -0
  11. package/dist/react/config/environment.d.ts +22 -0
  12. package/dist/react/config/environment.js +132 -0
  13. package/dist/react/config/payment.d.ts +23 -0
  14. package/dist/react/config/payment.js +52 -0
  15. package/dist/react/hooks/useAuth.d.ts +4 -0
  16. package/dist/react/hooks/useAuth.js +12 -0
  17. package/dist/react/hooks/useCheckout.d.ts +262 -0
  18. package/dist/react/hooks/useCheckout.js +325 -0
  19. package/dist/react/hooks/useCurrency.d.ts +4 -0
  20. package/dist/react/hooks/useCurrency.js +640 -0
  21. package/dist/react/hooks/useCustomer.d.ts +7 -0
  22. package/dist/react/hooks/useCustomer.js +14 -0
  23. package/dist/react/hooks/useEnvironment.d.ts +7 -0
  24. package/dist/react/hooks/useEnvironment.js +18 -0
  25. package/dist/react/hooks/useLocale.d.ts +2 -0
  26. package/dist/react/hooks/useLocale.js +43 -0
  27. package/dist/react/hooks/useOffers.d.ts +99 -0
  28. package/dist/react/hooks/useOffers.js +115 -0
  29. package/dist/react/hooks/useOrder.d.ts +44 -0
  30. package/dist/react/hooks/useOrder.js +77 -0
  31. package/dist/react/hooks/usePayment.d.ts +60 -0
  32. package/dist/react/hooks/usePayment.js +343 -0
  33. package/dist/react/hooks/usePaymentPolling.d.ts +45 -0
  34. package/dist/react/hooks/usePaymentPolling.js +146 -0
  35. package/dist/react/hooks/useProducts.d.ts +95 -0
  36. package/dist/react/hooks/useProducts.js +120 -0
  37. package/dist/react/hooks/useSession.d.ts +10 -0
  38. package/dist/react/hooks/useSession.js +17 -0
  39. package/dist/react/hooks/useThreeds.d.ts +38 -0
  40. package/dist/react/hooks/useThreeds.js +162 -0
  41. package/dist/react/hooks/useThreedsModal.d.ts +16 -0
  42. package/dist/react/hooks/useThreedsModal.js +328 -0
  43. package/dist/react/index.d.ts +26 -0
  44. package/dist/react/index.js +27 -0
  45. package/dist/react/providers/TagadaProvider.d.ts +55 -0
  46. package/dist/react/providers/TagadaProvider.js +471 -0
  47. package/dist/react/services/apiService.d.ts +149 -0
  48. package/dist/react/services/apiService.js +168 -0
  49. package/dist/react/types.d.ts +151 -0
  50. package/dist/react/types.js +4 -0
  51. package/dist/react/utils/__tests__/urlUtils.test.d.ts +1 -0
  52. package/dist/react/utils/__tests__/urlUtils.test.js +189 -0
  53. package/dist/react/utils/deviceInfo.d.ts +39 -0
  54. package/dist/react/utils/deviceInfo.js +163 -0
  55. package/dist/react/utils/jwtDecoder.d.ts +14 -0
  56. package/dist/react/utils/jwtDecoder.js +86 -0
  57. package/dist/react/utils/money.d.ts +2273 -0
  58. package/dist/react/utils/money.js +104 -0
  59. package/dist/react/utils/tokenStorage.d.ts +16 -0
  60. package/dist/react/utils/tokenStorage.js +52 -0
  61. package/dist/react/utils/urlUtils.d.ts +239 -0
  62. package/dist/react/utils/urlUtils.js +449 -0
  63. package/package.json +64 -0
package/README.md ADDED
@@ -0,0 +1,475 @@
1
+ # TagadaPay Plugin SDK
2
+
3
+ A modern, type-safe React SDK for building checkout plugins and integrations with the TagadaPay platform.
4
+
5
+ ## Features
6
+
7
+ - 🚀 **Modern React Hooks** - Built with React 18+ hooks for optimal performance
8
+ - 🔧 **TypeScript Support** - Full type safety with comprehensive TypeScript definitions
9
+ - 🎯 **Checkout Management** - Complete checkout session lifecycle management
10
+ - 💳 **Payment Processing** - Integrated payment processing with 3DS support
11
+ - 📦 **Product Management** - Fetch and manage products, variants, and pricing
12
+ - 🛒 **Order Management** - Comprehensive order data fetching and management
13
+ - 🎁 **Offers & Promotions** - Handle special offers and promotional codes
14
+ - 🌍 **Multi-Environment** - Support for development, staging, and production
15
+ - 📱 **Responsive Design** - Mobile-first design patterns
16
+
17
+ ## Quick Start
18
+
19
+ ### Installation
20
+
21
+ ```bash
22
+ npm install @tagadapay/plugin-sdk
23
+ # or
24
+ pnpm add @tagadapay/plugin-sdk
25
+ # or
26
+ yarn add @tagadapay/plugin-sdk
27
+ ```
28
+
29
+ ### Basic Setup
30
+
31
+ ```tsx
32
+ import React from 'react';
33
+ import { TagadaProvider, useCheckout, useCustomer } from '@tagadapay/plugin-sdk';
34
+
35
+ function App() {
36
+ return (
37
+ <TagadaProvider storeId="your-store-id" accountId="your-account-id" environment="development">
38
+ <MyCheckoutPlugin />
39
+ </TagadaProvider>
40
+ );
41
+ }
42
+
43
+ function MyCheckoutPlugin() {
44
+ const { customer, isAuthenticated } = useCustomer();
45
+ const { checkout, init, updateLineItems } = useCheckout();
46
+
47
+ return (
48
+ <div>
49
+ {isAuthenticated ? <p>Welcome back, {customer?.firstName}!</p> : <p>Welcome, guest!</p>}
50
+
51
+ {checkout ? (
52
+ <CheckoutForm checkout={checkout} />
53
+ ) : (
54
+ <button
55
+ onClick={() =>
56
+ init({
57
+ lineItems: [{ variantId: 'variant-id', quantity: 1 }],
58
+ })
59
+ }
60
+ >
61
+ Start Checkout
62
+ </button>
63
+ )}
64
+ </div>
65
+ );
66
+ }
67
+ ```
68
+
69
+ ## Core Hooks
70
+
71
+ ### `useCheckout`
72
+
73
+ Manage checkout sessions, line items, and customer information.
74
+
75
+ ```tsx
76
+ import { useCheckout } from '@tagadapay/plugin-sdk';
77
+
78
+ function CheckoutComponent() {
79
+ const {
80
+ checkout,
81
+ isLoading,
82
+ error,
83
+ init,
84
+ updateLineItems,
85
+ updateCustomerAndSessionInfo,
86
+ applyPromotionCode,
87
+ } = useCheckout({
88
+ checkoutToken: 'optional-existing-token',
89
+ autoRefresh: true,
90
+ });
91
+
92
+ // Initialize new checkout
93
+ const startCheckout = async () => {
94
+ await init({
95
+ storeId: 'store-id',
96
+ lineItems: [
97
+ { variantId: 'variant-1', quantity: 2 },
98
+ { variantId: 'variant-2', quantity: 1 },
99
+ ],
100
+ customer: {
101
+ email: 'customer@example.com',
102
+ currency: 'USD',
103
+ },
104
+ });
105
+ };
106
+
107
+ // Update items in cart
108
+ const updateCart = async () => {
109
+ await updateLineItems([{ variantId: 'variant-1', quantity: 3 }]);
110
+ };
111
+
112
+ // Apply discount code
113
+ const applyDiscount = async () => {
114
+ await applyPromotionCode('SAVE20');
115
+ };
116
+
117
+ return (
118
+ <div>
119
+ {checkout && (
120
+ <div>
121
+ <h2>Total: {formatMoney(checkout.summary.totalAdjustedAmount, checkout.summary.currency)}</h2>
122
+ {checkout.summary.items.map((item) => (
123
+ <div key={item.id}>
124
+ {item.name} - Qty: {item.quantity} - {formatMoney(item.adjustedAmount, item.currency)}
125
+ </div>
126
+ ))}
127
+ </div>
128
+ )}
129
+ </div>
130
+ );
131
+ }
132
+ ```
133
+
134
+ ### `useOrder`
135
+
136
+ Fetch and display order information for thankyou pages and order management.
137
+
138
+ ```tsx
139
+ import { useOrder, formatMoney } from '@tagadapay/plugin-sdk';
140
+
141
+ function ThankYouPage({ orderId }: { orderId: string }) {
142
+ const { order, isLoading, error, refetch } = useOrder({
143
+ orderId,
144
+ autoFetch: true,
145
+ });
146
+
147
+ if (isLoading) return <div>Loading order...</div>;
148
+ if (error) return <div>Error: {error.message}</div>;
149
+ if (!order) return <div>Order not found</div>;
150
+
151
+ return (
152
+ <div>
153
+ <h1>Order Confirmed!</h1>
154
+ <p>Order #{order.id}</p>
155
+ <p>Status: {order.status}</p>
156
+ <p>Total: {formatMoney(order.paidAmount, order.currency)}</p>
157
+
158
+ <h3>Items:</h3>
159
+ {order.items.map((item) => (
160
+ <div key={item.id}>
161
+ <h4>{item.orderLineItemProduct?.name}</h4>
162
+ <p>Quantity: {item.quantity}</p>
163
+ <p>Price: {formatMoney(item.adjustedAmount, item.currency)}</p>
164
+ </div>
165
+ ))}
166
+
167
+ {order.shippingAddress && (
168
+ <div>
169
+ <h3>Shipping Address:</h3>
170
+ <p>
171
+ {order.shippingAddress.firstName} {order.shippingAddress.lastName}
172
+ </p>
173
+ <p>{order.shippingAddress.address1}</p>
174
+ <p>
175
+ {order.shippingAddress.city}, {order.shippingAddress.state} {order.shippingAddress.postal}
176
+ </p>
177
+ </div>
178
+ )}
179
+ </div>
180
+ );
181
+ }
182
+ ```
183
+
184
+ ### `usePayment`
185
+
186
+ Process payments with support for credit cards, Apple Pay, and 3D Secure.
187
+
188
+ ```tsx
189
+ import { usePayment, useCheckout } from '@tagadapay/plugin-sdk';
190
+
191
+ function PaymentForm() {
192
+ const { checkout } = useCheckout();
193
+ const { processCardPayment, isLoading, error } = usePayment();
194
+
195
+ const handlePayment = async (formData: any) => {
196
+ if (!checkout?.checkoutSession?.id) return;
197
+
198
+ try {
199
+ const result = await processCardPayment(
200
+ checkout.checkoutSession.id,
201
+ {
202
+ cardNumber: formData.cardNumber,
203
+ expiryDate: formData.expiryDate,
204
+ cvc: formData.cvc,
205
+ cardholderName: formData.cardholderName,
206
+ },
207
+ {
208
+ enableThreeds: true,
209
+ onSuccess: (payment) => {
210
+ // Redirect to thank you page
211
+ window.location.href = `/thankyou/${payment.orderId}`;
212
+ },
213
+ onFailure: (error) => {
214
+ console.error('Payment failed:', error);
215
+ },
216
+ },
217
+ );
218
+ } catch (err) {
219
+ console.error('Payment error:', err);
220
+ }
221
+ };
222
+
223
+ return (
224
+ <form onSubmit={handlePayment}>
225
+ {/* Payment form fields */}
226
+ <button type="submit" disabled={isLoading}>
227
+ {isLoading ? 'Processing...' : 'Pay Now'}
228
+ </button>
229
+ {error && <div className="error">{error}</div>}
230
+ </form>
231
+ );
232
+ }
233
+ ```
234
+
235
+ ### `useProducts`
236
+
237
+ Fetch product information, variants, and pricing.
238
+
239
+ ```tsx
240
+ import { useProducts } from '@tagadapay/plugin-sdk';
241
+
242
+ function ProductSelector() {
243
+ const { products, isLoading, getVariant, filterVariants } = useProducts({
244
+ includeVariants: true,
245
+ includePrices: true,
246
+ });
247
+
248
+ const featuredVariants = filterVariants((variant, product) => product.metadata?.featured === true);
249
+
250
+ return (
251
+ <div>
252
+ {products.map((product) => (
253
+ <div key={product.id}>
254
+ <h3>{product.name}</h3>
255
+ <p>{product.description}</p>
256
+ {product.variants?.map((variant) => (
257
+ <div key={variant.id}>
258
+ <span>{variant.name}</span>
259
+ <span>{formatMoney(variant.price?.amount || 0, variant.price?.currency || 'USD')}</span>
260
+ </div>
261
+ ))}
262
+ </div>
263
+ ))}
264
+ </div>
265
+ );
266
+ }
267
+ ```
268
+
269
+ ### `useOffers`
270
+
271
+ Handle special offers and promotional content.
272
+
273
+ ```tsx
274
+ import { useOffers } from '@tagadapay/plugin-sdk';
275
+
276
+ function OffersDisplay() {
277
+ const { offers, isLoading, createCheckoutSession, getTotalSavings } = useOffers({
278
+ offerIds: ['offer-1', 'offer-2'],
279
+ returnUrl: window.location.origin + '/thankyou',
280
+ });
281
+
282
+ const handleOfferClick = async (offerId: string) => {
283
+ const { checkoutUrl } = await createCheckoutSession(offerId);
284
+ window.location.href = checkoutUrl;
285
+ };
286
+
287
+ return (
288
+ <div>
289
+ <p>Total Savings: {formatMoney(getTotalSavings(), 'USD')}</p>
290
+ {offers.map((offer) => (
291
+ <div key={offer.id}>
292
+ <h3>{offer.title}</h3>
293
+ <p>{offer.description}</p>
294
+ <button onClick={() => handleOfferClick(offer.id)}>Claim Offer</button>
295
+ </div>
296
+ ))}
297
+ </div>
298
+ );
299
+ }
300
+ ```
301
+
302
+ ## Utility Functions
303
+
304
+ ### `formatMoney`
305
+
306
+ Format monetary amounts with proper currency symbols.
307
+
308
+ ```tsx
309
+ import { formatMoney } from '@tagadapay/plugin-sdk';
310
+
311
+ // Format different currencies
312
+ formatMoney(2999, 'USD'); // "$29.99"
313
+ formatMoney(2999, 'EUR'); // "€29.99"
314
+ formatMoney(2999, 'GBP'); // "£29.99"
315
+
316
+ // With custom options
317
+ formatMoney(2999, 'USD', {
318
+ showDecimals: false,
319
+ }); // "$30"
320
+ ```
321
+
322
+ ## Environment Configuration
323
+
324
+ ```tsx
325
+ <TagadaProvider
326
+ storeId="your-store-id"
327
+ accountId="your-account-id"
328
+ environment="development" // 'development' | 'production' | 'local'
329
+ customApiConfig={{
330
+ baseUrl: 'https://custom-api.example.com',
331
+ }}
332
+ debugMode={true}
333
+ >
334
+ <App />
335
+ </TagadaProvider>
336
+ ```
337
+
338
+ ## TypeScript Support
339
+
340
+ The SDK is fully typed with comprehensive TypeScript definitions:
341
+
342
+ ```tsx
343
+ import type {
344
+ Order,
345
+ OrderItem,
346
+ CheckoutSession,
347
+ Customer,
348
+ UseCheckoutResult,
349
+ UseOrderResult,
350
+ } from '@tagadapay/plugin-sdk';
351
+
352
+ interface MyComponentProps {
353
+ order: Order;
354
+ onOrderUpdate: (order: Order) => void;
355
+ }
356
+
357
+ function MyComponent({ order, onOrderUpdate }: MyComponentProps) {
358
+ // Fully typed props and hooks
359
+ }
360
+ ```
361
+
362
+ ## Error Handling
363
+
364
+ All hooks provide comprehensive error handling:
365
+
366
+ ```tsx
367
+ function MyComponent() {
368
+ const { order, error, isLoading } = useOrder({ orderId: 'order-123' });
369
+
370
+ if (isLoading) return <LoadingSpinner />;
371
+
372
+ if (error) {
373
+ return (
374
+ <ErrorDisplay
375
+ title="Failed to load order"
376
+ message={error.message}
377
+ onRetry={() => window.location.reload()}
378
+ />
379
+ );
380
+ }
381
+
382
+ return <OrderDisplay order={order} />;
383
+ }
384
+ ```
385
+
386
+ ## Advanced Usage
387
+
388
+ ### Custom API Configuration
389
+
390
+ ```tsx
391
+ const customConfig = {
392
+ baseUrl: 'https://api.your-domain.com',
393
+ endpoints: {
394
+ checkout: {
395
+ sessionInit: '/v2/checkout/init',
396
+ sessionStatus: '/v2/checkout/status',
397
+ },
398
+ },
399
+ };
400
+
401
+ <TagadaProvider customApiConfig={customConfig}>
402
+ <App />
403
+ </TagadaProvider>;
404
+ ```
405
+
406
+ ### Plugin Development
407
+
408
+ For building complete checkout plugins:
409
+
410
+ ```tsx
411
+ // Plugin entry point
412
+ export function MyCheckoutPlugin() {
413
+ return (
414
+ <TagadaProvider storeId={STORE_ID}>
415
+ <Router>
416
+ <Routes>
417
+ <Route path="/checkout" element={<CheckoutPage />} />
418
+ <Route path="/thankyou/:orderId" element={<ThankYouPage />} />
419
+ </Routes>
420
+ </Router>
421
+ </TagadaProvider>
422
+ );
423
+ }
424
+ ```
425
+
426
+ ## Examples
427
+
428
+ - **[JointBoost Vite Demo](../jointboost-vite)** - Complete checkout implementation
429
+ - **[Checkout Integration](./README-useCheckout.md)** - Detailed checkout examples
430
+ - **[Payment Processing](./README-useOffers.md)** - Payment integration examples
431
+ - **[Money Formatting](./README-money.md)** - Currency formatting utilities
432
+
433
+ ## API Reference
434
+
435
+ ### Hooks
436
+
437
+ - [`useCheckout`](./README-useCheckout.md) - Checkout session management
438
+ - [`useOrder`](#useorder) - Order data fetching
439
+ - [`usePayment`](./README-useOffers.md) - Payment processing
440
+ - [`useProducts`](#useproducts) - Product management
441
+ - [`useOffers`](./README-useOffers.md) - Offers and promotions
442
+ - [`useCustomer`](#usecustomer) - Customer information
443
+ - [`useSession`](#usesession) - Session management
444
+
445
+ ### Utilities
446
+
447
+ - [`formatMoney`](./README-money.md) - Currency formatting
448
+ - [`setCheckoutInfo`](./README-setCheckoutInfo.md) - Checkout information helpers
449
+ - [`urlUtils`](./README-urlUtils.md) - URL manipulation utilities
450
+
451
+ ## Browser Support
452
+
453
+ - Chrome 90+
454
+ - Firefox 88+
455
+ - Safari 14+
456
+ - Edge 90+
457
+
458
+ ## Contributing
459
+
460
+ 1. Fork the repository
461
+ 2. Create a feature branch
462
+ 3. Make your changes
463
+ 4. Add tests
464
+ 5. Submit a pull request
465
+
466
+ ## License
467
+
468
+ MIT License - see [LICENSE](./LICENSE) for details.
469
+
470
+ ## Support
471
+
472
+ - 📖 [Documentation](./README.md)
473
+ - 🐛 [Issues](https://github.com/tagadapay/plugin-sdk/issues)
474
+ - 💬 [Discussions](https://github.com/tagadapay/plugin-sdk/discussions)
475
+ - 📧 [Support Email](mailto:support@tagadapay.com)