@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
@@ -0,0 +1,165 @@
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Express Payment Methods Context Provider using v2 Architecture
4
+ * Manages express payment methods (Apple Pay, Google Pay, PayPal, Klarna)
5
+ */
6
+ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
7
+ import { createContext, useCallback, useMemo, useState } from 'react';
8
+ import { ExpressPaymentMethodsResource, } from '../../core/resources/expressPaymentMethods';
9
+ import { getGlobalApiClient } from '../hooks/useApiQuery';
10
+ import { useShippingRatesQuery } from '../hooks/useShippingRatesQuery';
11
+ export const ExpressPaymentMethodsContext = createContext(undefined);
12
+ export const ExpressPaymentMethodsProvider = ({ children, customerId, checkout, }) => {
13
+ const queryClient = useQueryClient();
14
+ const [availableExpressPaymentMethodIds, setAvailableExpressPaymentMethodIds] = useState([]);
15
+ const [error, setError] = useState(null);
16
+ const checkoutSessionId = checkout?.checkoutSession?.id;
17
+ // Create express payment methods resource client
18
+ const expressPaymentResource = useMemo(() => {
19
+ try {
20
+ return new ExpressPaymentMethodsResource(getGlobalApiClient());
21
+ }
22
+ catch (error) {
23
+ throw new Error('Failed to initialize express payment methods resource: ' +
24
+ (error instanceof Error ? error.message : 'Unknown error'));
25
+ }
26
+ }, []);
27
+ // Fetch payment methods using TanStack Query
28
+ const { data: paymentMethods, isLoading: isLoadingPaymentMethods } = useQuery({
29
+ queryKey: ['payment-methods', checkoutSessionId],
30
+ queryFn: () => expressPaymentResource.getPaymentMethods(checkoutSessionId),
31
+ enabled: !!checkoutSessionId,
32
+ staleTime: 60000, // 1 minute
33
+ refetchOnWindowFocus: false,
34
+ });
35
+ // Use v2 shipping rates hook
36
+ const { shippingRates, refetch: refetchRates } = useShippingRatesQuery({ checkout });
37
+ // Get order summary from checkout data
38
+ const orderSummary = checkout?.summary;
39
+ const handleAddExpressId = useCallback((id) => {
40
+ setAvailableExpressPaymentMethodIds((prev) => (prev.includes(id) ? prev : [...prev, id]));
41
+ }, []);
42
+ const minorUnitsToCurrencyString = useCallback((amountMinor, currency) => {
43
+ if (!amountMinor || !currency)
44
+ return '0.00';
45
+ return (amountMinor / 100).toFixed(2);
46
+ }, []);
47
+ // Convert shipping rates to express shipping methods
48
+ const shippingMethods = useMemo(() => (shippingRates || []).map((rate) => ({
49
+ label: rate.shippingRateName,
50
+ amount: minorUnitsToCurrencyString(rate.amount, rate.currency),
51
+ identifier: rate.id,
52
+ detail: rate.description || '',
53
+ })), [shippingRates, minorUnitsToCurrencyString]);
54
+ // Convert order summary to line items
55
+ const lineItems = useMemo(() => [
56
+ {
57
+ label: 'Subtotal',
58
+ amount: minorUnitsToCurrencyString(orderSummary?.subtotalAdjustedAmount, orderSummary?.currency),
59
+ },
60
+ {
61
+ label: 'Shipping',
62
+ amount: minorUnitsToCurrencyString(orderSummary?.shippingCost ?? 0, orderSummary?.currency),
63
+ },
64
+ {
65
+ label: 'Tax',
66
+ amount: minorUnitsToCurrencyString(orderSummary?.totalTaxAmount, orderSummary?.currency),
67
+ },
68
+ ], [orderSummary, minorUnitsToCurrencyString]);
69
+ // Update checkout session address mutation
70
+ const updateAddressMutation = useMutation({
71
+ mutationFn: (data) => expressPaymentResource.updateCheckoutSessionAddress(checkoutSessionId, { data }),
72
+ onSuccess: () => {
73
+ // Invalidate checkout query to refresh data
74
+ void queryClient.invalidateQueries({ queryKey: ['checkout'] });
75
+ },
76
+ });
77
+ // Update customer email mutation
78
+ const updateEmailMutation = useMutation({
79
+ mutationFn: (data) => expressPaymentResource.updateCustomerEmail(customerId, { data }),
80
+ });
81
+ // Recompute order summary (refetch after updates)
82
+ const reComputeOrderSummary = useCallback(async () => {
83
+ try {
84
+ // Invalidate and refetch checkout to get latest data
85
+ await queryClient.invalidateQueries({ queryKey: ['checkout'] });
86
+ await refetchRates();
87
+ // Wait a bit for queries to settle
88
+ await new Promise((resolve) => setTimeout(resolve, 100));
89
+ // Get fresh data from cache
90
+ const freshCheckout = queryClient.getQueryData(['checkout']);
91
+ const freshSummary = freshCheckout?.summary;
92
+ if (!freshSummary || !shippingRates)
93
+ return;
94
+ const recomputedLineItems = [
95
+ {
96
+ label: 'Subtotal',
97
+ amount: minorUnitsToCurrencyString(freshSummary.subtotalAdjustedAmount, freshSummary.currency),
98
+ },
99
+ {
100
+ label: 'Shipping',
101
+ amount: minorUnitsToCurrencyString(freshSummary.shippingCost ?? 0, freshSummary.currency),
102
+ },
103
+ {
104
+ label: 'Tax',
105
+ amount: minorUnitsToCurrencyString(freshSummary.totalTaxAmount, freshSummary.currency),
106
+ },
107
+ ];
108
+ const total = {
109
+ label: 'Order Total',
110
+ amount: minorUnitsToCurrencyString(freshSummary.totalAdjustedAmount, freshSummary.currency),
111
+ };
112
+ const recomputedShippingMethods = (shippingRates || []).map((rate) => ({
113
+ label: rate.shippingRateName,
114
+ amount: minorUnitsToCurrencyString(rate.amount, rate.currency),
115
+ identifier: rate.id,
116
+ detail: rate.description || '',
117
+ }));
118
+ return {
119
+ lineItems: recomputedLineItems,
120
+ total,
121
+ shippingMethods: recomputedShippingMethods,
122
+ };
123
+ }
124
+ catch (e) {
125
+ console.error('Error recomputing order summary:', e);
126
+ return undefined;
127
+ }
128
+ }, [queryClient, refetchRates, shippingRates, minorUnitsToCurrencyString]);
129
+ // Update checkout session values
130
+ const updateCheckoutSessionValues = useCallback(async (input) => {
131
+ await updateAddressMutation.mutateAsync(input.data);
132
+ }, [updateAddressMutation]);
133
+ // Update customer email
134
+ const updateCustomerEmail = useCallback(async (input) => {
135
+ if (!customerId)
136
+ return;
137
+ await updateEmailMutation.mutateAsync(input.data);
138
+ }, [customerId, updateEmailMutation]);
139
+ // Identify specific payment method types
140
+ const applePayPaymentMethod = useMemo(() => paymentMethods?.find((p) => p.type === 'apple_pay'), [paymentMethods]);
141
+ const googlePayPaymentMethod = useMemo(() => paymentMethods?.find((p) => p.type === 'google_pay'), [paymentMethods]);
142
+ const paypalPaymentMethod = useMemo(() => paymentMethods?.find((p) => p.type === 'paypal'), [paymentMethods]);
143
+ const klarnaPaymentMethod = useMemo(() => paymentMethods?.find((p) => p.type === 'klarna'), [paymentMethods]);
144
+ const loading = !paymentMethods || isLoadingPaymentMethods;
145
+ const contextValue = {
146
+ paymentMethods,
147
+ availableExpressPaymentMethodIds,
148
+ setAvailableExpressPaymentMethodIds,
149
+ applePayPaymentMethod,
150
+ googlePayPaymentMethod,
151
+ paypalPaymentMethod,
152
+ klarnaPaymentMethod,
153
+ shippingMethods,
154
+ lineItems,
155
+ reComputeOrderSummary,
156
+ loading,
157
+ handleAddExpressId,
158
+ updateCheckoutSessionValues,
159
+ updateCustomerEmail,
160
+ error,
161
+ setError,
162
+ };
163
+ const hasAnyEnabled = Boolean(applePayPaymentMethod || googlePayPaymentMethod || paypalPaymentMethod || klarnaPaymentMethod);
164
+ return (_jsx(ExpressPaymentMethodsContext.Provider, { value: contextValue, children: hasAnyEnabled ? _jsx(_Fragment, { children: children }) : _jsx(_Fragment, {}) }));
165
+ };
@@ -41,11 +41,11 @@ const InitializationLoader = () => (_jsxs("div", { style: {
41
41
  borderTop: '1.5px solid #9ca3af',
42
42
  borderRadius: '50%',
43
43
  animation: 'tagada-spin 1s linear infinite',
44
- } }), _jsx("span", { children: "Loading..." }), _jsx("style", { children: `
45
- @keyframes tagada-spin {
46
- 0% { transform: rotate(0deg); }
47
- 100% { transform: rotate(360deg); }
48
- }
44
+ } }), _jsx("span", { children: "Loading..." }), _jsx("style", { children: `
45
+ @keyframes tagada-spin {
46
+ 0% { transform: rotate(0deg); }
47
+ 100% { transform: rotate(360deg); }
48
+ }
49
49
  ` })] }));
50
50
  const TagadaContext = createContext(null);
51
51
  // Global instance tracking for TagadaProvider
package/package.json CHANGED
@@ -1,90 +1,90 @@
1
- {
2
- "name": "@tagadapay/plugin-sdk",
3
- "version": "2.6.2",
4
- "description": "Modern React SDK for building Tagada Pay plugins",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "exports": {
8
- ".": {
9
- "types": "./dist/index.d.ts",
10
- "import": "./dist/index.js",
11
- "require": "./dist/index.js"
12
- },
13
- "./react": {
14
- "types": "./dist/react/index.d.ts",
15
- "import": "./dist/react/index.js",
16
- "require": "./dist/react/index.js"
17
- },
18
- "./v2": {
19
- "types": "./dist/v2/index.d.ts",
20
- "import": "./dist/v2/index.js",
21
- "require": "./dist/v2/index.js"
22
- }
23
- },
24
- "scripts": {
25
- "build": "tsc",
26
- "clean": "rm -rf dist",
27
- "lint": "echo \"No linting configured\"",
28
- "test": "echo \"No tests yet\" && exit 0",
29
- "dev": "tsc --watch",
30
- "prepublishOnly": "npm run clean && npm run build",
31
- "publish:patch": "npm version patch && npm publish",
32
- "publish:minor": "npm version minor && npm publish",
33
- "publish:major": "npm version major && npm publish",
34
- "publish:beta": "npm version prerelease --preid=beta && npm publish --tag beta",
35
- "publish:alpha": "npm version prerelease --preid=alpha && npm publish --tag alpha",
36
- "version:patch": "npm version patch",
37
- "version:minor": "npm version minor",
38
- "version:major": "npm version major",
39
- "version:beta": "npm version prerelease --preid=beta",
40
- "version:alpha": "npm version prerelease --preid=alpha",
41
- "version:check": "node version-sync.js check",
42
- "version:sync": "node version-sync.js sync",
43
- "version:list": "node version-sync.js list",
44
- "version:next": "node version-sync.js next",
45
- "postversion": "echo \"✅ Version updated to $(node -p 'require(\"./package.json\").version')\" && (git push && git push --tags || echo \"⚠️ Git push failed - you may need to pull and push manually\")"
46
- },
47
- "keywords": [
48
- "tagadapay",
49
- "cms",
50
- "plugin",
51
- "sdk",
52
- "react",
53
- "typescript"
54
- ],
55
- "author": "Tagada Pay",
56
- "license": "MIT",
57
- "dependencies": {
58
- "@basis-theory/apple-pay-js": "^2.0.2",
59
- "@basis-theory/basis-theory-js": "^4.30.0",
60
- "@basis-theory/basis-theory-react": "^1.32.5",
61
- "@basis-theory/web-threeds": "^1.0.1",
62
- "@tanstack/react-query": "^5.90.2",
63
- "axios": "^1.10.0",
64
- "iso3166-2-db": "^2.3.11",
65
- "react-intl": "^7.1.11",
66
- "swr": "^2.3.6"
67
- },
68
- "devDependencies": {
69
- "@types/node": "^18.0.0",
70
- "@types/react": "^19",
71
- "@types/react-dom": "^19",
72
- "typescript": "^5.0.0"
73
- },
74
- "peerDependencies": {
75
- "react": "^18.0.0 || ^19.0.0",
76
- "react-dom": "^18.0.0 || ^19.0.0"
77
- },
78
- "files": [
79
- "dist/**/*",
80
- "README.md"
81
- ],
82
- "repository": {
83
- "type": "git",
84
- "url": "git+https://github.com/tagadapay/plugin-sdk.git"
85
- },
86
- "bugs": {
87
- "url": "https://github.com/tagadapay/plugin-sdk/issues"
88
- },
89
- "homepage": "https://github.com/tagadapay/plugin-sdk#readme"
90
- }
1
+ {
2
+ "name": "@tagadapay/plugin-sdk",
3
+ "version": "2.6.6",
4
+ "description": "Modern React SDK for building Tagada Pay plugins",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js"
12
+ },
13
+ "./react": {
14
+ "types": "./dist/react/index.d.ts",
15
+ "import": "./dist/react/index.js",
16
+ "require": "./dist/react/index.js"
17
+ },
18
+ "./v2": {
19
+ "types": "./dist/v2/index.d.ts",
20
+ "import": "./dist/v2/index.js",
21
+ "require": "./dist/v2/index.js"
22
+ }
23
+ },
24
+ "scripts": {
25
+ "build": "tsc",
26
+ "clean": "rm -rf dist",
27
+ "lint": "echo \"No linting configured\"",
28
+ "test": "echo \"No tests yet\" && exit 0",
29
+ "dev": "tsc --watch",
30
+ "prepublishOnly": "npm run clean && npm run build",
31
+ "publish:patch": "npm version patch && npm publish",
32
+ "publish:minor": "npm version minor && npm publish",
33
+ "publish:major": "npm version major && npm publish",
34
+ "publish:beta": "npm version prerelease --preid=beta && npm publish --tag beta",
35
+ "publish:alpha": "npm version prerelease --preid=alpha && npm publish --tag alpha",
36
+ "version:patch": "npm version patch",
37
+ "version:minor": "npm version minor",
38
+ "version:major": "npm version major",
39
+ "version:beta": "npm version prerelease --preid=beta",
40
+ "version:alpha": "npm version prerelease --preid=alpha",
41
+ "version:check": "node version-sync.js check",
42
+ "version:sync": "node version-sync.js sync",
43
+ "version:list": "node version-sync.js list",
44
+ "version:next": "node version-sync.js next",
45
+ "postversion": "echo \"✅ Version updated to $(node -p 'require(\"./package.json\").version')\" && (git push && git push --tags || echo \"⚠️ Git push failed - you may need to pull and push manually\")"
46
+ },
47
+ "keywords": [
48
+ "tagadapay",
49
+ "cms",
50
+ "plugin",
51
+ "sdk",
52
+ "react",
53
+ "typescript"
54
+ ],
55
+ "author": "Tagada Pay",
56
+ "license": "MIT",
57
+ "dependencies": {
58
+ "@basis-theory/apple-pay-js": "^2.0.2",
59
+ "@basis-theory/basis-theory-js": "^4.30.0",
60
+ "@basis-theory/basis-theory-react": "^1.32.5",
61
+ "@basis-theory/web-threeds": "^1.0.1",
62
+ "@tanstack/react-query": "^5.90.2",
63
+ "axios": "^1.10.0",
64
+ "iso3166-2-db": "^2.3.11",
65
+ "react-intl": "^7.1.11",
66
+ "swr": "^2.3.6"
67
+ },
68
+ "devDependencies": {
69
+ "@types/node": "^18.0.0",
70
+ "@types/react": "^19",
71
+ "@types/react-dom": "^19",
72
+ "typescript": "^5.0.0"
73
+ },
74
+ "peerDependencies": {
75
+ "react": "^18.0.0 || ^19.0.0",
76
+ "react-dom": "^18.0.0 || ^19.0.0"
77
+ },
78
+ "files": [
79
+ "dist/**/*",
80
+ "README.md"
81
+ ],
82
+ "repository": {
83
+ "type": "git",
84
+ "url": "git+https://github.com/tagadapay/plugin-sdk.git"
85
+ },
86
+ "bugs": {
87
+ "url": "https://github.com/tagadapay/plugin-sdk/issues"
88
+ },
89
+ "homepage": "https://github.com/tagadapay/plugin-sdk#readme"
90
+ }