@tagadapay/headless-sdk 1.8.0-rc.0 → 1.9.0
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 +216 -1
- package/dist/core/client.d.ts +68 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/client.js +73 -0
- package/dist/core/client.js.map +1 -0
- package/dist/core/errors.d.ts +53 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +58 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/helpers/autocomplete.d.ts +89 -0
- package/dist/core/helpers/autocomplete.d.ts.map +1 -0
- package/dist/core/helpers/autocomplete.js +186 -0
- package/dist/core/helpers/autocomplete.js.map +1 -0
- package/dist/core/helpers/countries.d.ts +45 -0
- package/dist/core/helpers/countries.d.ts.map +1 -0
- package/dist/core/helpers/countries.js +65 -0
- package/dist/core/helpers/countries.js.map +1 -0
- package/dist/core/helpers/currency.d.ts +26 -0
- package/dist/core/helpers/currency.d.ts.map +1 -0
- package/dist/core/helpers/currency.js +72 -0
- package/dist/core/helpers/currency.js.map +1 -0
- package/dist/core/helpers/index.d.ts +6 -0
- package/dist/core/helpers/index.d.ts.map +1 -0
- package/dist/core/helpers/index.js +6 -0
- package/dist/core/helpers/index.js.map +1 -0
- package/dist/core/helpers/iso3166.d.ts +28 -0
- package/dist/core/helpers/iso3166.d.ts.map +1 -0
- package/dist/core/helpers/iso3166.js +84 -0
- package/dist/core/helpers/iso3166.js.map +1 -0
- package/dist/core/helpers/walletContact.d.ts +67 -0
- package/dist/core/helpers/walletContact.d.ts.map +1 -0
- package/dist/core/helpers/walletContact.js +71 -0
- package/dist/core/helpers/walletContact.js.map +1 -0
- package/dist/core/http.d.ts +27 -0
- package/dist/core/http.d.ts.map +1 -0
- package/dist/core/http.js +125 -0
- package/dist/core/http.js.map +1 -0
- package/dist/core/index.d.ts +15 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +13 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/modules/catalog.d.ts +27 -0
- package/dist/core/modules/catalog.d.ts.map +1 -0
- package/dist/core/modules/catalog.js +38 -0
- package/dist/core/modules/catalog.js.map +1 -0
- package/dist/core/modules/checkout.d.ts +268 -0
- package/dist/core/modules/checkout.d.ts.map +1 -0
- package/dist/core/modules/checkout.js +470 -0
- package/dist/core/modules/checkout.js.map +1 -0
- package/dist/core/modules/customer.d.ts +33 -0
- package/dist/core/modules/customer.d.ts.map +1 -0
- package/dist/core/modules/customer.js +53 -0
- package/dist/core/modules/customer.js.map +1 -0
- package/dist/core/modules/funnel.d.ts +38 -0
- package/dist/core/modules/funnel.d.ts.map +1 -0
- package/dist/core/modules/funnel.js +143 -0
- package/dist/core/modules/funnel.js.map +1 -0
- package/dist/core/modules/offers.d.ts +137 -0
- package/dist/core/modules/offers.d.ts.map +1 -0
- package/dist/core/modules/offers.js +141 -0
- package/dist/core/modules/offers.js.map +1 -0
- package/dist/core/modules/payment.d.ts +353 -0
- package/dist/core/modules/payment.d.ts.map +1 -0
- package/dist/core/modules/payment.js +784 -0
- package/dist/core/modules/payment.js.map +1 -0
- package/dist/core/modules/rx.d.ts +162 -0
- package/dist/core/modules/rx.d.ts.map +1 -0
- package/dist/core/modules/rx.js +46 -0
- package/dist/core/modules/rx.js.map +1 -0
- package/dist/core/types.d.ts +532 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +5 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/react/hooks/useCatalog.d.ts +25 -0
- package/dist/react/hooks/useCatalog.d.ts.map +1 -0
- package/dist/react/hooks/useCatalog.js +58 -0
- package/dist/react/hooks/useCatalog.js.map +1 -0
- package/dist/react/hooks/useCheckout.d.ts +58 -0
- package/dist/react/hooks/useCheckout.d.ts.map +1 -0
- package/dist/react/hooks/useCheckout.js +177 -0
- package/dist/react/hooks/useCheckout.js.map +1 -0
- package/dist/react/hooks/useCustomer.d.ts +28 -0
- package/dist/react/hooks/useCustomer.d.ts.map +1 -0
- package/dist/react/hooks/useCustomer.js +77 -0
- package/dist/react/hooks/useCustomer.js.map +1 -0
- package/dist/react/hooks/useGoogleAutocomplete.d.ts +26 -0
- package/dist/react/hooks/useGoogleAutocomplete.d.ts.map +1 -0
- package/dist/react/hooks/useGoogleAutocomplete.js +70 -0
- package/dist/react/hooks/useGoogleAutocomplete.js.map +1 -0
- package/dist/react/hooks/useISOData.d.ts +23 -0
- package/dist/react/hooks/useISOData.d.ts.map +1 -0
- package/dist/react/hooks/useISOData.js +63 -0
- package/dist/react/hooks/useISOData.js.map +1 -0
- package/dist/react/hooks/useOffers.d.ts +134 -0
- package/dist/react/hooks/useOffers.d.ts.map +1 -0
- package/dist/react/hooks/useOffers.js +171 -0
- package/dist/react/hooks/useOffers.js.map +1 -0
- package/dist/react/hooks/usePayment.d.ts +117 -0
- package/dist/react/hooks/usePayment.d.ts.map +1 -0
- package/dist/react/hooks/usePayment.js +233 -0
- package/dist/react/hooks/usePayment.js.map +1 -0
- package/dist/react/hooks/useRx.d.ts +64 -0
- package/dist/react/hooks/useRx.d.ts.map +1 -0
- package/dist/react/hooks/useRx.js +145 -0
- package/dist/react/hooks/useRx.js.map +1 -0
- package/dist/react/index.d.ts +22 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +12 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/internal/redirectGuard.d.ts +9 -0
- package/dist/react/internal/redirectGuard.d.ts.map +1 -0
- package/dist/react/internal/redirectGuard.js +25 -0
- package/dist/react/internal/redirectGuard.js.map +1 -0
- package/dist/react/provider.d.ts +31 -0
- package/dist/react/provider.d.ts.map +1 -0
- package/dist/react/provider.js +32 -0
- package/dist/react/provider.js.map +1 -0
- package/dist/stripe/StripeExpressButton.d.ts +30 -0
- package/dist/stripe/StripeExpressButton.d.ts.map +1 -0
- package/dist/stripe/StripeExpressButton.js +32 -0
- package/dist/stripe/StripeExpressButton.js.map +1 -0
- package/dist/stripe/StripeExpressCheckout.d.ts +109 -0
- package/dist/stripe/StripeExpressCheckout.d.ts.map +1 -0
- package/dist/stripe/StripeExpressCheckout.js +242 -0
- package/dist/stripe/StripeExpressCheckout.js.map +1 -0
- package/dist/stripe/index.d.ts +8 -0
- package/dist/stripe/index.d.ts.map +1 -0
- package/dist/stripe/index.js +15 -0
- package/dist/stripe/index.js.map +1 -0
- package/dist/stripe/useStripeExpress.d.ts +54 -0
- package/dist/stripe/useStripeExpress.d.ts.map +1 -0
- package/dist/stripe/useStripeExpress.js +125 -0
- package/dist/stripe/useStripeExpress.js.map +1 -0
- package/dist/tagada-headless-react.min.js +8 -0
- package/dist/tagada-headless-react.min.js.map +7 -0
- package/dist/tagada-headless.js +2423 -0
- package/dist/tagada-headless.min.js +8 -0
- package/dist/tagada-headless.min.js.map +7 -0
- package/package.json +79 -73
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { useState, useCallback, useRef, useEffect } from 'react';
|
|
2
|
+
import { useHeadlessClient } from '../provider.js';
|
|
3
|
+
import { tryClaimResume } from '../internal/redirectGuard.js';
|
|
4
|
+
/**
|
|
5
|
+
* React hook for payment processing.
|
|
6
|
+
*
|
|
7
|
+
* Handles the full payment lifecycle including 3DS redirects and return-URL detection.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* const { processPayment, isProcessing, error } = usePayment({
|
|
12
|
+
* onPaymentSuccess: (result) => router.push('/confirmation'),
|
|
13
|
+
* onPaymentFailed: (result) => toast.error(result.error),
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* // On submit — one function handles everything
|
|
17
|
+
* const result = await processPayment({
|
|
18
|
+
* checkoutSessionId: session.id,
|
|
19
|
+
* tagadaToken,
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function usePayment(options) {
|
|
24
|
+
const client = useHeadlessClient();
|
|
25
|
+
const [paymentSetup, setPaymentSetup] = useState(null);
|
|
26
|
+
const [expressMethods, setExpressMethods] = useState(null);
|
|
27
|
+
const [storeConfig, setStoreConfig] = useState(null);
|
|
28
|
+
const [isProcessing, setIsProcessing] = useState(false);
|
|
29
|
+
const [result, setResult] = useState(null);
|
|
30
|
+
const [error, setError] = useState(null);
|
|
31
|
+
const loadedRef = useRef(false);
|
|
32
|
+
const redirectReturnProcessedRef = useRef(false);
|
|
33
|
+
const optionsRef = useRef(options);
|
|
34
|
+
optionsRef.current = options;
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
// Return-URL detection: auto-resume after 3DS / processor redirect
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (typeof window === 'undefined')
|
|
40
|
+
return;
|
|
41
|
+
if (redirectReturnProcessedRef.current)
|
|
42
|
+
return;
|
|
43
|
+
const params = new URLSearchParams(window.location.search);
|
|
44
|
+
const paymentAction = params.get('paymentAction');
|
|
45
|
+
const paymentActionStatus = params.get('paymentActionStatus');
|
|
46
|
+
const paymentId = params.get('paymentId');
|
|
47
|
+
if (paymentAction !== 'requireAction' || paymentActionStatus !== 'completed' || !paymentId) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
redirectReturnProcessedRef.current = true;
|
|
51
|
+
if (!tryClaimResume(paymentId)) {
|
|
52
|
+
// Another hook (likely useOffers) already started the resume for this
|
|
53
|
+
// paymentId; don't double-poll or double-fire callbacks.
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
setIsProcessing(true);
|
|
57
|
+
setError(null);
|
|
58
|
+
const resume = async () => {
|
|
59
|
+
try {
|
|
60
|
+
const resumeResult = await client.payment.resumeAfterRedirect(paymentId);
|
|
61
|
+
// Clean payment-related query params from URL
|
|
62
|
+
const cleanParams = new URLSearchParams(window.location.search);
|
|
63
|
+
['paymentAction', 'paymentActionStatus', 'paymentId', 'payment_intent', 'payment_intent_client_secret', 'source_type', 'redirect_status'].forEach((p) => cleanParams.delete(p));
|
|
64
|
+
const newUrl = cleanParams.toString()
|
|
65
|
+
? `${window.location.pathname}?${cleanParams.toString()}`
|
|
66
|
+
: window.location.pathname;
|
|
67
|
+
window.history.replaceState({}, document.title, newUrl);
|
|
68
|
+
if (resumeResult.status === 'succeeded') {
|
|
69
|
+
optionsRef.current?.onPaymentSuccess?.(resumeResult);
|
|
70
|
+
}
|
|
71
|
+
else if (resumeResult.status === 'failed') {
|
|
72
|
+
setError(new Error(resumeResult.error));
|
|
73
|
+
optionsRef.current?.onPaymentFailed?.(resumeResult);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
setIsProcessing(false);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
void resume();
|
|
84
|
+
}, [client]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
// Load payment setup
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
const loadPaymentSetup = useCallback(async (checkoutSessionId, opts) => {
|
|
89
|
+
if (loadedRef.current)
|
|
90
|
+
return;
|
|
91
|
+
loadedRef.current = true;
|
|
92
|
+
const setupOpts = opts?.paymentSetupConfig
|
|
93
|
+
? { paymentSetupConfig: opts.paymentSetupConfig }
|
|
94
|
+
: optionsRef.current?.paymentSetupConfig
|
|
95
|
+
? { paymentSetupConfig: optionsRef.current.paymentSetupConfig }
|
|
96
|
+
: undefined;
|
|
97
|
+
try {
|
|
98
|
+
const [setup, express, config] = await Promise.all([
|
|
99
|
+
client.payment.getPaymentSetup(checkoutSessionId, setupOpts),
|
|
100
|
+
client.payment.getExpressMethods(checkoutSessionId, setupOpts),
|
|
101
|
+
client.payment.getStoreConfig(),
|
|
102
|
+
]);
|
|
103
|
+
setPaymentSetup(setup);
|
|
104
|
+
setExpressMethods(express);
|
|
105
|
+
setStoreConfig(config);
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
loadedRef.current = false;
|
|
109
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
110
|
+
}
|
|
111
|
+
}, [client]);
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
// processPayment — high-level, handles everything
|
|
114
|
+
// ---------------------------------------------------------------------------
|
|
115
|
+
const processPayment = useCallback(async (opts) => {
|
|
116
|
+
setIsProcessing(true);
|
|
117
|
+
setError(null);
|
|
118
|
+
try {
|
|
119
|
+
const payResult = await client.payment.processPayment(opts);
|
|
120
|
+
if (payResult.status === 'requires_redirect') {
|
|
121
|
+
// Browser redirect — the hook will resume on return via the useEffect above
|
|
122
|
+
if (payResult.method === 'POST' && payResult.postData) {
|
|
123
|
+
const form = document.createElement('form');
|
|
124
|
+
form.method = 'POST';
|
|
125
|
+
form.action = payResult.redirectUrl;
|
|
126
|
+
for (const [key, value] of Object.entries(payResult.postData)) {
|
|
127
|
+
const input = document.createElement('input');
|
|
128
|
+
input.type = 'hidden';
|
|
129
|
+
input.name = key;
|
|
130
|
+
input.value = value;
|
|
131
|
+
form.appendChild(input);
|
|
132
|
+
}
|
|
133
|
+
document.body.appendChild(form);
|
|
134
|
+
form.submit();
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
window.location.href = payResult.redirectUrl;
|
|
138
|
+
}
|
|
139
|
+
// Don't setIsProcessing(false) — page is navigating away
|
|
140
|
+
return payResult;
|
|
141
|
+
}
|
|
142
|
+
if (payResult.status === 'succeeded') {
|
|
143
|
+
optionsRef.current?.onPaymentSuccess?.(payResult);
|
|
144
|
+
}
|
|
145
|
+
else if (payResult.status === 'failed') {
|
|
146
|
+
setError(new Error(payResult.error));
|
|
147
|
+
optionsRef.current?.onPaymentFailed?.(payResult);
|
|
148
|
+
}
|
|
149
|
+
return payResult;
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
153
|
+
setError(e);
|
|
154
|
+
return { status: 'failed', error: e.message };
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
setIsProcessing(false);
|
|
158
|
+
}
|
|
159
|
+
}, [client]);
|
|
160
|
+
// ---------------------------------------------------------------------------
|
|
161
|
+
// Low-level pay (raw API, no action handling)
|
|
162
|
+
// ---------------------------------------------------------------------------
|
|
163
|
+
const wrapAsync = useCallback((fn) => async () => {
|
|
164
|
+
setIsProcessing(true);
|
|
165
|
+
setError(null);
|
|
166
|
+
try {
|
|
167
|
+
const r = await fn();
|
|
168
|
+
return r;
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
172
|
+
setError(e);
|
|
173
|
+
throw e;
|
|
174
|
+
}
|
|
175
|
+
finally {
|
|
176
|
+
setIsProcessing(false);
|
|
177
|
+
}
|
|
178
|
+
}, []);
|
|
179
|
+
const pay = useCallback(async (opts) => {
|
|
180
|
+
setIsProcessing(true);
|
|
181
|
+
setError(null);
|
|
182
|
+
try {
|
|
183
|
+
const r = await client.payment.pay(opts);
|
|
184
|
+
setResult(r);
|
|
185
|
+
return r;
|
|
186
|
+
}
|
|
187
|
+
catch (err) {
|
|
188
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
189
|
+
setError(e);
|
|
190
|
+
throw e;
|
|
191
|
+
}
|
|
192
|
+
finally {
|
|
193
|
+
setIsProcessing(false);
|
|
194
|
+
}
|
|
195
|
+
}, [client]);
|
|
196
|
+
const tokenizeCard = useCallback((card) => client.payment.tokenizeCard(card), [client]);
|
|
197
|
+
const processApplePay = useCallback(async (opts) => {
|
|
198
|
+
const fn = wrapAsync(() => client.payment.processApplePay(opts));
|
|
199
|
+
const r = await fn();
|
|
200
|
+
setResult(r);
|
|
201
|
+
return r;
|
|
202
|
+
}, [client, wrapAsync]);
|
|
203
|
+
const processGooglePay = useCallback(async (opts) => {
|
|
204
|
+
const fn = wrapAsync(() => client.payment.processGooglePay(opts));
|
|
205
|
+
const r = await fn();
|
|
206
|
+
setResult(r);
|
|
207
|
+
return r;
|
|
208
|
+
}, [client, wrapAsync]);
|
|
209
|
+
const processApm = useCallback(async (opts) => {
|
|
210
|
+
const fn = wrapAsync(() => client.payment.processApm(opts));
|
|
211
|
+
const r = await fn();
|
|
212
|
+
setResult(r);
|
|
213
|
+
return r;
|
|
214
|
+
}, [client, wrapAsync]);
|
|
215
|
+
const pollStatus = useCallback((paymentId) => client.payment.pollPaymentStatus(paymentId), [client]);
|
|
216
|
+
return {
|
|
217
|
+
paymentSetup,
|
|
218
|
+
expressMethods,
|
|
219
|
+
storeConfig,
|
|
220
|
+
isProcessing,
|
|
221
|
+
result,
|
|
222
|
+
error,
|
|
223
|
+
loadPaymentSetup,
|
|
224
|
+
processPayment,
|
|
225
|
+
pay,
|
|
226
|
+
tokenizeCard,
|
|
227
|
+
processApplePay,
|
|
228
|
+
processGooglePay,
|
|
229
|
+
processApm,
|
|
230
|
+
pollStatus,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=usePayment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePayment.js","sourceRoot":"","sources":["../../../src/react/hooks/usePayment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AA0G9D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,UAAU,CAAC,OAA2B;IACpD,MAAM,MAAM,GAAG,iBAAiB,EAAE,CAAC;IACnC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAA4B,IAAI,CAAC,CAA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,UAAU,GAAG,WAAW,CAC5B,CAAC,SAAiB,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,EAClE,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,OAAO;QACL,YAAY;QACZ,cAAc;QACd,WAAW;QACX,YAAY;QACZ,MAAM;QACN,KAAK;QACL,gBAAgB;QAChB,cAAc;QACd,GAAG;QACH,YAAY;QACZ,eAAe;QACf,gBAAgB;QAChB,UAAU;QACV,UAAU;KACX,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { RxCaseSummary, RxQuestionsForProduct, RxRequiredForProduct, RxSubmitCaseInput, RxSubmitCaseResult } from '../../core/modules/rx.js';
|
|
2
|
+
export interface UseRxReturn {
|
|
3
|
+
/** Cases attached to the current order (populated by `pollOrder`). */
|
|
4
|
+
cases: RxCaseSummary[];
|
|
5
|
+
/** Result of the last `submitCase` call, kept for the thank-you page. */
|
|
6
|
+
lastSubmission: RxSubmitCaseResult | null;
|
|
7
|
+
/** True while ANY rx call is in flight. */
|
|
8
|
+
isLoading: boolean;
|
|
9
|
+
error: Error | null;
|
|
10
|
+
/**
|
|
11
|
+
* Ask whether a product needs an Rx case before submitting payment.
|
|
12
|
+
* Storefronts call this at product-page load to decide whether to
|
|
13
|
+
* render the intake step.
|
|
14
|
+
*/
|
|
15
|
+
isRequiredForProduct: (productId: string, opts?: {
|
|
16
|
+
clinicalNetworkId?: string;
|
|
17
|
+
}) => Promise<RxRequiredForProduct>;
|
|
18
|
+
/** Fetch network-authored intake questions for a product. */
|
|
19
|
+
getQuestionsForProduct: (productId: string) => Promise<RxQuestionsForProduct>;
|
|
20
|
+
/**
|
|
21
|
+
* Submit a fresh case after the order is paid. The result is also
|
|
22
|
+
* stored in `lastSubmission` so the thank-you page can read it.
|
|
23
|
+
*/
|
|
24
|
+
submitCase: (input: RxSubmitCaseInput) => Promise<RxSubmitCaseResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Fetch the public summary of every case attached to a paid order.
|
|
27
|
+
* Useful for the thank-you page or order history.
|
|
28
|
+
*/
|
|
29
|
+
fetchCasesForOrder: (input: {
|
|
30
|
+
orderId: string;
|
|
31
|
+
checkoutToken: string;
|
|
32
|
+
}) => Promise<RxCaseSummary[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Auto-poll the cases for an order until they all reach a terminal
|
|
35
|
+
* status (approved / shipped / delivered / declined / cancelled /
|
|
36
|
+
* error). Returns a `stop()` function to cancel the polling.
|
|
37
|
+
*/
|
|
38
|
+
pollOrder: (input: {
|
|
39
|
+
orderId: string;
|
|
40
|
+
checkoutToken: string;
|
|
41
|
+
}, opts?: {
|
|
42
|
+
intervalMs?: number;
|
|
43
|
+
onUpdate?: (cases: RxCaseSummary[]) => void;
|
|
44
|
+
}) => () => void;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* React hook for Tagada Rx storefronts.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```tsx
|
|
51
|
+
* const { isRequiredForProduct, submitCase, lastSubmission, pollOrder } = useRx();
|
|
52
|
+
*
|
|
53
|
+
* useEffect(() => {
|
|
54
|
+
* if (orderId && checkoutToken) {
|
|
55
|
+
* const stop = pollOrder({ orderId, checkoutToken }, {
|
|
56
|
+
* onUpdate: (cases) => setCases(cases),
|
|
57
|
+
* });
|
|
58
|
+
* return stop;
|
|
59
|
+
* }
|
|
60
|
+
* }, [orderId, checkoutToken, pollOrder]);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function useRx(): UseRxReturn;
|
|
64
|
+
//# sourceMappingURL=useRx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRx.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useRx.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,aAAa,EACb,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACj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eadlessClient } from '../provider.js';
|
|
3
|
+
const TERMINAL_STATUSES = new Set([
|
|
4
|
+
'approved',
|
|
5
|
+
'shipped',
|
|
6
|
+
'delivered',
|
|
7
|
+
'declined',
|
|
8
|
+
'cancelled',
|
|
9
|
+
'error',
|
|
10
|
+
]);
|
|
11
|
+
/**
|
|
12
|
+
* React hook for Tagada Rx storefronts.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const { isRequiredForProduct, submitCase, lastSubmission, pollOrder } = useRx();
|
|
17
|
+
*
|
|
18
|
+
* useEffect(() => {
|
|
19
|
+
* if (orderId && checkoutToken) {
|
|
20
|
+
* const stop = pollOrder({ orderId, checkoutToken }, {
|
|
21
|
+
* onUpdate: (cases) => setCases(cases),
|
|
22
|
+
* });
|
|
23
|
+
* return stop;
|
|
24
|
+
* }
|
|
25
|
+
* }, [orderId, checkoutToken, pollOrder]);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function useRx() {
|
|
29
|
+
const client = useHeadlessClient();
|
|
30
|
+
const [cases, setCases] = useState([]);
|
|
31
|
+
const [lastSubmission, setLastSubmission] = useState(null);
|
|
32
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
33
|
+
const [error, setError] = useState(null);
|
|
34
|
+
const pollTimerRef = useRef(null);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
return () => {
|
|
37
|
+
if (pollTimerRef.current)
|
|
38
|
+
clearInterval(pollTimerRef.current);
|
|
39
|
+
};
|
|
40
|
+
}, []);
|
|
41
|
+
const isRequiredForProduct = useCallback(async (productId, opts) => {
|
|
42
|
+
setIsLoading(true);
|
|
43
|
+
setError(null);
|
|
44
|
+
try {
|
|
45
|
+
return await client.rx.isRequiredForProduct(productId, opts);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
49
|
+
setError(e);
|
|
50
|
+
throw e;
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
setIsLoading(false);
|
|
54
|
+
}
|
|
55
|
+
}, [client]);
|
|
56
|
+
const getQuestionsForProduct = useCallback(async (productId) => {
|
|
57
|
+
setIsLoading(true);
|
|
58
|
+
setError(null);
|
|
59
|
+
try {
|
|
60
|
+
return await client.rx.getQuestionsForProduct(productId);
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
64
|
+
setError(e);
|
|
65
|
+
throw e;
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
setIsLoading(false);
|
|
69
|
+
}
|
|
70
|
+
}, [client]);
|
|
71
|
+
const submitCase = useCallback(async (input) => {
|
|
72
|
+
setIsLoading(true);
|
|
73
|
+
setError(null);
|
|
74
|
+
try {
|
|
75
|
+
const res = await client.rx.submitCase(input);
|
|
76
|
+
setLastSubmission(res);
|
|
77
|
+
return res;
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
81
|
+
setError(e);
|
|
82
|
+
throw e;
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
setIsLoading(false);
|
|
86
|
+
}
|
|
87
|
+
}, [client]);
|
|
88
|
+
const fetchCasesForOrder = useCallback(async (input) => {
|
|
89
|
+
setIsLoading(true);
|
|
90
|
+
setError(null);
|
|
91
|
+
try {
|
|
92
|
+
const res = await client.rx.getCasesForOrder(input);
|
|
93
|
+
setCases(res.cases);
|
|
94
|
+
return res.cases;
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
98
|
+
setError(e);
|
|
99
|
+
throw e;
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
setIsLoading(false);
|
|
103
|
+
}
|
|
104
|
+
}, [client]);
|
|
105
|
+
const pollOrder = useCallback(({ orderId, checkoutToken }, opts) => {
|
|
106
|
+
if (pollTimerRef.current)
|
|
107
|
+
clearInterval(pollTimerRef.current);
|
|
108
|
+
const intervalMs = opts?.intervalMs ?? 5000;
|
|
109
|
+
const tick = async () => {
|
|
110
|
+
try {
|
|
111
|
+
const res = await client.rx.getCasesForOrder({ orderId, checkoutToken });
|
|
112
|
+
setCases(res.cases);
|
|
113
|
+
opts?.onUpdate?.(res.cases);
|
|
114
|
+
if (res.cases.length > 0 && res.cases.every((c) => TERMINAL_STATUSES.has(c.status))) {
|
|
115
|
+
if (pollTimerRef.current)
|
|
116
|
+
clearInterval(pollTimerRef.current);
|
|
117
|
+
pollTimerRef.current = null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
122
|
+
setError(e);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
void tick();
|
|
126
|
+
pollTimerRef.current = setInterval(tick, intervalMs);
|
|
127
|
+
return () => {
|
|
128
|
+
if (pollTimerRef.current)
|
|
129
|
+
clearInterval(pollTimerRef.current);
|
|
130
|
+
pollTimerRef.current = null;
|
|
131
|
+
};
|
|
132
|
+
}, [client]);
|
|
133
|
+
return {
|
|
134
|
+
cases,
|
|
135
|
+
lastSubmission,
|
|
136
|
+
isLoading,
|
|
137
|
+
error,
|
|
138
|
+
isRequiredForProduct,
|
|
139
|
+
getQuestionsForProduct,
|
|
140
|
+
submitCase,
|
|
141
|
+
fetchCasesForOrder,
|
|
142
|
+
pollOrder,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=useRx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRx.js","sourceRoot":"","sources":["../../../src/react/hooks/useRx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { TagadaHeadlessProvider, useHeadlessClient } from './provider.js';
|
|
2
|
+
export type { TagadaHeadlessProviderProps } from './provider.js';
|
|
3
|
+
export { useCheckout } from './hooks/useCheckout.js';
|
|
4
|
+
export type { UseCheckoutReturn } from './hooks/useCheckout.js';
|
|
5
|
+
export { usePayment } from './hooks/usePayment.js';
|
|
6
|
+
export type { UsePaymentReturn, UsePaymentOptions } from './hooks/usePayment.js';
|
|
7
|
+
export { useOffers } from './hooks/useOffers.js';
|
|
8
|
+
export type { UseOffersReturn } from './hooks/useOffers.js';
|
|
9
|
+
export { useCustomer } from './hooks/useCustomer.js';
|
|
10
|
+
export type { UseCustomerReturn } from './hooks/useCustomer.js';
|
|
11
|
+
export { useCatalog } from './hooks/useCatalog.js';
|
|
12
|
+
export type { UseCatalogReturn } from './hooks/useCatalog.js';
|
|
13
|
+
export { useRx } from './hooks/useRx.js';
|
|
14
|
+
export type { UseRxReturn } from './hooks/useRx.js';
|
|
15
|
+
export { useGoogleAutocomplete } from './hooks/useGoogleAutocomplete.js';
|
|
16
|
+
export type { UseGoogleAutocompleteOptions, UseGoogleAutocompleteReturn } from './hooks/useGoogleAutocomplete.js';
|
|
17
|
+
export { useISOData, useCountryOptions, useRegionOptions } from './hooks/useISOData.js';
|
|
18
|
+
export type { UseISODataReturn } from './hooks/useISOData.js';
|
|
19
|
+
export type { GooglePrediction, GooglePlaceDetails, ExtractedAddress, FormattedAddress, SupportedLanguage, ISOCountry, ISORegion, Currency, } from '../core/helpers/index.js';
|
|
20
|
+
export { formatMoney, CurrencyUtils, ISODataCore, GoogleAutocompleteCore, loadGoogleMapsScript } from '../core/helpers/index.js';
|
|
21
|
+
export type { HeadlessConfig, Environment, CheckoutSession, CheckoutLineItem, CheckoutTotals, CheckoutCustomer, Address, ShippingRate, LineItem, PaymentSetupConfig, PaymentMethodConfig, ExpressMethods, ExpressMethod, StoreConfig, PayResult, PayOptions, PaymentStatus, ProcessPaymentOptions, ProcessPaymentResult, Offer, OfferLineItem, OfferPreview, OfferPreviewItem, OfferPayResult, Customer, Order, Subscription, CatalogProduct, CatalogVariant, CatalogPrice, CurrencyOption, StripeExpressOptions, } from '../core/types.js';
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC1E,YAAY,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAEjF,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,YAAY,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,YAAY,EAAE,4BAA4B,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAElH,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACxF,YAAY,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,YAAY,EACV,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,SAAS,EACT,QAAQ,GACT,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEjI,YAAY,EACV,cAAc,EACd,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,WAAW,EACX,SAAS,EACT,UAAU,EACV,aAAa,EACb,qBAAqB,EACrB,oBAAoB,EACpB,KAAK,EACL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,QAAQ,EACR,KAAK,EACL,YAAY,EACZ,cAAc,EACd,cAAc,EACd,YAAY,EACZ,cAAc,EACd,oBAAoB,GACrB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { TagadaHeadlessProvider, useHeadlessClient } from './provider.js';
|
|
2
|
+
export { useCheckout } from './hooks/useCheckout.js';
|
|
3
|
+
export { usePayment } from './hooks/usePayment.js';
|
|
4
|
+
export { useOffers } from './hooks/useOffers.js';
|
|
5
|
+
export { useCustomer } from './hooks/useCustomer.js';
|
|
6
|
+
export { useCatalog } from './hooks/useCatalog.js';
|
|
7
|
+
export { useRx } from './hooks/useRx.js';
|
|
8
|
+
// Helpers hooks
|
|
9
|
+
export { useGoogleAutocomplete } from './hooks/useGoogleAutocomplete.js';
|
|
10
|
+
export { useISOData, useCountryOptions, useRegionOptions } from './hooks/useISOData.js';
|
|
11
|
+
export { formatMoney, CurrencyUtils, ISODataCore, GoogleAutocompleteCore, loadGoogleMapsScript } from '../core/helpers/index.js';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAG1E,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGzC,gBAAgB;AAChB,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAGzE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAexF,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Try to claim ownership of resuming a payment. Returns `true` if the
|
|
3
|
+
* caller is the first one to claim it (and should proceed); `false` if
|
|
4
|
+
* another hook has already claimed it.
|
|
5
|
+
*/
|
|
6
|
+
export declare function tryClaimResume(paymentId: string): boolean;
|
|
7
|
+
/** Reset the guard. Useful in tests and on hard refresh logic. */
|
|
8
|
+
export declare function resetResumeGuard(): void;
|
|
9
|
+
//# sourceMappingURL=redirectGuard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirectGuard.d.ts","sourceRoot":"","sources":["../../../src/react/internal/redirectGuard.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAIzD;AAED,kEAAkE;AAClE,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module-level guard preventing two hooks (`usePayment`, `useOffers`) from
|
|
3
|
+
* both resuming the same payment after a 3DS / processor redirect.
|
|
4
|
+
*
|
|
5
|
+
* Each `paymentId` is processed at most once per page load. The first hook
|
|
6
|
+
* that wins the race calls `client.payment.resumeAfterRedirect` and fires
|
|
7
|
+
* its callback; the other hook becomes a no-op.
|
|
8
|
+
*/
|
|
9
|
+
const RESUMED_PAYMENT_IDS = new Set();
|
|
10
|
+
/**
|
|
11
|
+
* Try to claim ownership of resuming a payment. Returns `true` if the
|
|
12
|
+
* caller is the first one to claim it (and should proceed); `false` if
|
|
13
|
+
* another hook has already claimed it.
|
|
14
|
+
*/
|
|
15
|
+
export function tryClaimResume(paymentId) {
|
|
16
|
+
if (RESUMED_PAYMENT_IDS.has(paymentId))
|
|
17
|
+
return false;
|
|
18
|
+
RESUMED_PAYMENT_IDS.add(paymentId);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
/** Reset the guard. Useful in tests and on hard refresh logic. */
|
|
22
|
+
export function resetResumeGuard() {
|
|
23
|
+
RESUMED_PAYMENT_IDS.clear();
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=redirectGuard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirectGuard.js","sourceRoot":"","sources":["../../../src/react/internal/redirectGuard.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAU,CAAC;AAE9C;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,SAAiB;IAC9C,IAAI,mBAAmB,CAAC,GAAG,CAAC,SAAS,CAAC;QAAE,OAAO,KAAK,CAAC;IACrD,mBAAmB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACnC,OAAO,IAAI,CAAC;AACd,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,gBAAgB;IAC9B,mBAAmB,CAAC,KAAK,EAAE,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { HeadlessClient } from '../core/client.js';
|
|
3
|
+
import type { HeadlessConfig, Environment } from '../core/types.js';
|
|
4
|
+
export interface TagadaHeadlessProviderProps {
|
|
5
|
+
/** Your TagadaPay store ID. */
|
|
6
|
+
storeId: string;
|
|
7
|
+
/** Environment. Defaults to "production". */
|
|
8
|
+
environment?: Environment;
|
|
9
|
+
/** Public API key for authenticated requests. */
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
/** Override the base API URL. */
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
/** Full config object (alternative to individual props). */
|
|
14
|
+
config?: HeadlessConfig;
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Root provider for the TagadaPay Headless SDK React integration.
|
|
19
|
+
* Creates a single HeadlessClient and shares it via context.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* <TagadaHeadlessProvider storeId="store_abc123" environment="production">
|
|
24
|
+
* <App />
|
|
25
|
+
* </TagadaHeadlessProvider>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function TagadaHeadlessProvider({ storeId, environment, apiKey, baseUrl, config, children, }: TagadaHeadlessProviderProps): import("react/jsx-runtime.js").JSX.Element;
|
|
29
|
+
/** Access the HeadlessClient from context. Throws if used outside the provider. */
|
|
30
|
+
export declare function useHeadlessClient(): HeadlessClient;
|
|
31
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/react/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,cAAc,EAAwB,MAAM,mBAAmB,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAQpE,MAAM,WAAW,2BAA2B;IAC1C,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,6CAA6C;IAC7C,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,iDAAiD;IACjD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iCAAiC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4DAA4D;IAC5D,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,OAAO,EACP,WAAW,EACX,MAAM,EACN,OAAO,EACP,MAAM,EACN,QAAQ,GACT,EAAE,2BAA2B,8CAa7B;AAED,mFAAmF;AACnF,wBAAgB,iBAAiB,IAAI,cAAc,CAMlD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
3
|
+
import { createHeadlessClient } from '../core/client.js';
|
|
4
|
+
const TagadaHeadlessContext = createContext(null);
|
|
5
|
+
/**
|
|
6
|
+
* Root provider for the TagadaPay Headless SDK React integration.
|
|
7
|
+
* Creates a single HeadlessClient and shares it via context.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* <TagadaHeadlessProvider storeId="store_abc123" environment="production">
|
|
12
|
+
* <App />
|
|
13
|
+
* </TagadaHeadlessProvider>
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export function TagadaHeadlessProvider({ storeId, environment, apiKey, baseUrl, config, children, }) {
|
|
17
|
+
const client = useMemo(() => {
|
|
18
|
+
const cfg = config ?? { storeId, environment, apiKey, baseUrl };
|
|
19
|
+
return createHeadlessClient(cfg);
|
|
20
|
+
}, [storeId, environment, apiKey, baseUrl, config]);
|
|
21
|
+
const value = useMemo(() => ({ client }), [client]);
|
|
22
|
+
return (_jsx(TagadaHeadlessContext.Provider, { value: value, children: children }));
|
|
23
|
+
}
|
|
24
|
+
/** Access the HeadlessClient from context. Throws if used outside the provider. */
|
|
25
|
+
export function useHeadlessClient() {
|
|
26
|
+
const ctx = useContext(TagadaHeadlessContext);
|
|
27
|
+
if (!ctx) {
|
|
28
|
+
throw new Error('useHeadlessClient must be used within <TagadaHeadlessProvider>');
|
|
29
|
+
}
|
|
30
|
+
return ctx.client;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/react/provider.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,EAAkB,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAOzE,MAAM,qBAAqB,GAAG,aAAa,CAAoC,IAAI,CAAC,CAAC;AAgBrF;;;;;;;;;;GAUG;AACH,MAAM,UAAU,sBAAsB,CAAC,EACrC,OAAO,EACP,WAAW,EACX,MAAM,EACN,OAAO,EACP,MAAM,EACN,QAAQ,GACoB;IAC5B,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE;QAC1B,MAAM,GAAG,GAAmB,MAAM,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;QAChF,OAAO,oBAAoB,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;IAEpD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEpD,OAAO,CACL,KAAC,qBAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACzC,QAAQ,GACsB,CAClC,CAAC;AACJ,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,iBAAiB;IAC/B,MAAM,GAAG,GAAG,UAAU,CAAC,qBAAqB,CAAC,CAAC;IAC9C,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;IACpF,CAAC;IACD,OAAO,GAAG,CAAC,MAAM,CAAC;AACpB,CAAC"}
|