@liquidcommerce/elements-sdk 2.6.0-beta.37 → 2.6.0-beta.39

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.
@@ -0,0 +1,420 @@
1
+ # Checkout
2
+
3
+ The checkout component handles the complete purchase flow - collecting customer information, processing payments, and showing order confirmation. It can run as a slide-out drawer from the cart or as a standalone hosted page.
4
+
5
+ ## Overview
6
+
7
+ The checkout element guides customers through:
8
+ - Contact information collection
9
+ - Delivery address confirmation
10
+ - Payment processing (via Stripe)
11
+ - Promo codes and gift cards
12
+ - Gift options and messaging
13
+ - Marketing opt-ins
14
+ - Age verification
15
+ - Order confirmation
16
+
17
+ After a successful purchase, customers see a confirmation screen with their order details.
18
+
19
+ ---
20
+
21
+ ## Declarative Setup (HTML Attributes)
22
+
23
+ ### Default Drawer Checkout
24
+
25
+ By default, checkout opens as a drawer when customers click "Checkout" from the cart. No additional configuration needed.
26
+
27
+ ### Hosted Checkout (External Page)
28
+
29
+ Redirect to a dedicated checkout page instead of using the drawer:
30
+
31
+ ```html
32
+ <script
33
+ defer
34
+ type="text/javascript"
35
+ data-liquid-commerce-elements
36
+ data-token="YOUR_API_KEY"
37
+ data-env="production"
38
+ data-checkout-url="https://yoursite.com/checkout"
39
+ src="https://assets-elements.liquidcommerce.us/all/elements.js"
40
+ ></script>
41
+ ```
42
+
43
+ When customers click "Checkout", they're redirected to your checkout URL with a checkout token.
44
+
45
+ ### Checkout-Only Page
46
+
47
+ For dedicated checkout pages, use the checkout-only build:
48
+
49
+ ```html
50
+ <div id="checkout-container"></div>
51
+
52
+ <script
53
+ defer
54
+ type="text/javascript"
55
+ data-liquid-commerce-checkout
56
+ data-token="YOUR_API_KEY"
57
+ data-env="production"
58
+ data-container="checkout-container"
59
+ src="https://assets-elements.liquidcommerce.us/checkout/elements.js"
60
+ ></script>
61
+ ```
62
+
63
+ This lighter build only includes checkout components, reducing bundle size for dedicated checkout pages.
64
+
65
+ ---
66
+
67
+ ## Programmatic Setup (JavaScript API)
68
+
69
+ Inject the checkout element for maximum control.
70
+
71
+ ### Basic Injection
72
+
73
+ ```javascript
74
+ const client = await Elements('YOUR_API_KEY', { env: 'production' });
75
+
76
+ const component = await client.injectCheckoutElement({
77
+ containerId: 'checkout-container'
78
+ });
79
+ ```
80
+
81
+ ### With Options
82
+
83
+ ```javascript
84
+ const component = await client.injectCheckoutElement({
85
+ containerId: 'checkout-container',
86
+ checkoutId: 'chk_abc123', // Load a specific checkout session
87
+ hideHeader: true // Hide header for embedded checkout
88
+ });
89
+ ```
90
+
91
+ ### Parameters
92
+
93
+ | Parameter | Type | Required | Description |
94
+ |-----------|------|----------|-------------|
95
+ | `containerId` | string | Yes | ID of the container element |
96
+ | `checkoutId` | string | No | Checkout token to resume a session |
97
+ | `hideHeader` | boolean | No | Hide the checkout header |
98
+
99
+ ### TypeScript Types
100
+
101
+ For TypeScript users, import types directly from the package:
102
+
103
+ ```typescript
104
+ import type {
105
+ ILiquidCommerceElementsClient,
106
+ ILiquidCommerceElementsConfig,
107
+ IAddProductParams,
108
+ ICheckoutActions
109
+ } from '@liquidcommerce/elements-sdk';
110
+ ```
111
+
112
+ ### Checkout-Only Build (NPM)
113
+
114
+ For dedicated checkout pages with smaller bundle:
115
+
116
+ ```javascript
117
+ import { ElementsCheckout } from '@liquidcommerce/elements-sdk/checkout';
118
+
119
+ const client = await ElementsCheckout('YOUR_API_KEY', { env: 'production' });
120
+ await client.injectCheckoutElement({ containerId: 'checkout-container' });
121
+ ```
122
+
123
+ ---
124
+
125
+ ## Actions
126
+
127
+ Control checkout behavior and pre-fill customer data.
128
+
129
+ ### Open / Close / Toggle
130
+
131
+ ```javascript
132
+ // Open checkout drawer
133
+ window.elements.actions.checkout.openCheckout();
134
+
135
+ // Close checkout drawer
136
+ window.elements.actions.checkout.closeCheckout();
137
+
138
+ // Toggle checkout drawer
139
+ window.elements.actions.checkout.toggleCheckout();
140
+
141
+ // Navigate to exit URL (for hosted checkout)
142
+ window.elements.actions.checkout.exitCheckout();
143
+ ```
144
+
145
+ ### Add Products Directly to Checkout
146
+
147
+ Skip the cart and go straight to checkout:
148
+
149
+ ```javascript
150
+ await window.elements.actions.checkout.addProduct(
151
+ [
152
+ {
153
+ identifier: '00619947000020',
154
+ fulfillmentType: 'shipping',
155
+ quantity: 1
156
+ }
157
+ ],
158
+ true // Open checkout after adding
159
+ );
160
+ ```
161
+
162
+ ### Promo Codes
163
+
164
+ ```javascript
165
+ // Apply promo code
166
+ await window.elements.actions.checkout.applyPromoCode('SAVE10');
167
+
168
+ // Remove promo code
169
+ await window.elements.actions.checkout.removePromoCode();
170
+ ```
171
+
172
+ ### Gift Cards
173
+
174
+ ```javascript
175
+ // Apply gift card
176
+ await window.elements.actions.checkout.applyGiftCard('GIFT-XXXX-XXXX');
177
+
178
+ // Remove gift card
179
+ await window.elements.actions.checkout.removeGiftCard('GIFT-XXXX-XXXX');
180
+ ```
181
+
182
+ ### Form Controls
183
+
184
+ Pre-fill or toggle checkout form options:
185
+
186
+ ```javascript
187
+ // Toggle gift mode
188
+ await window.elements.actions.checkout.toggleIsGift(true);
189
+
190
+ // Use shipping address for billing
191
+ await window.elements.actions.checkout.toggleBillingSameAsShipping(true);
192
+
193
+ // Set marketing preferences
194
+ await window.elements.actions.checkout.toggleMarketingPreferences('canEmail', true);
195
+ await window.elements.actions.checkout.toggleMarketingPreferences('canSms', false);
196
+ ```
197
+
198
+ ### Pre-fill Customer Information
199
+
200
+ Pre-fill forms for logged-in customers:
201
+
202
+ ```javascript
203
+ // Customer contact info
204
+ window.elements.actions.checkout.updateCustomerInfo({
205
+ firstName: 'John',
206
+ lastName: 'Doe',
207
+ email: 'john@example.com',
208
+ phone: '555-123-4567'
209
+ });
210
+
211
+ // Billing address (if different from shipping)
212
+ window.elements.actions.checkout.updateBillingInfo({
213
+ firstName: 'John',
214
+ lastName: 'Doe',
215
+ street1: '123 Billing St',
216
+ city: 'New York',
217
+ state: 'NY',
218
+ zipCode: '10001'
219
+ });
220
+
221
+ // Gift recipient info
222
+ window.elements.actions.checkout.updateGiftInfo({
223
+ recipientName: 'Jane Smith',
224
+ senderName: 'John Doe',
225
+ giftMessage: 'Happy Birthday!'
226
+ });
227
+ ```
228
+
229
+ ### Get Checkout Details
230
+
231
+ Retrieve current checkout state:
232
+
233
+ ```javascript
234
+ const checkout = window.elements.actions.checkout.getDetails();
235
+
236
+ console.log(checkout.subtotal);
237
+ console.log(checkout.total);
238
+ console.log(checkout.items);
239
+ ```
240
+
241
+ ---
242
+
243
+ ## Events
244
+
245
+ Track checkout progress and handle completion.
246
+
247
+ ### Subscribing to Events
248
+
249
+ ```javascript
250
+ window.addEventListener('lce:actions.checkout_submit_completed', (event) => {
251
+ const { orderNumber, orderTotal } = event.detail.data;
252
+ console.log('Order placed:', orderNumber);
253
+ });
254
+ ```
255
+
256
+ ### Lifecycle Events
257
+
258
+ | Event | Description | Key Data |
259
+ |-------|-------------|----------|
260
+ | `checkout_loaded` | Checkout ready | Full checkout state |
261
+ | `checkout_opened` | Drawer opened | boolean |
262
+ | `checkout_closed` | Drawer closed | boolean |
263
+ | `checkout_failed` | Operation failed | message |
264
+
265
+ ### Form Events
266
+
267
+ | Event | Description | Key Data |
268
+ |-------|-------------|----------|
269
+ | `checkout_customer_information_updated` | Customer form filled | cartId (data is secure) |
270
+ | `checkout_billing_information_updated` | Billing form filled | cartId (data is secure) |
271
+ | `checkout_gift_information_updated` | Gift form filled | cartId (data is secure) |
272
+ | `checkout_is_gift_toggled` | Gift option changed | cartId, isActive |
273
+ | `checkout_billing_same_as_shipping_toggled` | Address option changed | cartId, isActive |
274
+ | `checkout_marketing_preferences_toggled` | Opt-in changed | cartId, fieldName, isActive |
275
+
276
+ **Note:** Form update events only indicate completion status, not actual customer data (for security).
277
+
278
+ ### Item Events
279
+
280
+ | Event | Description | Key Data |
281
+ |-------|-------------|----------|
282
+ | `checkout_item_removed` | Item removed | cartId, cartItemId |
283
+ | `checkout_item_quantity_increase` | Quantity increased | cartId, cartItemId, quantity |
284
+ | `checkout_item_quantity_decrease` | Quantity decreased | cartId, cartItemId, quantity |
285
+ | `checkout_item_engraving_updated` | Personalization changed | cartId, cartItemId, engravingLines |
286
+ | `checkout_tip_updated` | Delivery tip changed | cartId, deliveryTips |
287
+
288
+ ### Submit Events
289
+
290
+ | Event | Description | Key Data |
291
+ |-------|-------------|----------|
292
+ | `checkout_submit_started` | Payment processing | started: boolean |
293
+ | `checkout_submit_completed` | Order placed | orderNumber, orderTotal |
294
+ | `checkout_submit_failed` | Order failed | message |
295
+
296
+ ### Discount Events
297
+
298
+ | Event | Description | Key Data |
299
+ |-------|-------------|----------|
300
+ | `checkout_promo_code_applied` | Discount applied | cartId, discount, newTotal |
301
+ | `checkout_promo_code_removed` | Discount removed | cartId, newTotal |
302
+ | `checkout_promo_code_failed` | Discount rejected | cartId, error |
303
+ | `checkout_gift_card_applied` | Gift card applied | cartId, newTotal |
304
+ | `checkout_gift_card_removed` | Gift card removed | cartId, newTotal |
305
+ | `checkout_gift_card_failed` | Gift card rejected | cartId, error |
306
+
307
+ ### Product Events
308
+
309
+ | Event | Description | Key Data |
310
+ |-------|-------------|----------|
311
+ | `checkout_product_add_success` | Programmatic add succeeded | cartId, itemsAdded, identifiers |
312
+ | `checkout_product_add_failed` | Programmatic add failed | cartId, identifiers, error |
313
+
314
+ ### Example: Order Completion Tracking
315
+
316
+ ```javascript
317
+ // Track successful orders
318
+ window.addEventListener('lce:actions.checkout_submit_completed', (event) => {
319
+ const { orderNumber, orderTotal } = event.detail.data;
320
+
321
+ // Send to analytics
322
+ analytics.track('Order Completed', {
323
+ orderId: orderNumber,
324
+ revenue: orderTotal
325
+ });
326
+
327
+ // Redirect to thank you page
328
+ window.location.href = `/thank-you?order=${orderNumber}`;
329
+ });
330
+
331
+ // Track failed orders
332
+ window.addEventListener('lce:actions.checkout_submit_failed', (event) => {
333
+ analytics.track('Checkout Failed', {
334
+ error: event.detail.data.message
335
+ });
336
+ });
337
+ ```
338
+
339
+ ---
340
+
341
+ ## Use Cases
342
+
343
+ ### Express Checkout for Returning Customers
344
+
345
+ Pre-fill everything for logged-in users:
346
+
347
+ ```javascript
348
+ // When user reaches checkout and is logged in
349
+ if (currentUser) {
350
+ window.elements.actions.checkout.updateCustomerInfo({
351
+ firstName: currentUser.firstName,
352
+ lastName: currentUser.lastName,
353
+ email: currentUser.email,
354
+ phone: currentUser.phone
355
+ });
356
+
357
+ // Enable billing same as shipping by default
358
+ await window.elements.actions.checkout.toggleBillingSameAsShipping(true);
359
+ }
360
+ ```
361
+
362
+ ### Skip Cart Flow
363
+
364
+ Go directly from product page to checkout:
365
+
366
+ ```javascript
367
+ document.querySelector('#buy-now').addEventListener('click', async () => {
368
+ await window.elements.actions.checkout.addProduct([
369
+ {
370
+ identifier: currentProductId,
371
+ fulfillmentType: selectedFulfillment,
372
+ quantity: selectedQuantity
373
+ }
374
+ ], true); // Opens checkout immediately
375
+ });
376
+ ```
377
+
378
+ ### Auto-Apply Best Discount
379
+
380
+ ```javascript
381
+ // Check for URL promo or user's best available code
382
+ const promoCode = urlParams.get('promo') || currentUser?.bestPromoCode;
383
+
384
+ if (promoCode) {
385
+ window.addEventListener('lce:actions.checkout_loaded', async () => {
386
+ await window.elements.actions.checkout.applyPromoCode(promoCode);
387
+ });
388
+ }
389
+ ```
390
+
391
+ ---
392
+
393
+ ## Customization
394
+
395
+ Style checkout through theme configuration.
396
+
397
+ ```javascript
398
+ const client = await Elements('YOUR_API_KEY', {
399
+ customTheme: {
400
+ checkout: {
401
+ // Checkout-specific theme options
402
+ }
403
+ }
404
+ });
405
+ ```
406
+
407
+ See [theming.md](./theming.md) for available checkout theme options including:
408
+ - Form field styling
409
+ - Button colors
410
+ - Completion screen customization
411
+ - Layout options
412
+
413
+ ---
414
+
415
+ ## See Also
416
+
417
+ - [Cart](./cart.md) - Shopping cart component
418
+ - [Actions Reference](./actions.md) - All available actions
419
+ - [Events Reference](./events.md) - All available events
420
+ - [Theming Guide](./theming.md) - Customization options