@tagadapay/headless-sdk 1.8.0-rc.0 → 1.8.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.js +71 -0
- package/dist/core/errors.d.ts +46 -0
- package/dist/core/errors.js +57 -0
- package/dist/core/helpers/autocomplete.d.ts +89 -0
- package/dist/core/helpers/autocomplete.js +186 -0
- package/dist/core/helpers/countries.d.ts +45 -0
- package/dist/core/helpers/countries.js +65 -0
- package/dist/core/helpers/currency.d.ts +26 -0
- package/dist/core/helpers/currency.js +72 -0
- package/dist/core/helpers/index.d.ts +5 -0
- package/dist/core/helpers/index.js +5 -0
- package/dist/core/helpers/iso3166.d.ts +28 -0
- package/dist/core/helpers/iso3166.js +84 -0
- package/dist/core/http.d.ts +27 -0
- package/dist/core/http.js +116 -0
- package/dist/core/index.d.ts +15 -0
- package/dist/core/index.js +13 -0
- package/dist/core/modules/catalog.d.ts +27 -0
- package/dist/core/modules/catalog.js +38 -0
- package/dist/core/modules/checkout.d.ts +268 -0
- package/dist/core/modules/checkout.js +470 -0
- package/dist/core/modules/customer.d.ts +33 -0
- package/dist/core/modules/customer.js +53 -0
- package/dist/core/modules/funnel.d.ts +38 -0
- package/dist/core/modules/funnel.js +138 -0
- package/dist/core/modules/offers.d.ts +137 -0
- package/dist/core/modules/offers.js +141 -0
- package/dist/core/modules/payment.d.ts +298 -0
- package/dist/core/modules/payment.js +701 -0
- package/dist/core/modules/rx.d.ts +162 -0
- package/dist/core/modules/rx.js +46 -0
- package/dist/core/types.d.ts +505 -0
- package/dist/core/types.js +5 -0
- package/dist/react/hooks/useCatalog.d.ts +25 -0
- package/dist/react/hooks/useCatalog.js +58 -0
- package/dist/react/hooks/useCheckout.d.ts +58 -0
- package/dist/react/hooks/useCheckout.js +177 -0
- package/dist/react/hooks/useCustomer.d.ts +28 -0
- package/dist/react/hooks/useCustomer.js +77 -0
- package/dist/react/hooks/useGoogleAutocomplete.d.ts +26 -0
- package/dist/react/hooks/useGoogleAutocomplete.js +70 -0
- package/dist/react/hooks/useISOData.d.ts +23 -0
- package/dist/react/hooks/useISOData.js +63 -0
- package/dist/react/hooks/useOffers.d.ts +134 -0
- package/dist/react/hooks/useOffers.js +171 -0
- package/dist/react/hooks/usePayment.d.ts +108 -0
- package/dist/react/hooks/usePayment.js +233 -0
- package/dist/react/hooks/useRx.d.ts +64 -0
- package/dist/react/hooks/useRx.js +145 -0
- package/dist/react/index.d.ts +22 -0
- package/dist/react/index.js +12 -0
- package/dist/react/internal/redirectGuard.d.ts +9 -0
- package/dist/react/internal/redirectGuard.js +25 -0
- package/dist/react/provider.d.ts +31 -0
- package/dist/react/provider.js +32 -0
- package/dist/stripe/StripeExpressButton.d.ts +30 -0
- package/dist/stripe/StripeExpressButton.js +32 -0
- package/dist/stripe/StripeExpressCheckout.d.ts +98 -0
- package/dist/stripe/StripeExpressCheckout.js +198 -0
- package/dist/stripe/index.d.ts +8 -0
- package/dist/stripe/index.js +15 -0
- package/dist/stripe/useStripeExpress.d.ts +54 -0
- package/dist/stripe/useStripeExpress.js +126 -0
- package/package.json +2 -3
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js';
|
|
2
|
+
/**
|
|
3
|
+
* Tagada Rx — storefront module.
|
|
4
|
+
*
|
|
5
|
+
* Drives the post-checkout clinical case flow from the browser:
|
|
6
|
+
* 1. Ask the API whether a product needs an Rx case.
|
|
7
|
+
* 2. After the order is paid, submit the intake (patient + answers)
|
|
8
|
+
* with the `(orderId, checkoutToken)` ownership proof.
|
|
9
|
+
* 3. Poll the case status from the thank-you page.
|
|
10
|
+
*
|
|
11
|
+
* PHI handling: the `patient` and `intakeAnswers` payloads are sent
|
|
12
|
+
* straight to the Tagada API which forwards them to the clinical
|
|
13
|
+
* network (e.g. MDI). Tagada NEVER persists PHI in its database.
|
|
14
|
+
*
|
|
15
|
+
* Auth model: there is no API key. Each route authorizes per-resource
|
|
16
|
+
* (productId is public; case routes require the checkoutToken the
|
|
17
|
+
* storefront already received when it bootstrapped the checkout).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const { required } = await tagada.rx.isRequiredForProduct(productId);
|
|
22
|
+
* if (required) {
|
|
23
|
+
* const intake = await collectIntakeFromUser();
|
|
24
|
+
* const res = await tagada.rx.submitCase({
|
|
25
|
+
* orderId, checkoutToken, productId,
|
|
26
|
+
* patient, intakeAnswers: intake,
|
|
27
|
+
* });
|
|
28
|
+
* router.push(`/thank-you?rxCase=${res.rxCaseId}`);
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export type RxCaseStatus = 'requested' | 'submitted' | 'in_review' | 'approved' | 'shipped' | 'delivered' | 'declined' | 'cancelled' | 'error';
|
|
33
|
+
export interface RxRequiredForProduct {
|
|
34
|
+
required: boolean;
|
|
35
|
+
clinicalNetworkId: string | null;
|
|
36
|
+
externalOfferingId: string | null;
|
|
37
|
+
requiresLabs: boolean;
|
|
38
|
+
requiresIdVerification: boolean;
|
|
39
|
+
isDeaControlled: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface RxStorefrontPatient {
|
|
42
|
+
firstName: string;
|
|
43
|
+
lastName: string;
|
|
44
|
+
email: string;
|
|
45
|
+
phone?: string | null;
|
|
46
|
+
/** ISO date YYYY-MM-DD. */
|
|
47
|
+
dateOfBirth: string;
|
|
48
|
+
sexAtBirth: 'male' | 'female' | 'unspecified';
|
|
49
|
+
address: {
|
|
50
|
+
line1: string;
|
|
51
|
+
line2?: string;
|
|
52
|
+
city: string;
|
|
53
|
+
state: string;
|
|
54
|
+
zip: string;
|
|
55
|
+
/** ISO 3166-1 alpha-2 country code. */
|
|
56
|
+
country: string;
|
|
57
|
+
};
|
|
58
|
+
/** Patient-level clinical fields (MDI Full API / Judd). */
|
|
59
|
+
weight?: number | string;
|
|
60
|
+
height?: number | string;
|
|
61
|
+
allergies?: string;
|
|
62
|
+
pregnancy?: boolean | string;
|
|
63
|
+
currentMedications?: string;
|
|
64
|
+
medicalConditions?: string;
|
|
65
|
+
specialNecessities?: string;
|
|
66
|
+
driverLicenseId?: string;
|
|
67
|
+
introVideoId?: string;
|
|
68
|
+
}
|
|
69
|
+
export interface RxIntakeAnswer {
|
|
70
|
+
questionId: string;
|
|
71
|
+
value: string | number | boolean | string[];
|
|
72
|
+
comment?: string;
|
|
73
|
+
/** Exact question text shown to the patient (MDI case_questions.question). */
|
|
74
|
+
question?: string;
|
|
75
|
+
/** MDI answer type: string | number | boolean. */
|
|
76
|
+
type?: string;
|
|
77
|
+
important?: boolean;
|
|
78
|
+
isCritical?: boolean;
|
|
79
|
+
displayInPdf?: boolean;
|
|
80
|
+
description?: string;
|
|
81
|
+
label?: string;
|
|
82
|
+
metadata?: string;
|
|
83
|
+
/** Options presented for MCQ questions. */
|
|
84
|
+
displayedOptions?: string[];
|
|
85
|
+
}
|
|
86
|
+
export interface RxClinicalQuestion {
|
|
87
|
+
externalQuestionId: string;
|
|
88
|
+
title: string;
|
|
89
|
+
description: string | null;
|
|
90
|
+
placeholder: string | null;
|
|
91
|
+
type: string;
|
|
92
|
+
required: boolean;
|
|
93
|
+
order: number;
|
|
94
|
+
options: {
|
|
95
|
+
value: string;
|
|
96
|
+
label: string;
|
|
97
|
+
}[];
|
|
98
|
+
}
|
|
99
|
+
export interface RxQuestionsForProduct {
|
|
100
|
+
required: boolean;
|
|
101
|
+
externalQuestionnaireId: string | null;
|
|
102
|
+
questions: RxClinicalQuestion[];
|
|
103
|
+
}
|
|
104
|
+
export interface RxSubmitCaseInput {
|
|
105
|
+
orderId: string;
|
|
106
|
+
checkoutToken: string;
|
|
107
|
+
productId: string;
|
|
108
|
+
patient: RxStorefrontPatient;
|
|
109
|
+
intakeAnswers: RxIntakeAnswer[];
|
|
110
|
+
preferredPharmacyId?: string;
|
|
111
|
+
}
|
|
112
|
+
export interface RxSubmitCaseResult {
|
|
113
|
+
rxCaseId: string;
|
|
114
|
+
externalCaseId: string;
|
|
115
|
+
status: 'submitted' | 'error';
|
|
116
|
+
accrualAmountMinor: number;
|
|
117
|
+
accrualCurrency: string;
|
|
118
|
+
}
|
|
119
|
+
export interface RxCaseSummary {
|
|
120
|
+
id: string;
|
|
121
|
+
status: RxCaseStatus;
|
|
122
|
+
externalCaseId: string | null;
|
|
123
|
+
lastShipmentShippedAt: string | null;
|
|
124
|
+
createdAt: string;
|
|
125
|
+
}
|
|
126
|
+
export declare class RxModule {
|
|
127
|
+
private readonly http;
|
|
128
|
+
constructor(http: HttpClient);
|
|
129
|
+
/**
|
|
130
|
+
* Check whether a product requires an Rx case. Storefronts call this
|
|
131
|
+
* before rendering the intake form so they only ask the patient
|
|
132
|
+
* questions when really necessary.
|
|
133
|
+
*
|
|
134
|
+
* Read-only / public — does not require any ownership proof.
|
|
135
|
+
*/
|
|
136
|
+
isRequiredForProduct(productId: string, opts?: {
|
|
137
|
+
clinicalNetworkId?: string;
|
|
138
|
+
}): Promise<RxRequiredForProduct>;
|
|
139
|
+
/**
|
|
140
|
+
* Look up the Rx cases attached to an order. Storefronts poll this
|
|
141
|
+
* on the thank-you page to render "Your prescription is being
|
|
142
|
+
* reviewed" → "Shipped" transitions.
|
|
143
|
+
*/
|
|
144
|
+
getCasesForOrder(input: {
|
|
145
|
+
orderId: string;
|
|
146
|
+
checkoutToken: string;
|
|
147
|
+
}): Promise<{
|
|
148
|
+
cases: RxCaseSummary[];
|
|
149
|
+
}>;
|
|
150
|
+
/**
|
|
151
|
+
* Submit a fresh clinical case for a freshly-paid order. PHI is
|
|
152
|
+
* forwarded to the clinical network and never persisted on
|
|
153
|
+
* Tagada-side rows.
|
|
154
|
+
*/
|
|
155
|
+
submitCase(input: RxSubmitCaseInput): Promise<RxSubmitCaseResult>;
|
|
156
|
+
/**
|
|
157
|
+
* Fetch the network-authored intake questions for a product.
|
|
158
|
+
* Empty `questions` means the storefront should use its local quiz.
|
|
159
|
+
*/
|
|
160
|
+
getQuestionsForProduct(productId: string): Promise<RxQuestionsForProduct>;
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=rx.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export class RxModule {
|
|
2
|
+
constructor(http) {
|
|
3
|
+
this.http = http;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Check whether a product requires an Rx case. Storefronts call this
|
|
7
|
+
* before rendering the intake form so they only ask the patient
|
|
8
|
+
* questions when really necessary.
|
|
9
|
+
*
|
|
10
|
+
* Read-only / public — does not require any ownership proof.
|
|
11
|
+
*/
|
|
12
|
+
async isRequiredForProduct(productId, opts) {
|
|
13
|
+
return this.http.get('/api/public/v1/rx/required-for-product', {
|
|
14
|
+
params: {
|
|
15
|
+
productId,
|
|
16
|
+
clinicalNetworkId: opts?.clinicalNetworkId,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Look up the Rx cases attached to an order. Storefronts poll this
|
|
22
|
+
* on the thank-you page to render "Your prescription is being
|
|
23
|
+
* reviewed" → "Shipped" transitions.
|
|
24
|
+
*/
|
|
25
|
+
async getCasesForOrder(input) {
|
|
26
|
+
return this.http.post('/api/public/v1/rx/cases/lookup', input);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Submit a fresh clinical case for a freshly-paid order. PHI is
|
|
30
|
+
* forwarded to the clinical network and never persisted on
|
|
31
|
+
* Tagada-side rows.
|
|
32
|
+
*/
|
|
33
|
+
async submitCase(input) {
|
|
34
|
+
return this.http.post('/api/public/v1/rx/cases/submit', input);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Fetch the network-authored intake questions for a product.
|
|
38
|
+
* Empty `questions` means the storefront should use its local quiz.
|
|
39
|
+
*/
|
|
40
|
+
async getQuestionsForProduct(productId) {
|
|
41
|
+
return this.http.get('/api/public/v1/rx/questions-for-product', {
|
|
42
|
+
params: { productId },
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=rx.js.map
|
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
export type Environment = 'production' | 'development' | 'local';
|
|
2
|
+
export interface HeadlessConfig {
|
|
3
|
+
/** Your TagadaPay store ID (e.g. "store_abc123"). */
|
|
4
|
+
storeId: string;
|
|
5
|
+
/**
|
|
6
|
+
* Your TagadaPay account ID (e.g. "acc_abc123"). Required for
|
|
7
|
+
* `funnel.navigate()` — the CMS session + funnel-init endpoints reject calls
|
|
8
|
+
* without it. Optional for pure checkout / payment flows.
|
|
9
|
+
*/
|
|
10
|
+
accountId?: string;
|
|
11
|
+
/** Environment. Defaults to "production". */
|
|
12
|
+
environment?: Environment;
|
|
13
|
+
/** Public API key for authenticated requests. Optional -- many flows use checkout tokens instead. */
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
/** Override the base API URL. Auto-resolved from environment if omitted. */
|
|
16
|
+
baseUrl?: string;
|
|
17
|
+
/** Request timeout in ms. Default 30000. */
|
|
18
|
+
timeout?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface HttpRequestOptions {
|
|
21
|
+
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
22
|
+
body?: unknown;
|
|
23
|
+
headers?: Record<string, string>;
|
|
24
|
+
params?: Record<string, string | number | boolean | undefined>;
|
|
25
|
+
/** Override the auth token for this single request. */
|
|
26
|
+
token?: string;
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
}
|
|
29
|
+
export interface LineItem {
|
|
30
|
+
variantId: string;
|
|
31
|
+
priceId?: string;
|
|
32
|
+
quantity: number;
|
|
33
|
+
}
|
|
34
|
+
export interface CheckoutSession {
|
|
35
|
+
id: string;
|
|
36
|
+
storeId: string;
|
|
37
|
+
checkoutToken: string;
|
|
38
|
+
currency: string;
|
|
39
|
+
items: CheckoutLineItem[];
|
|
40
|
+
totals: CheckoutTotals;
|
|
41
|
+
customer?: CheckoutCustomer;
|
|
42
|
+
shippingAddress?: Address;
|
|
43
|
+
billingAddress?: Address;
|
|
44
|
+
/**
|
|
45
|
+
* ID of the shipping rate currently selected on the session, if any.
|
|
46
|
+
* Set by `selectShippingRate()` and persisted on the server. Use this
|
|
47
|
+
* to pre-select the radio button in your shipping rate UI after a
|
|
48
|
+
* page refresh — without it the customer has to re-pick the rate
|
|
49
|
+
* every time the form remounts.
|
|
50
|
+
*/
|
|
51
|
+
selectedShippingRateId?: string | null;
|
|
52
|
+
promotionCode?: string;
|
|
53
|
+
metadata?: Record<string, unknown>;
|
|
54
|
+
}
|
|
55
|
+
export interface CheckoutLineItem {
|
|
56
|
+
id: string;
|
|
57
|
+
variantId: string;
|
|
58
|
+
priceId?: string;
|
|
59
|
+
productName: string;
|
|
60
|
+
variantName: string;
|
|
61
|
+
quantity: number;
|
|
62
|
+
unitAmount: number;
|
|
63
|
+
totalAmount: number;
|
|
64
|
+
currency: string;
|
|
65
|
+
imageUrl?: string;
|
|
66
|
+
recurring?: {
|
|
67
|
+
interval: string;
|
|
68
|
+
intervalCount: number;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export interface CheckoutTotals {
|
|
72
|
+
subtotal: number;
|
|
73
|
+
discount: number;
|
|
74
|
+
shipping: number;
|
|
75
|
+
tax: number;
|
|
76
|
+
total: number;
|
|
77
|
+
currency: string;
|
|
78
|
+
}
|
|
79
|
+
export interface CheckoutCustomer {
|
|
80
|
+
id?: string;
|
|
81
|
+
email?: string;
|
|
82
|
+
firstName?: string;
|
|
83
|
+
lastName?: string;
|
|
84
|
+
phone?: string;
|
|
85
|
+
}
|
|
86
|
+
export interface Address {
|
|
87
|
+
firstName?: string;
|
|
88
|
+
lastName?: string;
|
|
89
|
+
line1?: string;
|
|
90
|
+
line2?: string;
|
|
91
|
+
city?: string;
|
|
92
|
+
state?: string;
|
|
93
|
+
postalCode?: string;
|
|
94
|
+
country?: string;
|
|
95
|
+
phone?: string;
|
|
96
|
+
}
|
|
97
|
+
export interface ShippingRate {
|
|
98
|
+
id: string;
|
|
99
|
+
name: string;
|
|
100
|
+
description?: string;
|
|
101
|
+
amount: number;
|
|
102
|
+
currency: string;
|
|
103
|
+
estimatedDays?: number;
|
|
104
|
+
}
|
|
105
|
+
export interface PaymentMethodConfig {
|
|
106
|
+
enabled: boolean;
|
|
107
|
+
method: string;
|
|
108
|
+
provider?: string;
|
|
109
|
+
type?: string;
|
|
110
|
+
label?: string;
|
|
111
|
+
logoUrl?: string;
|
|
112
|
+
description?: string;
|
|
113
|
+
express?: boolean;
|
|
114
|
+
paymentFlowId?: string;
|
|
115
|
+
processorId?: string;
|
|
116
|
+
integrationId?: string;
|
|
117
|
+
publishableKey?: string;
|
|
118
|
+
/** Map of express method keys to their enabled state (e.g. apple_pay, google_pay). */
|
|
119
|
+
methods?: Record<string, {
|
|
120
|
+
enabled: boolean;
|
|
121
|
+
}>;
|
|
122
|
+
metadata?: Record<string, unknown>;
|
|
123
|
+
}
|
|
124
|
+
export type PaymentSetupConfig = Record<string, PaymentMethodConfig>;
|
|
125
|
+
export interface ExpressMethod {
|
|
126
|
+
type: string;
|
|
127
|
+
available: boolean;
|
|
128
|
+
processorId?: string;
|
|
129
|
+
publishableKey?: string;
|
|
130
|
+
metadata?: Record<string, unknown>;
|
|
131
|
+
}
|
|
132
|
+
export interface ExpressMethods {
|
|
133
|
+
applePay?: ExpressMethod;
|
|
134
|
+
googlePay?: ExpressMethod;
|
|
135
|
+
paypal?: ExpressMethod;
|
|
136
|
+
klarna?: ExpressMethod;
|
|
137
|
+
link?: ExpressMethod;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Options for initializing the Stripe Express Checkout Element.
|
|
141
|
+
* Used by `StripeExpressCheckout` (vanilla) and `useStripeExpress` (React).
|
|
142
|
+
*/
|
|
143
|
+
export interface StripeExpressOptions {
|
|
144
|
+
/** Stripe publishable key (pk_xxx). Obtained from `getExpressMethods()`. */
|
|
145
|
+
publishableKey: string;
|
|
146
|
+
/** Processor ID for the Stripe express integration. */
|
|
147
|
+
processorId: string;
|
|
148
|
+
/** Which express methods to show: 'apple_pay', 'google_pay', 'paypal', 'link', 'klarna_express'. */
|
|
149
|
+
enabledMethods?: string[];
|
|
150
|
+
/** Button height in pixels. Default: 48. */
|
|
151
|
+
buttonHeight?: number;
|
|
152
|
+
/** Button type for Apple Pay / Google Pay. Default: 'buy'. */
|
|
153
|
+
buttonType?: 'buy' | 'plain' | 'book' | 'donate' | 'checkout';
|
|
154
|
+
/** Require email from the wallet. Default: true. */
|
|
155
|
+
emailRequired?: boolean;
|
|
156
|
+
/** Require billing address from the wallet. Default: true. */
|
|
157
|
+
billingAddressRequired?: boolean;
|
|
158
|
+
}
|
|
159
|
+
export interface StoreConfig {
|
|
160
|
+
threedsEnabled: boolean;
|
|
161
|
+
paymentFlowId?: string;
|
|
162
|
+
[key: string]: unknown;
|
|
163
|
+
}
|
|
164
|
+
export interface PayResult {
|
|
165
|
+
payment: {
|
|
166
|
+
id: string;
|
|
167
|
+
amount: number;
|
|
168
|
+
currency: string;
|
|
169
|
+
status: 'succeeded' | 'pending' | 'failed' | 'declined' | 'requires_action';
|
|
170
|
+
requireAction?: 'none' | 'threeds_auth' | 'redirect';
|
|
171
|
+
requireActionData?: {
|
|
172
|
+
type: string;
|
|
173
|
+
processed?: boolean;
|
|
174
|
+
redirectUrl?: string;
|
|
175
|
+
metadata?: {
|
|
176
|
+
type?: string;
|
|
177
|
+
redirect?: {
|
|
178
|
+
redirectUrl: string;
|
|
179
|
+
returnUrl: string;
|
|
180
|
+
method?: string;
|
|
181
|
+
data?: Record<string, string>;
|
|
182
|
+
};
|
|
183
|
+
threedsSession?: {
|
|
184
|
+
externalSessionId: string;
|
|
185
|
+
acsChallengeUrl: string;
|
|
186
|
+
acsTransID: string;
|
|
187
|
+
messageVersion: string;
|
|
188
|
+
};
|
|
189
|
+
[key: string]: unknown;
|
|
190
|
+
};
|
|
191
|
+
resumeToken?: string;
|
|
192
|
+
message?: string;
|
|
193
|
+
errorCode?: string;
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
order?: {
|
|
197
|
+
id: string;
|
|
198
|
+
checkoutSessionId?: string;
|
|
199
|
+
};
|
|
200
|
+
redirectUrl?: string;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Options for `processPayment()`. Same as `PayOptions` with an optional
|
|
204
|
+
* `returnUrl` that the processor will redirect back to after 3DS / auth.
|
|
205
|
+
* If omitted, the SDK uses `window.location.href` (browser) or throws (Node).
|
|
206
|
+
*/
|
|
207
|
+
export interface ProcessPaymentOptions extends PayOptions {
|
|
208
|
+
/**
|
|
209
|
+
* URL the bank / PSP redirects back to after 3DS or processor auth.
|
|
210
|
+
* The URL will receive query params: `paymentAction`, `paymentActionStatus`, `paymentId`.
|
|
211
|
+
* Default: current page URL (browser only).
|
|
212
|
+
*/
|
|
213
|
+
returnUrl?: string;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Discriminated union returned by `processPayment()`.
|
|
217
|
+
*
|
|
218
|
+
* - `succeeded` — payment is confirmed. Show a success screen.
|
|
219
|
+
* - `requires_redirect` — user must be redirected to a URL (3DS, processor auth, APM).
|
|
220
|
+
* In React, `usePayment().processPayment()` handles this automatically.
|
|
221
|
+
* - `failed` — payment was declined or errored.
|
|
222
|
+
* - `pending` — payment is still processing (rare edge case if polling timed out).
|
|
223
|
+
*/
|
|
224
|
+
export type ProcessPaymentResult = {
|
|
225
|
+
status: 'succeeded';
|
|
226
|
+
payment: PayResult['payment'];
|
|
227
|
+
order?: PayResult['order'];
|
|
228
|
+
} | {
|
|
229
|
+
status: 'requires_redirect';
|
|
230
|
+
redirectUrl: string;
|
|
231
|
+
method?: 'GET' | 'POST';
|
|
232
|
+
postData?: Record<string, string>;
|
|
233
|
+
paymentId: string;
|
|
234
|
+
} | {
|
|
235
|
+
status: 'failed';
|
|
236
|
+
error: string;
|
|
237
|
+
payment?: PayResult['payment'];
|
|
238
|
+
} | {
|
|
239
|
+
status: 'pending';
|
|
240
|
+
paymentId: string;
|
|
241
|
+
};
|
|
242
|
+
export interface PayOptions {
|
|
243
|
+
checkoutSessionId: string;
|
|
244
|
+
/** Base64-encoded TagadaToken from tokenizeCard(). Instrument is auto-created. */
|
|
245
|
+
tagadaToken?: string;
|
|
246
|
+
/** Existing payment instrument ID (skip instrument creation). */
|
|
247
|
+
paymentInstrumentId?: string;
|
|
248
|
+
paymentFlowId?: string;
|
|
249
|
+
threedsSessionId?: string;
|
|
250
|
+
processorId?: string;
|
|
251
|
+
paymentMethod?: string;
|
|
252
|
+
isExpress?: boolean;
|
|
253
|
+
metadata?: Record<string, unknown>;
|
|
254
|
+
/**
|
|
255
|
+
* URL the bank / PSP redirects back to after 3DS or processor auth.
|
|
256
|
+
* If omitted during `processPayment()`, defaults to `window.location.href`.
|
|
257
|
+
*/
|
|
258
|
+
returnUrl?: string;
|
|
259
|
+
}
|
|
260
|
+
export interface PayDirectOptions {
|
|
261
|
+
checkoutSessionId: string;
|
|
262
|
+
paymentInstrumentId?: string;
|
|
263
|
+
paymentFlowId?: string;
|
|
264
|
+
processorId?: string;
|
|
265
|
+
paymentMethod?: string;
|
|
266
|
+
isExpress?: boolean;
|
|
267
|
+
threedsSessionId?: string;
|
|
268
|
+
}
|
|
269
|
+
export interface CreateInstrumentOptions {
|
|
270
|
+
tagadaToken: string;
|
|
271
|
+
storeId: string;
|
|
272
|
+
customerData?: {
|
|
273
|
+
email?: string;
|
|
274
|
+
firstName?: string;
|
|
275
|
+
lastName?: string;
|
|
276
|
+
};
|
|
277
|
+
customerId?: string;
|
|
278
|
+
}
|
|
279
|
+
export interface PaymentInstrument {
|
|
280
|
+
id: string;
|
|
281
|
+
type: string;
|
|
282
|
+
customerId: string;
|
|
283
|
+
card?: {
|
|
284
|
+
last4: string;
|
|
285
|
+
brand: string;
|
|
286
|
+
expMonth: number;
|
|
287
|
+
expYear: number;
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
export interface ThreedsSession {
|
|
291
|
+
id: string;
|
|
292
|
+
externalSessionId: string;
|
|
293
|
+
provider: string;
|
|
294
|
+
status: string;
|
|
295
|
+
paymentInstrumentId: string;
|
|
296
|
+
}
|
|
297
|
+
export interface PaymentStatus {
|
|
298
|
+
id: string;
|
|
299
|
+
amount: number;
|
|
300
|
+
currency: string;
|
|
301
|
+
status: 'succeeded' | 'pending' | 'failed' | 'declined';
|
|
302
|
+
subStatus?: string;
|
|
303
|
+
requireAction?: string;
|
|
304
|
+
requireActionData?: PayResult['payment']['requireActionData'];
|
|
305
|
+
order?: {
|
|
306
|
+
id: string;
|
|
307
|
+
checkoutSessionId?: string;
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
export interface Offer {
|
|
311
|
+
id: string;
|
|
312
|
+
type: 'upsell' | 'downsell' | 'orderbump';
|
|
313
|
+
title: string;
|
|
314
|
+
titleTrans?: Record<string, string>;
|
|
315
|
+
description?: string;
|
|
316
|
+
lineItems: OfferLineItem[];
|
|
317
|
+
pricing?: {
|
|
318
|
+
amount: number;
|
|
319
|
+
currency: string;
|
|
320
|
+
compareAtAmount?: number;
|
|
321
|
+
};
|
|
322
|
+
metadata?: Record<string, unknown>;
|
|
323
|
+
}
|
|
324
|
+
export interface OfferLineItem {
|
|
325
|
+
id: string;
|
|
326
|
+
priceId: string;
|
|
327
|
+
productId?: string;
|
|
328
|
+
variantId?: string;
|
|
329
|
+
quantity: number;
|
|
330
|
+
productName?: string;
|
|
331
|
+
variantName?: string;
|
|
332
|
+
imageUrl?: string;
|
|
333
|
+
unitAmount?: number;
|
|
334
|
+
currency?: string;
|
|
335
|
+
}
|
|
336
|
+
export interface OfferPreview {
|
|
337
|
+
items: OfferPreviewItem[];
|
|
338
|
+
totalAmount: number;
|
|
339
|
+
totalAdjustedAmount: number;
|
|
340
|
+
currency: string;
|
|
341
|
+
}
|
|
342
|
+
export interface OfferPreviewItem {
|
|
343
|
+
id: string;
|
|
344
|
+
productId: string;
|
|
345
|
+
productName: string;
|
|
346
|
+
variantId: string;
|
|
347
|
+
variantName: string;
|
|
348
|
+
imageUrl?: string;
|
|
349
|
+
quantity: number;
|
|
350
|
+
unitAmount: number;
|
|
351
|
+
currency: string;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Response shape from `POST /api/v1/offers/:offerId/pay-preview`.
|
|
355
|
+
*
|
|
356
|
+
* The server pipeline runs preview → transform-to-checkout → prepare-order →
|
|
357
|
+
* payOrder, then returns each intermediate object so the client can either:
|
|
358
|
+
* - inspect `payment.status` to know if the upsell charge succeeded,
|
|
359
|
+
* - read `order.id` to chain to a follow-up upsell, or
|
|
360
|
+
* - read `payment.requireAction` to handle a 3DS challenge inline.
|
|
361
|
+
*
|
|
362
|
+
* Mirrors the structure of `PayResult` (`{ payment, order }`) plus the
|
|
363
|
+
* `preview` and `checkout` artifacts. Lifecycle helpers like
|
|
364
|
+
* `processPayment()` are NOT used internally by `pay-preview` — if the
|
|
365
|
+
* upsell card requires 3DS, callers should read `payment.requireActionData`
|
|
366
|
+
* and either redirect or fall back to a customer-present retry.
|
|
367
|
+
*/
|
|
368
|
+
export interface OfferPayResult {
|
|
369
|
+
/** Pricing breakdown that was previewed before charging. */
|
|
370
|
+
preview: OfferPreview;
|
|
371
|
+
/** Newly-created upsell checkout session (linked to `mainOrderId`). */
|
|
372
|
+
checkout: {
|
|
373
|
+
checkoutUrl: string;
|
|
374
|
+
customerId?: string;
|
|
375
|
+
checkoutSessionId?: string;
|
|
376
|
+
checkoutToken?: string;
|
|
377
|
+
};
|
|
378
|
+
/**
|
|
379
|
+
* Payment outcome from the upsell charge.
|
|
380
|
+
* Same shape as `PayResult['payment']` returned by `pay()`.
|
|
381
|
+
*/
|
|
382
|
+
payment: PayResult['payment'];
|
|
383
|
+
/** Newly-created upsell order (`order.id` chains to the next upsell as `mainOrderId`). */
|
|
384
|
+
order?: {
|
|
385
|
+
id: string;
|
|
386
|
+
status?: string;
|
|
387
|
+
checkoutSessionId?: string;
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
export interface CatalogProduct {
|
|
391
|
+
id: string;
|
|
392
|
+
name: string;
|
|
393
|
+
description?: string;
|
|
394
|
+
active: boolean;
|
|
395
|
+
variants: CatalogVariant[];
|
|
396
|
+
}
|
|
397
|
+
export interface CatalogVariant {
|
|
398
|
+
id: string;
|
|
399
|
+
productId: string;
|
|
400
|
+
name: string;
|
|
401
|
+
description?: string;
|
|
402
|
+
sku?: string;
|
|
403
|
+
price?: number;
|
|
404
|
+
currency?: string;
|
|
405
|
+
compareAtPrice?: number;
|
|
406
|
+
imageUrl?: string;
|
|
407
|
+
active: boolean;
|
|
408
|
+
inStock: boolean;
|
|
409
|
+
prices: CatalogPrice[];
|
|
410
|
+
}
|
|
411
|
+
export interface CurrencyOption {
|
|
412
|
+
amount: number;
|
|
413
|
+
compareAtAmount?: number;
|
|
414
|
+
}
|
|
415
|
+
export interface CatalogPrice {
|
|
416
|
+
id: string;
|
|
417
|
+
variantId?: string;
|
|
418
|
+
default: boolean;
|
|
419
|
+
currencyOptions: Record<string, CurrencyOption>;
|
|
420
|
+
recurring: boolean;
|
|
421
|
+
interval?: string;
|
|
422
|
+
intervalCount?: number;
|
|
423
|
+
}
|
|
424
|
+
export interface Customer {
|
|
425
|
+
id: string;
|
|
426
|
+
email: string;
|
|
427
|
+
firstName?: string;
|
|
428
|
+
lastName?: string;
|
|
429
|
+
phone?: string;
|
|
430
|
+
tags?: string[];
|
|
431
|
+
metadata?: Record<string, unknown>;
|
|
432
|
+
createdAt?: string;
|
|
433
|
+
}
|
|
434
|
+
export interface Order {
|
|
435
|
+
id: string;
|
|
436
|
+
storeId: string;
|
|
437
|
+
customerId: string;
|
|
438
|
+
amount: number;
|
|
439
|
+
currency: string;
|
|
440
|
+
status: string;
|
|
441
|
+
items: OrderItem[];
|
|
442
|
+
createdAt: string;
|
|
443
|
+
}
|
|
444
|
+
export interface OrderItem {
|
|
445
|
+
id: string;
|
|
446
|
+
productName: string;
|
|
447
|
+
variantName: string;
|
|
448
|
+
quantity: number;
|
|
449
|
+
unitAmount: number;
|
|
450
|
+
totalAmount: number;
|
|
451
|
+
}
|
|
452
|
+
export interface Subscription {
|
|
453
|
+
id: string;
|
|
454
|
+
customerId: string;
|
|
455
|
+
storeId: string;
|
|
456
|
+
status: 'trialing' | 'active' | 'past_due' | 'paused' | 'canceled';
|
|
457
|
+
priceId: string;
|
|
458
|
+
currency: string;
|
|
459
|
+
amount: number;
|
|
460
|
+
interval: string;
|
|
461
|
+
intervalCount: number;
|
|
462
|
+
currentPeriodStart: string;
|
|
463
|
+
currentPeriodEnd: string;
|
|
464
|
+
cancelAtPeriodEnd: boolean;
|
|
465
|
+
}
|
|
466
|
+
export interface FunnelNavigateInput {
|
|
467
|
+
/** Funnel ID to enter (e.g. "fnlv2_..."). */
|
|
468
|
+
funnelId: string;
|
|
469
|
+
/**
|
|
470
|
+
* Funnel step to land on. Used for both `entryStepId` and `funnelStepId`,
|
|
471
|
+
* matching the WooCommerce plugin behaviour.
|
|
472
|
+
*/
|
|
473
|
+
stepId: string;
|
|
474
|
+
/** Where the funnel should send the shopper back to after checkout. */
|
|
475
|
+
returnUrl?: string;
|
|
476
|
+
/**
|
|
477
|
+
* Customer overrides. Defaults are sourced from the currently-loaded
|
|
478
|
+
* `CheckoutSession` (`session.customer.email`, `session.currency`).
|
|
479
|
+
*/
|
|
480
|
+
customer?: {
|
|
481
|
+
email?: string;
|
|
482
|
+
currency?: string;
|
|
483
|
+
locale?: string;
|
|
484
|
+
};
|
|
485
|
+
/**
|
|
486
|
+
* Discount codes to apply. Defaults to the session's `promotionCode` if set.
|
|
487
|
+
*/
|
|
488
|
+
discountCodes?: string[];
|
|
489
|
+
/** Arbitrary metadata forwarded to the funnel-navigate event. */
|
|
490
|
+
metadata?: Record<string, unknown>;
|
|
491
|
+
/**
|
|
492
|
+
* Override the page URL recorded by the funnel. Defaults to
|
|
493
|
+
* `globalThis.location?.href` when running in a browser.
|
|
494
|
+
*/
|
|
495
|
+
currentUrl?: string;
|
|
496
|
+
/** Override `accountId` per-call. Falls back to `HeadlessConfig.accountId`. */
|
|
497
|
+
accountId?: string;
|
|
498
|
+
}
|
|
499
|
+
export interface FunnelNavigateResult {
|
|
500
|
+
/** Fully-qualified URL the caller should redirect the shopper to. */
|
|
501
|
+
url: string;
|
|
502
|
+
/** Funnel session id (`context.sessionId` from `/funnel/initialize`). */
|
|
503
|
+
funnelSessionId: string;
|
|
504
|
+
}
|
|
505
|
+
//# sourceMappingURL=types.d.ts.map
|