@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,470 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages checkout sessions — load, update cart, apply promo codes, handle shipping.
|
|
3
|
+
*
|
|
4
|
+
* Works for both **shipped** and **digital** products:
|
|
5
|
+
*
|
|
6
|
+
* **Shipped products** (physical goods):
|
|
7
|
+
* ```
|
|
8
|
+
* updateCustomer(id, { email, firstName, lastName })
|
|
9
|
+
* updateAddress(id, { shippingAddress: { line1, city, ... } })
|
|
10
|
+
* getShippingRates(id)
|
|
11
|
+
* selectShippingRate(id, rateId)
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* **Digital products** (no shipping needed):
|
|
15
|
+
* ```
|
|
16
|
+
* updateCustomer(id, { email, firstName, lastName })
|
|
17
|
+
* updateAddress(id, { billingAddress: { line1, city, country } })
|
|
18
|
+
* // Skip shipping rates — go straight to payment
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export class CheckoutModule {
|
|
22
|
+
constructor(http, storeId, onTokenChange) {
|
|
23
|
+
this.http = http;
|
|
24
|
+
this.storeId = storeId;
|
|
25
|
+
this.onTokenChange = onTokenChange;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns the most recently loaded `CheckoutSession`, if any.
|
|
29
|
+
*
|
|
30
|
+
* Populated by `loadSession()`. Returns `undefined` if the SDK has not
|
|
31
|
+
* loaded a session yet. Used by `funnel.navigate()` to source the cart.
|
|
32
|
+
*/
|
|
33
|
+
getCurrentSession() {
|
|
34
|
+
return this._currentSession;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Load an existing checkout session by its checkout token.
|
|
38
|
+
*
|
|
39
|
+
* @param checkoutToken The checkout token (from URL param `checkoutToken`).
|
|
40
|
+
* @param sessionToken The JWT session token (from URL param `token`). Required for auth.
|
|
41
|
+
* @param opts.currency Optional presentment currency override (e.g. 'EUR').
|
|
42
|
+
* Only applied when the session has no currency set yet (first load).
|
|
43
|
+
* Once set, currency is locked to the session and this param is ignored.
|
|
44
|
+
*
|
|
45
|
+
* Both `checkoutToken` and `sessionToken` come from the redirect URL returned by `createSession()`.
|
|
46
|
+
* Example URL: `/checkout?checkoutToken=abc123&token=eyJ...`
|
|
47
|
+
*/
|
|
48
|
+
async loadSession(checkoutToken, sessionToken, opts) {
|
|
49
|
+
if (sessionToken) {
|
|
50
|
+
this.sessionToken = sessionToken;
|
|
51
|
+
this.onTokenChange?.(sessionToken);
|
|
52
|
+
}
|
|
53
|
+
const params = { skipAsyncWait: 'false' };
|
|
54
|
+
if (opts?.currency) {
|
|
55
|
+
params.currency = opts.currency;
|
|
56
|
+
}
|
|
57
|
+
const raw = await this.http.get(`/api/v1/checkout-sessions/${checkoutToken}/v2`, {
|
|
58
|
+
params,
|
|
59
|
+
token: this.sessionToken,
|
|
60
|
+
});
|
|
61
|
+
const session = this.normalizeSession(raw);
|
|
62
|
+
this._currentSession = session;
|
|
63
|
+
return session;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create a new checkout session.
|
|
67
|
+
*
|
|
68
|
+
* Returns a `checkoutToken` and `sessionToken` (JWT) needed for all subsequent calls.
|
|
69
|
+
* Also returns a `checkoutUrl` (the full Tagada-hosted checkout URL, for reference).
|
|
70
|
+
*/
|
|
71
|
+
async createSession(opts) {
|
|
72
|
+
const lineItems = opts.items.map((i) => ({
|
|
73
|
+
variantId: i.variantId,
|
|
74
|
+
priceId: i.priceId,
|
|
75
|
+
quantity: i.quantity,
|
|
76
|
+
}));
|
|
77
|
+
const body = {
|
|
78
|
+
storeId: this.storeId,
|
|
79
|
+
lineItems,
|
|
80
|
+
};
|
|
81
|
+
if (opts.returnUrl)
|
|
82
|
+
body.returnUrl = opts.returnUrl;
|
|
83
|
+
// Always send currency in customer object (backend reads customer.currency)
|
|
84
|
+
const customerData = {};
|
|
85
|
+
if (opts.currency)
|
|
86
|
+
customerData.currency = opts.currency;
|
|
87
|
+
if (opts.customerEmail) {
|
|
88
|
+
customerData.email = opts.customerEmail;
|
|
89
|
+
customerData.firstName = opts.customerFirstName;
|
|
90
|
+
customerData.lastName = opts.customerLastName;
|
|
91
|
+
}
|
|
92
|
+
if (Object.keys(customerData).length > 0) {
|
|
93
|
+
body.customer = customerData;
|
|
94
|
+
}
|
|
95
|
+
const res = await this.http.post('/api/v1/checkout/session/init', body);
|
|
96
|
+
const url = new URL(res.checkoutUrl);
|
|
97
|
+
const sessionToken = url.searchParams.get('token') ?? '';
|
|
98
|
+
this.sessionToken = sessionToken;
|
|
99
|
+
if (sessionToken)
|
|
100
|
+
this.onTokenChange?.(sessionToken);
|
|
101
|
+
return {
|
|
102
|
+
checkoutUrl: res.checkoutUrl,
|
|
103
|
+
checkoutToken: res.checkoutToken,
|
|
104
|
+
sessionToken,
|
|
105
|
+
customerId: res.customerId,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Create a session and produce a self-hosted redirect URL.
|
|
110
|
+
*
|
|
111
|
+
* Convenience wrapper around `createSession()`. Builds a URL of the
|
|
112
|
+
* form `${origin}${checkoutPath}?checkoutToken=...&sessionToken=...`
|
|
113
|
+
* that you can navigate to from a Cart page. The receiving page reads
|
|
114
|
+
* the params via {@link CheckoutModule.parseTokensFromUrl} and calls
|
|
115
|
+
* {@link CheckoutModule.loadSession}.
|
|
116
|
+
*
|
|
117
|
+
* For Tagada-hosted checkouts use the `checkoutUrl` returned by
|
|
118
|
+
* `createSession()` directly — this helper is for **self-hosted**
|
|
119
|
+
* checkout pages.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* const { url } = await tagada.checkout.createSessionUrl({
|
|
124
|
+
* items: [{ variantId, quantity: 1 }],
|
|
125
|
+
* checkoutPath: '/checkout',
|
|
126
|
+
* });
|
|
127
|
+
* window.location.href = url;
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
async createSessionUrl(opts) {
|
|
131
|
+
const session = await this.createSession({
|
|
132
|
+
items: opts.items,
|
|
133
|
+
currency: opts.currency,
|
|
134
|
+
returnUrl: opts.returnUrl,
|
|
135
|
+
customerEmail: opts.customerEmail,
|
|
136
|
+
customerFirstName: opts.customerFirstName,
|
|
137
|
+
customerLastName: opts.customerLastName,
|
|
138
|
+
});
|
|
139
|
+
const origin = opts.origin ?? (typeof window !== 'undefined' ? window.location.origin : '');
|
|
140
|
+
const checkoutPath = opts.checkoutPath ?? '/checkout';
|
|
141
|
+
const params = new URLSearchParams({
|
|
142
|
+
checkoutToken: session.checkoutToken,
|
|
143
|
+
sessionToken: session.sessionToken,
|
|
144
|
+
});
|
|
145
|
+
const url = `${origin}${checkoutPath}?${params.toString()}`;
|
|
146
|
+
return { ...session, url };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Read `checkoutToken` and session token from a URL.
|
|
150
|
+
*
|
|
151
|
+
* Recognizes both the SDK convention (`?sessionToken=`) and the
|
|
152
|
+
* Tagada-hosted convention (`?token=`), so the same checkout page
|
|
153
|
+
* works whether the user came from `createSessionUrl()` or directly
|
|
154
|
+
* from a Tagada-hosted redirect.
|
|
155
|
+
*
|
|
156
|
+
* Returns `null` if `checkoutToken` is missing.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* const tokens = CheckoutModule.parseTokensFromUrl();
|
|
161
|
+
* if (!tokens) {
|
|
162
|
+
* window.location.href = '/cart';
|
|
163
|
+
* return;
|
|
164
|
+
* }
|
|
165
|
+
* const session = await tagada.checkout.loadSession(
|
|
166
|
+
* tokens.checkoutToken,
|
|
167
|
+
* tokens.sessionToken,
|
|
168
|
+
* );
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
static parseTokensFromUrl(url) {
|
|
172
|
+
if (typeof url === 'undefined' && typeof window === 'undefined')
|
|
173
|
+
return null;
|
|
174
|
+
const href = url ?? window.location.href;
|
|
175
|
+
let parsed;
|
|
176
|
+
try {
|
|
177
|
+
parsed = new URL(href);
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
const checkoutToken = parsed.searchParams.get('checkoutToken');
|
|
183
|
+
if (!checkoutToken)
|
|
184
|
+
return null;
|
|
185
|
+
const sessionToken = parsed.searchParams.get('sessionToken') ?? parsed.searchParams.get('token') ?? '';
|
|
186
|
+
return { checkoutToken, sessionToken };
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Add or update cart items on an existing session (upsert by product).
|
|
190
|
+
*
|
|
191
|
+
* Sends each item as `lineItems` to `POST /checkout-sessions/:id/line-items`.
|
|
192
|
+
* The endpoint UPSERTs by product: it adds new products and updates the
|
|
193
|
+
* variant/quantity of products already in the cart, but it does NOT remove
|
|
194
|
+
* products omitted from `items`, and an empty array is a no-op (it does not
|
|
195
|
+
* clear the cart). Each `quantity` must be >= 1 — removal is not supported by
|
|
196
|
+
* this endpoint.
|
|
197
|
+
*
|
|
198
|
+
* Returns a server-side mutation summary (counts of created/updated rows).
|
|
199
|
+
* It does NOT return the updated `CheckoutSession` — the underlying endpoint
|
|
200
|
+
* never has and the previous typing was a lie that quietly assigned
|
|
201
|
+
* `{ success, updated, ... }` into a `CheckoutSession` slot in `useCheckout`.
|
|
202
|
+
*
|
|
203
|
+
* Call `loadSession()` after this if you need the refreshed session
|
|
204
|
+
* (the React `useCheckout` hook does this for you).
|
|
205
|
+
*/
|
|
206
|
+
async updateCart(sessionId, items) {
|
|
207
|
+
const lineItems = items.map((i) => ({
|
|
208
|
+
variantId: i.variantId,
|
|
209
|
+
priceId: i.priceId,
|
|
210
|
+
quantity: i.quantity,
|
|
211
|
+
}));
|
|
212
|
+
return this.http.post(`/api/v1/checkout-sessions/${sessionId}/line-items`, { lineItems }, { token: this.sessionToken });
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Update customer identity (email, name, phone).
|
|
216
|
+
*
|
|
217
|
+
* Call this before `updateAddress()` — the SDK remembers the values and
|
|
218
|
+
* includes them automatically when addresses are submitted.
|
|
219
|
+
*
|
|
220
|
+
* If you prefer a single call, use `updateCustomerAndAddress()` instead.
|
|
221
|
+
*/
|
|
222
|
+
async updateCustomer(sessionId, customer) {
|
|
223
|
+
if (customer.email)
|
|
224
|
+
this.customerEmail = customer.email;
|
|
225
|
+
if (customer.firstName)
|
|
226
|
+
this.customerFirstName = customer.firstName;
|
|
227
|
+
if (customer.lastName)
|
|
228
|
+
this.customerLastName = customer.lastName;
|
|
229
|
+
if (customer.phone)
|
|
230
|
+
this.customerPhone = customer.phone;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Update shipping and/or billing address on the session.
|
|
234
|
+
*
|
|
235
|
+
* Automatically includes customer name/phone stored from `updateCustomer()`.
|
|
236
|
+
* Uses the same atomic API call as the production checkout, so email,
|
|
237
|
+
* customer name, and addresses are all persisted together.
|
|
238
|
+
*
|
|
239
|
+
* **Shipped products**: pass `shippingAddress`. If `billingAddress` is omitted,
|
|
240
|
+
* the shipping address is automatically used as billing.
|
|
241
|
+
*
|
|
242
|
+
* **Digital products**: pass only `billingAddress` (no shipping needed).
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* // Shipped product — billing = shipping automatically
|
|
246
|
+
* await checkout.updateAddress(sessionId, {
|
|
247
|
+
* shippingAddress: { line1: '10 Rue de la Paix', city: 'Paris', postalCode: '75002', country: 'FR' },
|
|
248
|
+
* });
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* // Digital product — billing only
|
|
252
|
+
* await checkout.updateAddress(sessionId, {
|
|
253
|
+
* billingAddress: { country: 'FR' },
|
|
254
|
+
* });
|
|
255
|
+
*/
|
|
256
|
+
async updateAddress(sessionId, addresses) {
|
|
257
|
+
const shipping = this.mapAddress(addresses.shippingAddress);
|
|
258
|
+
const billing = this.mapAddress(addresses.billingAddress);
|
|
259
|
+
const effectiveShipping = shipping ?? billing ?? {};
|
|
260
|
+
const effectiveBilling = billing ?? shipping;
|
|
261
|
+
const differentBilling = !!(addresses.billingAddress && addresses.shippingAddress);
|
|
262
|
+
await this.http.post(`/api/v1/checkout-sessions/${sessionId}/customer-and-session-info`, {
|
|
263
|
+
checkoutSessionId: sessionId,
|
|
264
|
+
customerData: {
|
|
265
|
+
email: this.customerEmail,
|
|
266
|
+
},
|
|
267
|
+
shippingAddress: effectiveShipping,
|
|
268
|
+
billingAddress: effectiveBilling ?? {},
|
|
269
|
+
differentBillingAddress: differentBilling,
|
|
270
|
+
}, { token: this.sessionToken });
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Set customer info + addresses in one call (mirrors production checkout).
|
|
274
|
+
*
|
|
275
|
+
* Equivalent to calling `updateCustomer()` then `updateAddress()`, but
|
|
276
|
+
* in a single network request.
|
|
277
|
+
*/
|
|
278
|
+
async updateCustomerAndAddress(sessionId, data) {
|
|
279
|
+
if (data.customer.email)
|
|
280
|
+
this.customerEmail = data.customer.email;
|
|
281
|
+
if (data.customer.firstName)
|
|
282
|
+
this.customerFirstName = data.customer.firstName;
|
|
283
|
+
if (data.customer.lastName)
|
|
284
|
+
this.customerLastName = data.customer.lastName;
|
|
285
|
+
if (data.customer.phone)
|
|
286
|
+
this.customerPhone = data.customer.phone;
|
|
287
|
+
const shipping = this.mapAddress(data.shippingAddress);
|
|
288
|
+
const billing = this.mapAddress(data.billingAddress);
|
|
289
|
+
const effectiveShipping = shipping ?? billing ?? {};
|
|
290
|
+
const effectiveBilling = billing ?? shipping;
|
|
291
|
+
const differentBilling = !!(data.billingAddress && data.shippingAddress);
|
|
292
|
+
await this.http.post(`/api/v1/checkout-sessions/${sessionId}/customer-and-session-info`, {
|
|
293
|
+
checkoutSessionId: sessionId,
|
|
294
|
+
customerData: {
|
|
295
|
+
email: this.customerEmail,
|
|
296
|
+
},
|
|
297
|
+
shippingAddress: effectiveShipping,
|
|
298
|
+
billingAddress: effectiveBilling ?? {},
|
|
299
|
+
differentBillingAddress: differentBilling,
|
|
300
|
+
}, { token: this.sessionToken });
|
|
301
|
+
}
|
|
302
|
+
/** Map an SDK Address to the API shape, injecting stored customer fields. */
|
|
303
|
+
mapAddress(a) {
|
|
304
|
+
if (!a)
|
|
305
|
+
return undefined;
|
|
306
|
+
return stripEmpty({
|
|
307
|
+
firstName: a.firstName ?? this.customerFirstName,
|
|
308
|
+
lastName: a.lastName ?? this.customerLastName,
|
|
309
|
+
phone: a.phone ?? this.customerPhone,
|
|
310
|
+
address1: a.line1,
|
|
311
|
+
address2: a.line2,
|
|
312
|
+
city: a.city,
|
|
313
|
+
state: a.state,
|
|
314
|
+
postal: a.postalCode,
|
|
315
|
+
country: a.country,
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
/** Apply a promotion code to the session. */
|
|
319
|
+
async applyPromoCode(sessionId, code) {
|
|
320
|
+
await this.http.post(`/api/v1/checkout-sessions/${sessionId}/promotions/apply`, { checkoutSessionId: sessionId, code }, { token: this.sessionToken });
|
|
321
|
+
}
|
|
322
|
+
/** Remove a promotion from the session by promotion ID. */
|
|
323
|
+
async removePromoCode(sessionId, promotionId) {
|
|
324
|
+
const promoId = promotionId ?? 'default';
|
|
325
|
+
await this.http.delete(`/api/v1/checkout-sessions/${sessionId}/promotions/${promoId}`, { token: this.sessionToken });
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Fetch available shipping rates for the session's address.
|
|
329
|
+
* Only relevant for **shipped products** — digital products can skip this step.
|
|
330
|
+
*
|
|
331
|
+
* Requires a shipping address to be set first via `updateAddress()`.
|
|
332
|
+
* Returns an empty array if no rates are configured or address is missing.
|
|
333
|
+
*/
|
|
334
|
+
async getShippingRates(sessionId) {
|
|
335
|
+
const res = await this.http.get(`/api/v1/checkout-sessions/${sessionId}/shipping-rates`, { token: this.sessionToken });
|
|
336
|
+
return (res.rates ?? []).map((r) => this.normalizeShippingRate(r));
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Normalize the v1 rates payload (`shippingRateName`, `estimatedDeliveryTime`)
|
|
340
|
+
* to the SDK's `ShippingRate` shape (`name`, `estimatedDays`). Without
|
|
341
|
+
* this the consumer's UI shows blank rate names — the demo's "Delivery"
|
|
342
|
+
* radios were rendering only the price, no label.
|
|
343
|
+
*/
|
|
344
|
+
normalizeShippingRate(r) {
|
|
345
|
+
return {
|
|
346
|
+
id: r.id,
|
|
347
|
+
name: (r.name ?? r.shippingRateName ?? ''),
|
|
348
|
+
description: (r.description ?? undefined),
|
|
349
|
+
amount: (r.amount ?? 0),
|
|
350
|
+
currency: (r.currency ?? 'USD'),
|
|
351
|
+
estimatedDays: (r.estimatedDays ?? r.estimatedDeliveryTime ?? undefined),
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Select a shipping rate for the session.
|
|
356
|
+
* Only relevant for **shipped products** — digital products can skip this step.
|
|
357
|
+
*/
|
|
358
|
+
async selectShippingRate(sessionId, rateId) {
|
|
359
|
+
await this.http.post(`/api/v1/checkout-sessions/${sessionId}/shipping-rate`, { checkoutSessionId: sessionId, shippingRateId: rateId }, { token: this.sessionToken });
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Normalize the raw v2 API response into a cleaner CheckoutSession shape.
|
|
363
|
+
* The raw response has nested `checkoutSession` + `summary` -- we flatten it.
|
|
364
|
+
*/
|
|
365
|
+
normalizeSession(raw) {
|
|
366
|
+
const cs = raw.checkoutSession;
|
|
367
|
+
const orderSummaries = (cs.orderSummaries ?? []);
|
|
368
|
+
const summary = (raw.summary ?? cs.summary ?? orderSummaries[0] ?? {});
|
|
369
|
+
const lineItems = (cs.sessionLineItems ?? []);
|
|
370
|
+
const customer = cs.customer;
|
|
371
|
+
const sessionCurrency = (summary.currency ?? cs.selectedPresentmentCurrency)?.toUpperCase();
|
|
372
|
+
const items = lineItems.map((li) => {
|
|
373
|
+
const price = li.price;
|
|
374
|
+
// The v2 endpoint returns `product` and `variant` as siblings of
|
|
375
|
+
// `price` on each line item — not nested under `price`. Reading
|
|
376
|
+
// them from `price.variant.product` (the old code) silently gave
|
|
377
|
+
// back empty objects, which is why the order summary rendered
|
|
378
|
+
// blank product names and a placeholder image instead of the
|
|
379
|
+
// actual product art.
|
|
380
|
+
const variant = (li.variant ?? price?.variant ?? {});
|
|
381
|
+
const product = (li.product ?? variant.product ?? {});
|
|
382
|
+
const currencyOpts = (price?.currencyOptions ?? {});
|
|
383
|
+
// Pick the amount bucket matching the session's presentment currency, then fall back to first available
|
|
384
|
+
const priceEntry = (sessionCurrency ? currencyOpts[sessionCurrency] : undefined)
|
|
385
|
+
?? currencyOpts[Object.keys(currencyOpts)[0]];
|
|
386
|
+
const amount = priceEntry?.amount ?? 0;
|
|
387
|
+
return {
|
|
388
|
+
id: li.id,
|
|
389
|
+
variantId: li.variantId,
|
|
390
|
+
priceId: li.priceId,
|
|
391
|
+
productName: (product.name ?? ''),
|
|
392
|
+
variantName: (variant.name ?? ''),
|
|
393
|
+
quantity: (li.quantity ?? 1),
|
|
394
|
+
unitAmount: amount,
|
|
395
|
+
totalAmount: amount * (li.quantity ?? 1),
|
|
396
|
+
currency: (sessionCurrency ?? 'USD'),
|
|
397
|
+
imageUrl: (variant.imageUrl ?? product.imageUrl ?? ''),
|
|
398
|
+
};
|
|
399
|
+
});
|
|
400
|
+
const summaryItems = (summary.items ?? []);
|
|
401
|
+
return {
|
|
402
|
+
id: cs.id,
|
|
403
|
+
storeId: cs.storeId,
|
|
404
|
+
checkoutToken: cs.checkoutToken,
|
|
405
|
+
currency: (sessionCurrency ?? 'USD'),
|
|
406
|
+
items,
|
|
407
|
+
totals: {
|
|
408
|
+
subtotal: (summary.subtotalAmount ?? 0),
|
|
409
|
+
discount: (summary.totalPromotionAmount ?? 0),
|
|
410
|
+
shipping: (summary.shippingCost ?? 0),
|
|
411
|
+
tax: (summary.totalTaxAmount ?? 0),
|
|
412
|
+
total: (summary.totalAmount ?? summaryItems.reduce((s, i) => s + (i.amount ?? 0), 0)),
|
|
413
|
+
currency: (sessionCurrency ?? 'USD'),
|
|
414
|
+
},
|
|
415
|
+
customer: customer
|
|
416
|
+
? {
|
|
417
|
+
id: customer.id,
|
|
418
|
+
email: customer.email,
|
|
419
|
+
firstName: customer.firstName,
|
|
420
|
+
lastName: customer.lastName,
|
|
421
|
+
phone: customer.phone,
|
|
422
|
+
}
|
|
423
|
+
: undefined,
|
|
424
|
+
shippingAddress: this.normalizeAddress(cs.shippingAddress),
|
|
425
|
+
billingAddress: this.normalizeAddress(cs.billingAddress),
|
|
426
|
+
selectedShippingRateId: (cs.shippingRateId ?? null),
|
|
427
|
+
metadata: cs.metadata,
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Map the raw API address shape (`address1`, `address2`, `postal`) onto
|
|
432
|
+
* the SDK's `Address` shape (`line1`, `line2`, `postalCode`). Without
|
|
433
|
+
* this, `session.shippingAddress.line1` is silently undefined after a
|
|
434
|
+
* reload — the type was lying about the actual key names — which is
|
|
435
|
+
* what makes the demo lose form state on refresh.
|
|
436
|
+
*/
|
|
437
|
+
normalizeAddress(raw) {
|
|
438
|
+
if (!raw || typeof raw !== 'object')
|
|
439
|
+
return undefined;
|
|
440
|
+
const a = raw;
|
|
441
|
+
const out = {
|
|
442
|
+
firstName: a.firstName,
|
|
443
|
+
lastName: a.lastName,
|
|
444
|
+
line1: (a.line1 ?? a.address1),
|
|
445
|
+
line2: (a.line2 ?? a.address2),
|
|
446
|
+
city: a.city,
|
|
447
|
+
state: a.state,
|
|
448
|
+
postalCode: (a.postalCode ?? a.postal),
|
|
449
|
+
country: a.country,
|
|
450
|
+
phone: a.phone,
|
|
451
|
+
};
|
|
452
|
+
// If every field is undefined the API returned an empty address slot.
|
|
453
|
+
// Hand back undefined so consumers can `if (session.shippingAddress)`.
|
|
454
|
+
return Object.values(out).some((v) => v !== undefined && v !== '') ? out : undefined;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Remove keys with empty-string / null / undefined values from an object.
|
|
459
|
+
* Prevents sending `""` to APIs that reject empty values (e.g. Stripe `country`).
|
|
460
|
+
*/
|
|
461
|
+
function stripEmpty(obj) {
|
|
462
|
+
const result = {};
|
|
463
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
464
|
+
if (v !== undefined && v !== null && v !== '') {
|
|
465
|
+
result[k] = v;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return (Object.keys(result).length > 0 ? result : undefined);
|
|
469
|
+
}
|
|
470
|
+
//# sourceMappingURL=checkout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout.js","sourceRoot":"","sources":["../../../src/core/modules/checkout.ts"],"names":[],"mappings":"AAwBA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,cAAc;IAazB,YACmB,IAAgB,EAChB,OAAe,EACf,aAAuC;QAFvC,SAAI,GAAJ,IAAI,CAAY;QAChB,YAAO,GAAP,OAAO,CAAQ;QACf,kBAAa,GAAb,aAAa,CAA0B;IACvD,CAAC;IAEJ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AAC,SAAS,CAAM,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js';
|
|
2
|
+
import type { Customer, Order, Subscription } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Customer data -- profile, orders, subscriptions.
|
|
5
|
+
*
|
|
6
|
+
* Requires either an API key or a session token for authentication.
|
|
7
|
+
*/
|
|
8
|
+
export declare class CustomerModule {
|
|
9
|
+
private readonly http;
|
|
10
|
+
private readonly storeId;
|
|
11
|
+
constructor(http: HttpClient, storeId: string);
|
|
12
|
+
/** Get customer profile by ID. */
|
|
13
|
+
getProfile(customerId: string): Promise<Customer>;
|
|
14
|
+
/** Get customer profile by email. */
|
|
15
|
+
getByEmail(email: string): Promise<Customer | null>;
|
|
16
|
+
/** Update customer profile fields. */
|
|
17
|
+
updateProfile(customerId: string, data: Partial<Pick<Customer, 'email' | 'firstName' | 'lastName' | 'phone' | 'metadata'>>): Promise<Customer>;
|
|
18
|
+
/** List orders for a customer. */
|
|
19
|
+
getOrders(customerId: string, opts?: {
|
|
20
|
+
limit?: number;
|
|
21
|
+
offset?: number;
|
|
22
|
+
}): Promise<{
|
|
23
|
+
orders: Order[];
|
|
24
|
+
total: number;
|
|
25
|
+
}>;
|
|
26
|
+
/** Get a single order by ID. */
|
|
27
|
+
getOrder(orderId: string): Promise<Order>;
|
|
28
|
+
/** List subscriptions for a customer. */
|
|
29
|
+
getSubscriptions(customerId: string): Promise<Subscription[]>;
|
|
30
|
+
/** Get a single subscription by ID. */
|
|
31
|
+
getSubscription(subscriptionId: string): Promise<Subscription>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=customer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customer.d.ts","sourceRoot":"","sources":["../../../src/core/modules/customer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAA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ires either an API key or a session token for authentication.
|
|
5
|
+
*/
|
|
6
|
+
export class CustomerModule {
|
|
7
|
+
constructor(http, storeId) {
|
|
8
|
+
this.http = http;
|
|
9
|
+
this.storeId = storeId;
|
|
10
|
+
}
|
|
11
|
+
/** Get customer profile by ID. */
|
|
12
|
+
async getProfile(customerId) {
|
|
13
|
+
const res = await this.http.get(`/api/v1/customers/${customerId}`, { params: { storeId: this.storeId } });
|
|
14
|
+
return res.customer;
|
|
15
|
+
}
|
|
16
|
+
/** Get customer profile by email. */
|
|
17
|
+
async getByEmail(email) {
|
|
18
|
+
try {
|
|
19
|
+
const res = await this.http.get('/api/v1/customers/by-email', { params: { email, storeId: this.storeId } });
|
|
20
|
+
return res.customer;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Update customer profile fields. */
|
|
27
|
+
async updateProfile(customerId, data) {
|
|
28
|
+
const res = await this.http.patch(`/api/v1/customers/${customerId}`, { storeId: this.storeId, ...data });
|
|
29
|
+
return res.customer;
|
|
30
|
+
}
|
|
31
|
+
/** List orders for a customer. */
|
|
32
|
+
async getOrders(customerId, opts) {
|
|
33
|
+
return this.http.get(`/api/v1/customers/${customerId}/orders`, { params: { storeId: this.storeId, limit: opts?.limit, offset: opts?.offset } });
|
|
34
|
+
}
|
|
35
|
+
/** Get a single order by ID. */
|
|
36
|
+
async getOrder(orderId) {
|
|
37
|
+
const res = await this.http.get(`/api/v1/orders/${orderId}`, {
|
|
38
|
+
params: { storeId: this.storeId },
|
|
39
|
+
});
|
|
40
|
+
return res.order;
|
|
41
|
+
}
|
|
42
|
+
/** List subscriptions for a customer. */
|
|
43
|
+
async getSubscriptions(customerId) {
|
|
44
|
+
const res = await this.http.get(`/api/v1/customers/${customerId}/subscriptions`, { params: { storeId: this.storeId } });
|
|
45
|
+
return res.subscriptions;
|
|
46
|
+
}
|
|
47
|
+
/** Get a single subscription by ID. */
|
|
48
|
+
async getSubscription(subscriptionId) {
|
|
49
|
+
const res = await this.http.get(`/api/v1/subscriptions/${subscriptionId}`, { params: { storeId: this.storeId } });
|
|
50
|
+
return res.subscription;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=customer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customer.js","sourceRoot":"","sources":["../../../src/core/modules/customer.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,OAAO,cAAc;IACzB,YACmB,IAAgB,EAChB,OAAe;QADf,SAAI,GAAJ,IAAI,CAAY;QAChB,YAAO,GAAP,OAAO,CAAQ;IAC/B,CAAC;IAEJ,kCAAkC;IAClC,KAAK,CAAC,UAAU,CAAC,UAAkB;QACjC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAC7B,qBAAqB,UAAU,EAAE,EACjC,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,CACtC,CAAC;QACF,OAAO,GAAG,CAAC,QAAQ,CAAC;IACtB,CAAC;IAED,qCAAqC;IACrC,KAAK,CAAC,UAAU,CAAC,KAAa;QAC5B,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAC7B,4BAA4B,EAC5B,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,CAC7C,CAAC;YACF,OAAO,GAAG,CAAC,QAAQ,CAAC;QACtB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,sCAAsC;IACtC,KAAK,CAAC,aAAa,CACjB,UAAkB,EAClB,IAAwF;QAExF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAC/B,qBAAqB,UAAU,EAAE,EACjC,EAAE,OAAO,EAAE,IAAI,CA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0,0 +1,38 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js';
|
|
2
|
+
import type { FunnelNavigateInput, FunnelNavigateResult } from '../types.js';
|
|
3
|
+
import type { CheckoutModule } from './checkout.js';
|
|
4
|
+
/**
|
|
5
|
+
* Initialize a funnel session from the SDK's current cart and produce a
|
|
6
|
+
* redirect URL into a funnel step.
|
|
7
|
+
*
|
|
8
|
+
* Mirrors the WooCommerce checkout plugin
|
|
9
|
+
* (`public/assets/php/woocommerce/tagada-checkout-plugin.php`):
|
|
10
|
+
*
|
|
11
|
+
* 1. `POST /api/v1/cms/session/anonymous` — public, returns a CMS token.
|
|
12
|
+
* 2. `POST /api/v1/cms/session/v2/init` — uses the token, returns a CMS customer id.
|
|
13
|
+
* 3. `POST /api/v1/funnel/initialize` — creates the funnel session.
|
|
14
|
+
* 4. `POST /api/v1/funnel/navigate` — fires an `INIT_CHECKOUT` event and returns `{ url }`.
|
|
15
|
+
*
|
|
16
|
+
* Steps 1–3 are cached on the module instance, so repeat `navigate()` calls in
|
|
17
|
+
* the same page only fire step 4.
|
|
18
|
+
*
|
|
19
|
+
* **Prerequisite**: the SDK must have a loaded `CheckoutSession`
|
|
20
|
+
* (`sdk.checkout.loadSession(...)`). The cart is sourced from `session.items`,
|
|
21
|
+
* the currency from `session.currency`, the customer email from
|
|
22
|
+
* `session.customer.email`, and the promotion code from `session.promotionCode`.
|
|
23
|
+
*/
|
|
24
|
+
export declare class FunnelModule {
|
|
25
|
+
private readonly http;
|
|
26
|
+
private readonly storeId;
|
|
27
|
+
private readonly checkout;
|
|
28
|
+
private readonly accountId;
|
|
29
|
+
private _cmsToken;
|
|
30
|
+
private _cmsSessionId;
|
|
31
|
+
private _cmsCustomerId;
|
|
32
|
+
constructor(http: HttpClient, storeId: string, checkout: CheckoutModule, accountId: string | undefined);
|
|
33
|
+
navigate(input: FunnelNavigateInput): Promise<FunnelNavigateResult>;
|
|
34
|
+
private ensureCmsSession;
|
|
35
|
+
private initializeFunnel;
|
|
36
|
+
private runNavigate;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=funnel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"funnel.d.ts","sourceRoot":"","sources":["../../../src/core/modules/funnel.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAEV,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,YAAY;IAMrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAR5B,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,cAAc,CAAqB;gBAGxB,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,cAAc,EACxB,SAAS,EAAE,MAAM,GAAG,SAAS;IAG1C,QAAQ,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC;YA4C3D,gBAAgB;YA+BhB,gBAAgB;YA0BhB,WAAW;CAyD1B"}
|