@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,353 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js';
|
|
2
|
+
import { type ApplePayContact, type GooglePayContact } from '../helpers/walletContact.js';
|
|
3
|
+
import type { CheckoutModule } from './checkout.js';
|
|
4
|
+
import type { Environment, PaymentSetupConfig, ExpressMethods, StoreConfig, PayResult, PayOptions, PayDirectOptions, CreateInstrumentOptions, PaymentInstrument, ThreedsSession, PaymentStatus, ProcessPaymentOptions, ProcessPaymentResult } from '../types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Full payment lifecycle -- discover APMs, tokenize, create instruments,
|
|
7
|
+
* process payments, handle 3DS, and poll for status.
|
|
8
|
+
*
|
|
9
|
+
* Wraps the same REST endpoints that plugin-sdk uses internally.
|
|
10
|
+
*
|
|
11
|
+
* @remarks PCI DSS compliance notice
|
|
12
|
+
*
|
|
13
|
+
* This SDK collects card data (PAN, expiry, CVC) in the merchant's page
|
|
14
|
+
* context and sends it directly to Basis Theory for tokenization. Card data
|
|
15
|
+
* never reaches TagadaPay servers.
|
|
16
|
+
*
|
|
17
|
+
* Because card data transits through the merchant's JavaScript environment,
|
|
18
|
+
* merchants using this SDK are responsible for **PCI DSS SAQ-A-EP**
|
|
19
|
+
* compliance. This includes quarterly ASV scans, secure page delivery
|
|
20
|
+
* (TLS), and ensuring no unauthorized scripts can access cardholder data.
|
|
21
|
+
*
|
|
22
|
+
* TagadaPay is PCI DSS Level 1 certified. The merchant's PCI scope is
|
|
23
|
+
* determined by their integration method, not by TagadaPay's certification.
|
|
24
|
+
*
|
|
25
|
+
* See: https://docs.tagada.io/developer-tools/headless-sdk/pci-compliance
|
|
26
|
+
*/
|
|
27
|
+
export declare class PaymentModule {
|
|
28
|
+
private readonly http;
|
|
29
|
+
private readonly storeId;
|
|
30
|
+
private readonly environment;
|
|
31
|
+
/** Used to persist wallet contacts onto the session before charging. */
|
|
32
|
+
private readonly checkout?;
|
|
33
|
+
constructor(http: HttpClient, storeId: string, environment: Environment,
|
|
34
|
+
/** Used to persist wallet contacts onto the session before charging. */
|
|
35
|
+
checkout?: CheckoutModule | undefined);
|
|
36
|
+
/**
|
|
37
|
+
* Get the full payment setup config for a checkout session.
|
|
38
|
+
* Returns a map of payment methods with their configuration
|
|
39
|
+
* (card, apple_pay, google_pay, klarna, etc.).
|
|
40
|
+
*
|
|
41
|
+
* Priority chain:
|
|
42
|
+
* 1. Explicit `paymentSetupConfig` parameter (developer override)
|
|
43
|
+
* 2. `window.__TGD_STEP_CONFIG__` injection (Tagada routing infra)
|
|
44
|
+
* 3. API fallback (`GET /api/v1/payment-methods`)
|
|
45
|
+
*/
|
|
46
|
+
getPaymentSetup(checkoutSessionId: string, opts?: {
|
|
47
|
+
paymentSetupConfig?: PaymentSetupConfig;
|
|
48
|
+
}): Promise<PaymentSetupConfig>;
|
|
49
|
+
/**
|
|
50
|
+
* Get express payment methods (Apple Pay, Google Pay, PayPal, etc.)
|
|
51
|
+
* filtered to only those available in the current browser.
|
|
52
|
+
*/
|
|
53
|
+
getExpressMethods(checkoutSessionId: string, opts?: {
|
|
54
|
+
paymentSetupConfig?: PaymentSetupConfig;
|
|
55
|
+
}): Promise<ExpressMethods>;
|
|
56
|
+
/**
|
|
57
|
+
* Get store-level payment config (3DS flags, default flow ID, etc.).
|
|
58
|
+
*/
|
|
59
|
+
getStoreConfig(): Promise<StoreConfig>;
|
|
60
|
+
/**
|
|
61
|
+
* Convenience: return only enabled payment method keys.
|
|
62
|
+
*/
|
|
63
|
+
getEnabledMethods(checkoutSessionId: string, opts?: {
|
|
64
|
+
paymentSetupConfig?: PaymentSetupConfig;
|
|
65
|
+
}): Promise<string[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Tokenize a card using @tagadapay/core-js.
|
|
68
|
+
* Requires `@tagadapay/core-js` to be installed as a peer dependency.
|
|
69
|
+
*
|
|
70
|
+
* Card data is sent directly to Basis Theory for tokenization and never
|
|
71
|
+
* reaches TagadaPay servers. The returned `tagadaToken` is safe to pass
|
|
72
|
+
* to the TagadaPay API.
|
|
73
|
+
*
|
|
74
|
+
* **PCI note:** Using this method means card data passes through your
|
|
75
|
+
* JavaScript environment. You are responsible for PCI DSS SAQ-A-EP
|
|
76
|
+
* compliance. See https://docs.tagada.io/developer-tools/headless-sdk/pci-compliance
|
|
77
|
+
*
|
|
78
|
+
* @returns tagadaToken (base64 string) and rawToken with SCA metadata.
|
|
79
|
+
*/
|
|
80
|
+
tokenizeCard(card: {
|
|
81
|
+
cardNumber: string;
|
|
82
|
+
expiryDate: string;
|
|
83
|
+
cvc: string;
|
|
84
|
+
cardholderName?: string;
|
|
85
|
+
}): Promise<{
|
|
86
|
+
tagadaToken: string;
|
|
87
|
+
rawToken: Record<string, unknown>;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Create a reusable payment instrument from a TagadaToken.
|
|
91
|
+
* Session-authenticated (uses the checkout session JWT).
|
|
92
|
+
*/
|
|
93
|
+
createInstrument(opts: CreateInstrumentOptions): Promise<{
|
|
94
|
+
paymentInstrument: PaymentInstrument;
|
|
95
|
+
}>;
|
|
96
|
+
/**
|
|
97
|
+
* Create a 3DS session on the TagadaPay backend.
|
|
98
|
+
* This persists the session so the processor can use it during payment.
|
|
99
|
+
*/
|
|
100
|
+
create3dsSession(opts: {
|
|
101
|
+
paymentInstrumentId: string;
|
|
102
|
+
sessionData: {
|
|
103
|
+
sessionId: string;
|
|
104
|
+
metadata?: Record<string, unknown>;
|
|
105
|
+
};
|
|
106
|
+
provider?: string;
|
|
107
|
+
}): Promise<ThreedsSession>;
|
|
108
|
+
/**
|
|
109
|
+
* High-level pay: single API call that decodes tagadaToken server-side,
|
|
110
|
+
* creates the payment instrument, and processes payment.
|
|
111
|
+
*
|
|
112
|
+
* Also accepts `paymentInstrumentId` directly for pre-created instruments.
|
|
113
|
+
*/
|
|
114
|
+
pay(opts: PayOptions): Promise<PayResult>;
|
|
115
|
+
/**
|
|
116
|
+
* Low-level pay: process payment with an existing instrument or for APM/express flows
|
|
117
|
+
* where no instrument is needed (redirect-based methods).
|
|
118
|
+
*/
|
|
119
|
+
payDirect(opts: PayDirectOptions): Promise<PayResult>;
|
|
120
|
+
/**
|
|
121
|
+
* Persist a wallet contact onto the session before the charge.
|
|
122
|
+
*
|
|
123
|
+
* Express wallets are the one checkout where the buyer never fills an address
|
|
124
|
+
* form: they approve one inside the sheet, and it comes back on the
|
|
125
|
+
* authorization event. Studio's `ExpressPaymentWidget` writes it to the
|
|
126
|
+
* session; the headless path used to drop it, which is how a year of orders
|
|
127
|
+
* reached merchants with NULL shipping, billing and customer addresses
|
|
128
|
+
* (#TAG-1989).
|
|
129
|
+
*
|
|
130
|
+
* Never invents data: a contact with no street line or no country maps to
|
|
131
|
+
* `undefined` and the session is left exactly as it was. Failures are NOT
|
|
132
|
+
* swallowed — if we hold an address and cannot store it, the charge must not
|
|
133
|
+
* proceed, or we are back to the bug this fixes.
|
|
134
|
+
*/
|
|
135
|
+
private syncWalletContact;
|
|
136
|
+
/**
|
|
137
|
+
* Process an Apple Pay payment.
|
|
138
|
+
* Tokenizes the Apple Pay token and processes payment in one call.
|
|
139
|
+
*
|
|
140
|
+
* Pass the contacts from `onpaymentauthorized` — `event.payment.billingContact`
|
|
141
|
+
* and `event.payment.shippingContact` — and they are written to the session
|
|
142
|
+
* before the charge, so the address the buyer approved in the wallet sheet
|
|
143
|
+
* lands on the order (#TAG-1989).
|
|
144
|
+
*
|
|
145
|
+
* Apple only returns them when the payment request asked for them, so the
|
|
146
|
+
* `ApplePaySession` request needs:
|
|
147
|
+
*
|
|
148
|
+
* ```js
|
|
149
|
+
* requiredBillingContactFields: ['postalAddress'],
|
|
150
|
+
* requiredShippingContactFields: ['name', 'phone', 'email', 'postalAddress'],
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* session.onpaymentauthorized = async (event) => {
|
|
155
|
+
* await tagada.payment.processApplePay({
|
|
156
|
+
* checkoutSessionId,
|
|
157
|
+
* applePayToken: event.payment.token,
|
|
158
|
+
* billingContact: event.payment.billingContact,
|
|
159
|
+
* shippingContact: event.payment.shippingContact,
|
|
160
|
+
* });
|
|
161
|
+
* };
|
|
162
|
+
*/
|
|
163
|
+
processApplePay(opts: {
|
|
164
|
+
checkoutSessionId: string;
|
|
165
|
+
applePayToken: unknown;
|
|
166
|
+
billingContact?: ApplePayContact | null;
|
|
167
|
+
shippingContact?: ApplePayContact | null;
|
|
168
|
+
paymentFlowId?: string;
|
|
169
|
+
processorId?: string;
|
|
170
|
+
}): Promise<PayResult>;
|
|
171
|
+
/**
|
|
172
|
+
* Process a Google Pay payment.
|
|
173
|
+
* Tokenizes the Google Pay token and processes payment in one call.
|
|
174
|
+
*
|
|
175
|
+
* Pass `paymentData.shippingAddress` / the billing address off
|
|
176
|
+
* `paymentMethodData.info.billingAddress` and they are persisted to the
|
|
177
|
+
* session before the charge (#TAG-1989). Google only returns them when the
|
|
178
|
+
* request sets `shippingAddressRequired` / `billingAddressRequired`.
|
|
179
|
+
*/
|
|
180
|
+
processGooglePay(opts: {
|
|
181
|
+
checkoutSessionId: string;
|
|
182
|
+
googlePayToken: string;
|
|
183
|
+
billingAddress?: GooglePayContact | null;
|
|
184
|
+
shippingAddress?: GooglePayContact | null;
|
|
185
|
+
email?: string;
|
|
186
|
+
paymentFlowId?: string;
|
|
187
|
+
processorId?: string;
|
|
188
|
+
}): Promise<PayResult>;
|
|
189
|
+
/**
|
|
190
|
+
* Process an APM payment (Klarna, iDEAL, etc.) via redirect.
|
|
191
|
+
* These typically don't require a payment instrument -- the processor handles the redirect.
|
|
192
|
+
*/
|
|
193
|
+
processApm(opts: {
|
|
194
|
+
checkoutSessionId: string;
|
|
195
|
+
paymentMethod: string;
|
|
196
|
+
processorId: string;
|
|
197
|
+
paymentFlowId?: string;
|
|
198
|
+
}): Promise<PayResult>;
|
|
199
|
+
/**
|
|
200
|
+
* Initiate a Stripe Express Checkout payment (Apple Pay, Google Pay, Link, etc.).
|
|
201
|
+
*
|
|
202
|
+
* Calls `pay-v2` with `isExpress: true`, which returns a `clientSecret` in
|
|
203
|
+
* `payment.requireActionData.metadata.stripeExpressCheckout.clientSecret`.
|
|
204
|
+
* The caller must then call `stripe.confirmPayment()` with that secret.
|
|
205
|
+
*
|
|
206
|
+
* Used by the `StripeExpressCheckout` class and `useStripeExpress` hook.
|
|
207
|
+
* Not typically called directly — use the Stripe integration classes instead.
|
|
208
|
+
*/
|
|
209
|
+
processStripeExpress(opts: {
|
|
210
|
+
checkoutSessionId: string;
|
|
211
|
+
processorId: string;
|
|
212
|
+
paymentMethod: string;
|
|
213
|
+
}): Promise<PayResult>;
|
|
214
|
+
/**
|
|
215
|
+
* Process a payment end-to-end: pay, handle 3DS / redirects, poll until done.
|
|
216
|
+
*
|
|
217
|
+
* This is the **recommended** way to process payments. It wraps `pay()`, detects
|
|
218
|
+
* `requireAction`, runs 3DS challenges (if `@tagadapay/core-js` is installed),
|
|
219
|
+
* and polls until a terminal status.
|
|
220
|
+
*
|
|
221
|
+
* Returns a discriminated union so you can pattern-match on `result.status`:
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```ts
|
|
225
|
+
* const result = await payment.processPayment({
|
|
226
|
+
* checkoutSessionId: session.id,
|
|
227
|
+
* tagadaToken,
|
|
228
|
+
* });
|
|
229
|
+
*
|
|
230
|
+
* switch (result.status) {
|
|
231
|
+
* case 'succeeded':
|
|
232
|
+
* console.log('Paid!', result.payment.id);
|
|
233
|
+
* break;
|
|
234
|
+
* case 'requires_redirect':
|
|
235
|
+
* // In browser: window.location.href = result.redirectUrl
|
|
236
|
+
* // The React hook handles this automatically.
|
|
237
|
+
* break;
|
|
238
|
+
* case 'failed':
|
|
239
|
+
* console.error(result.error);
|
|
240
|
+
* break;
|
|
241
|
+
* }
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
processPayment(opts: ProcessPaymentOptions): Promise<ProcessPaymentResult>;
|
|
245
|
+
/**
|
|
246
|
+
* Resolve a raw `PayResult` (from any pay endpoint — `pay()`, `payDirect()`,
|
|
247
|
+
* `processApplePay()`, `offers.payPreviewedOffer()`, …) into a typed
|
|
248
|
+
* `ProcessPaymentResult` (`succeeded` / `requires_redirect` / `failed`
|
|
249
|
+
* / `pending`).
|
|
250
|
+
*
|
|
251
|
+
* Handles 3DS routing (modal challenge via core-js, or bank redirect)
|
|
252
|
+
* and async polling until the payment reaches a terminal status.
|
|
253
|
+
*
|
|
254
|
+
* This is the same logic `processPayment()` runs after `pay()` — exposed
|
|
255
|
+
* so callers (and the offers module) that already have a raw `PayResult`
|
|
256
|
+
* don't need to re-pay.
|
|
257
|
+
*/
|
|
258
|
+
finalize(input: PayResult, opts?: {
|
|
259
|
+
returnUrl?: string;
|
|
260
|
+
}): Promise<ProcessPaymentResult>;
|
|
261
|
+
/**
|
|
262
|
+
* Resume a payment after the user returns from a redirect (3DS, processor auth, APM).
|
|
263
|
+
*
|
|
264
|
+
* Called automatically by `usePayment()` in React when it detects return-URL params.
|
|
265
|
+
* You can also call it manually in non-React apps.
|
|
266
|
+
*/
|
|
267
|
+
resumeAfterRedirect(paymentId: string): Promise<ProcessPaymentResult>;
|
|
268
|
+
/**
|
|
269
|
+
* Detect a return from a 3DS / processor redirect by inspecting the
|
|
270
|
+
* current page URL, then poll the payment to completion.
|
|
271
|
+
*
|
|
272
|
+
* The post-3DS URL convention used by Tagada-routed processors is
|
|
273
|
+
* `?paymentAction=requireAction&paymentActionStatus=completed&paymentId=pay_xxx`.
|
|
274
|
+
* If those params are present, this method polls the payment, cleans the
|
|
275
|
+
* URL (so a refresh doesn't re-trigger), and returns the resolved
|
|
276
|
+
* `ProcessPaymentResult`. Otherwise it returns `null`.
|
|
277
|
+
*
|
|
278
|
+
* Use this in vanilla apps as the first thing on page load. The React
|
|
279
|
+
* `usePayment` hook does the same automatically — don't call this when
|
|
280
|
+
* also using `usePayment`, you'll double-poll.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```ts
|
|
284
|
+
* const tagada = createHeadlessClient({ storeId, environment });
|
|
285
|
+
*
|
|
286
|
+
* const resumed = await tagada.payment.maybeResumeFromUrl();
|
|
287
|
+
* if (resumed?.status === 'succeeded') {
|
|
288
|
+
* window.location.href = `/thank-you?orderId=${resumed.order?.id}`;
|
|
289
|
+
* return;
|
|
290
|
+
* }
|
|
291
|
+
* if (resumed?.status === 'failed') {
|
|
292
|
+
* showError(resumed.error);
|
|
293
|
+
* return;
|
|
294
|
+
* }
|
|
295
|
+
* // No 3DS return — render the normal page.
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
298
|
+
maybeResumeFromUrl(opts?: {
|
|
299
|
+
/**
|
|
300
|
+
* URL to inspect (defaults to `window.location.href`). Pass an explicit
|
|
301
|
+
* URL when running outside the browser or when integrating with a
|
|
302
|
+
* router that hasn't navigated yet.
|
|
303
|
+
*/
|
|
304
|
+
url?: string;
|
|
305
|
+
/**
|
|
306
|
+
* Whether to clean the redirect query params from the address bar
|
|
307
|
+
* once the payment has been resolved. Defaults to `true`.
|
|
308
|
+
*/
|
|
309
|
+
cleanUrl?: boolean;
|
|
310
|
+
}): Promise<ProcessPaymentResult | null>;
|
|
311
|
+
/** Get current status of a payment. */
|
|
312
|
+
getPaymentStatus(paymentId: string): Promise<PaymentStatus>;
|
|
313
|
+
/**
|
|
314
|
+
* Poll a payment until it reaches a terminal status.
|
|
315
|
+
* Returns the final status or throws on timeout.
|
|
316
|
+
*/
|
|
317
|
+
pollPaymentStatus(paymentId: string, opts?: {
|
|
318
|
+
intervalMs?: number;
|
|
319
|
+
timeoutMs?: number;
|
|
320
|
+
}): Promise<PaymentStatus>;
|
|
321
|
+
/** Finalize a payment after a 3DS challenge completes. */
|
|
322
|
+
completeAfter3ds(paymentId: string): Promise<PaymentStatus>;
|
|
323
|
+
/** Tell the server this action has been seen / is being processed. */
|
|
324
|
+
markActionProcessed(paymentId: string): Promise<void>;
|
|
325
|
+
/**
|
|
326
|
+
* Route a payment action to the appropriate handler.
|
|
327
|
+
* Returns `requires_redirect` for browser-level redirects,
|
|
328
|
+
* or attempts 3DS inline and polls to completion.
|
|
329
|
+
*/
|
|
330
|
+
private handlePaymentAction;
|
|
331
|
+
/**
|
|
332
|
+
* Extract redirect info from actionData.
|
|
333
|
+
* Works for processor_auth (GET or POST), redirect, and any unknown type with a URL.
|
|
334
|
+
*/
|
|
335
|
+
private extractRedirect;
|
|
336
|
+
/**
|
|
337
|
+
* Run a 3DS challenge using @tagadapay/core-js.
|
|
338
|
+
* If core-js is not installed, falls back to redirect.
|
|
339
|
+
*/
|
|
340
|
+
private handleThreedsAuth;
|
|
341
|
+
/**
|
|
342
|
+
* Poll until the payment reaches a terminal status, then return a ProcessPaymentResult.
|
|
343
|
+
* Also handles new requireAction that may appear during polling.
|
|
344
|
+
*/
|
|
345
|
+
private pollUntilDone;
|
|
346
|
+
/**
|
|
347
|
+
* Read paymentSetupConfig from the Tagada routing injection.
|
|
348
|
+
* Only available when running on Tagada infra (not on external hosting like Vercel).
|
|
349
|
+
*/
|
|
350
|
+
private readInjectedStepConfig;
|
|
351
|
+
private loadCoreJs;
|
|
352
|
+
}
|
|
353
|
+
//# sourceMappingURL=payment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../../src/core/modules/payment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAEV,WAAW,EACX,kBAAkB,EAElB,cAAc,EACd,WAAW,EACX,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,aAAa;IAEtB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,wEAAwE;IACxE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBAJT,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,WAAW;IACzC,wEAAwE;IACvD,QAAQ,CAAC,EAAE,cAAc,YAAA;IAO5C;;;;;;;;;OASG;IACG,eAAe,CACnB,iBAAiB,EAAE,MAAM,EACzB,IAAI,CAAC,EAAE;QAAE,kBAAkB,CAAC,EAAE,kBAAkB,CAAA;KAAE,GACjD,OAAO,CAAC,kBAAkB,CAAC;IAuB9B;;;OAGG;IACG,iBAAiB,CACrB,iBAAiB,EAAE,MAAM,EACzB,IAAI,CAAC,EAAE;QAAE,kBAAkB,CAAC,EAAE,kBAAkB,CAAA;KAAE,GACjD,OAAO,CAA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