@sesamy/sesamy-js 1.15.1 → 1.17.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 +137 -0
- package/dist/sesamy-js.cjs +4 -4
- package/dist/sesamy-js.d.ts +37 -26
- package/dist/sesamy-js.iife.js +4 -4
- package/dist/sesamy-js.mjs +771 -752
- package/package.json +18 -12
package/README.md
CHANGED
|
@@ -326,6 +326,143 @@ 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
|
+
|
|
403
|
+
# Services
|
|
404
|
+
|
|
405
|
+
## `checkouts.get(id: string)`
|
|
406
|
+
|
|
407
|
+
Retrieves the details of a specific checkout session from Sesamy. This function fetches the checkout session information based on the provided checkout session ID.
|
|
408
|
+
|
|
409
|
+
### Parameters
|
|
410
|
+
|
|
411
|
+
- id (string): The unique identifier of the checkout session to retrieve.
|
|
412
|
+
|
|
413
|
+
### Returns
|
|
414
|
+
|
|
415
|
+
Promise\<CheckoutResponse\>: A promise that resolves to the response JSON object from the Sesamy API, which contains details about the requested checkout session.
|
|
416
|
+
|
|
417
|
+
### CheckoutResponse Schema
|
|
418
|
+
|
|
419
|
+
- id (string): The unique identifier of the checkout session.
|
|
420
|
+
- checkoutUrl (string): The URL for the checkout session.
|
|
421
|
+
- status (enum): The status of the checkout session, can be 'PENDING' or 'PAID'.
|
|
422
|
+
- createdAt (string): The creation timestamp of the checkout session.
|
|
423
|
+
- modifiedAt (string): The last modified timestamp of the checkout session.
|
|
424
|
+
- type (enum): The type of checkout session, currently only 'RECURRING' is supported.
|
|
425
|
+
- currency (string): The currency used for the checkout session.
|
|
426
|
+
- country (string): The country associated with the checkout session.
|
|
427
|
+
- language (string): The language used for the checkout session.
|
|
428
|
+
- items (Array of objects): The items included in the checkout session.
|
|
429
|
+
- sku (string): The SKU of the product.
|
|
430
|
+
- purchaseOptionId (string, optional): The ID of the purchase option for the product.
|
|
431
|
+
- title (string): The title of the product.
|
|
432
|
+
- cover (string): The cover image URL of the product.
|
|
433
|
+
- itemsOwned (Array of strings): The SKUs of the items already owned by the user.
|
|
434
|
+
- discountCodes (Array of strings): The discount codes applied to the checkout session.
|
|
435
|
+
- paymentOptions (Array of objects): The available payment options.
|
|
436
|
+
- provider (string): The payment provider.
|
|
437
|
+
- methods (Array of strings): The payment methods supported by the provider.
|
|
438
|
+
|
|
439
|
+
### Example
|
|
440
|
+
|
|
441
|
+
The following example demonstrates how to retrieve the details of a specific checkout session with Sesamy:
|
|
442
|
+
|
|
443
|
+
```javascript
|
|
444
|
+
import { getCheckout } from '@sesamy/sesamy-js';
|
|
445
|
+
|
|
446
|
+
// Retrieve the details of a checkout session by ID
|
|
447
|
+
const checkoutId = 'checkout-session-id';
|
|
448
|
+
|
|
449
|
+
getCheckout(checkoutId)
|
|
450
|
+
.then(response => {
|
|
451
|
+
console.log('Checkout session details:', response);
|
|
452
|
+
})
|
|
453
|
+
.catch(error => {
|
|
454
|
+
console.error('Error retrieving checkout session:', error);
|
|
455
|
+
});
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
In this example, the details of a specific checkout session are retrieved using its unique ID. The function returns a promise that resolves to the details of the checkout session.
|
|
459
|
+
|
|
460
|
+
### Additional Notes
|
|
461
|
+
|
|
462
|
+
- The `id` parameter is required and must be a valid checkout session identifier.
|
|
463
|
+
|
|
464
|
+
By using the `getCheckout` function, you can easily fetch the details of a specific checkout session from the Sesamy API to view or process the transaction information.
|
|
465
|
+
|
|
329
466
|
## Transform
|
|
330
467
|
|
|
331
468
|
The transform module allows for dynamic content manipulation based on specified rules. This can include inserting, replacing, or removing elements on a webpage.
|