@sesamy/sesamy-js 1.15.0 → 1.16.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 CHANGED
@@ -326,6 +326,80 @@ generateLink(linkParams)
326
326
  });
327
327
  ```
328
328
 
329
+ ## `checkouts.create(params: CreateCheckoutParams)`
330
+
331
+ Creates a checkout session with Sesamy. This function initializes a checkout process by sending the necessary parameters to the Sesamy API.
332
+
333
+ ### Parameters
334
+
335
+ - params (CreateCheckoutParams): The parameters for creating the checkout session.
336
+ - items (Array of objects): An array of items to be included in the checkout.
337
+ - sku (string): The SKU of the product to be purchased.
338
+ - purchaseOptionsId (string, optional): The ID of the purchase options for the product.
339
+ - language (string, optional): The language for the checkout session. If not set, it will be automatically fetched from the HTML element's `lang` attribute.
340
+
341
+ ### Returns
342
+
343
+ Promise\<CheckoutResponse\>: A promise that resolves to the response JSON object from the Sesamy API, which contains details about the created checkout session.
344
+
345
+ ### CheckoutResponse Schema
346
+
347
+ - id (string): The unique identifier of the checkout session.
348
+ - checkoutUrl (string): The URL for the checkout session.
349
+ - status (enum): The status of the checkout session, can be 'PENDING' or 'PAID'.
350
+ - createdAt (string): The creation timestamp of the checkout session.
351
+ - modifiedAt (string): The last modified timestamp of the checkout session.
352
+ - type (enum): The type of checkout session, currently only 'RECURRING' is supported.
353
+ - currency (string): The currency used for the checkout session.
354
+ - country (string): The country associated with the checkout session.
355
+ - language (string): The language used for the checkout session.
356
+ - items (Array of objects): The items included in the checkout session.
357
+ - sku (string): The SKU of the product.
358
+ - purchaseOptionId (string, optional): The ID of the purchase option for the product.
359
+ - title (string): The title of the product.
360
+ - cover (string): The cover image URL of the product.
361
+ - itemsOwned (Array of strings): The SKUs of the items already owned by the user.
362
+ - discountCodes (Array of strings): The discount codes applied to the checkout session.
363
+ - paymentOptions (Array of objects): The available payment options.
364
+ - provider (string): The payment provider.
365
+ - methods (Array of strings): The payment methods supported by the provider.
366
+
367
+ ### Example
368
+
369
+ The following example demonstrates how to create a checkout session with Sesamy:
370
+
371
+ ```javascript
372
+ import { createCheckout } from '@sesamy/sesamy-js';
373
+
374
+ // Create a checkout session with one item
375
+ const checkoutParams = {
376
+ items: [
377
+ {
378
+ sku: 'product-sku',
379
+ purchaseOptionsId: 'option-id', // optional
380
+ },
381
+ ],
382
+ language: 'en', // optional
383
+ };
384
+
385
+ createCheckout(checkoutParams)
386
+ .then(response => {
387
+ console.log('Checkout session created:', response);
388
+ })
389
+ .catch(error => {
390
+ console.error('Error creating checkout session:', error);
391
+ });
392
+ ```
393
+
394
+ In this example, a checkout session is created with a single item specified by its SKU and an optional purchase options ID. The language is set to English (`'en'`), but if not provided, it will default to the language specified in the HTML `lang` attribute.
395
+
396
+ ### Additional Notes
397
+
398
+ - The `language` parameter is optional. If it is not provided, the language will be determined using the `getLanguage` function, which fetches the language from the `lang` attribute of the HTML document element.
399
+ - The `items` array must contain at least one item with a valid `sku`.
400
+
401
+ By using the `createCheckout` function, you can easily initialize a checkout process and handle the response from the Sesamy API to complete the transaction.
402
+
329
403
  ## Transform
330
404
 
331
405
  The transform module allows for dynamic content manipulation based on specified rules. This can include inserting, replacing, or removing elements on a webpage.