Class: CheckoutResource

CheckoutResource()

The JS Buy SDK checkout resource

Constructor

new CheckoutResource()

Source:

Methods

addLineItems(checkoutId, lineItems) → {Promise|GraphModel}

Adds line items to an existing checkout.

Parameters:
Name Type Description
checkoutId String

The ID of the checkout to add line items to.

lineItems Array.<Object>

A list of line items to add to the checkout. See the Storefront API reference for valid input fields for each line item.

Source:
Returns:

A promise resolving with the updated checkout.

Type
Promise | GraphModel
Example
const checkoutId = 'Z2lkOi8vc2hvcGlmeS9DaGVja291dC9kMTZmM2EzMDM4Yjc4N=';
const lineItems = [{variantId: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8yOTEwNjAyMjc5Mg==', quantity: 5}];

client.checkout.addLineItems(checkoutId, lineItems).then((checkout) => {
  // Do something with the updated checkout
});

create(inputopt) → {Promise|GraphModel}

Creates a checkout.

Parameters:
Name Type Attributes Description
input Object <optional>

An input object containing zero or more of:

Properties
Name Type Attributes Description
email String <optional>

An email connected to the checkout.

lineItems Array.<Object> <optional>

A list of line items in the checkout. See the Storefront API reference for valid input fields for each line item.

shippingAddress Object <optional>

A shipping address. See the Storefront API reference for valid input fields.

note String <optional>

A note for the checkout.

customAttributes Array.<Object> <optional>

A list of custom attributes for the checkout. See the Storefront API reference for valid input fields.

Source:
Returns:

A promise resolving with the created checkout.

Type
Promise | GraphModel
Example
const input = {
  lineItems: [
    {variantId: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8yOTEwNjAyMjc5Mg==', quantity: 5}
  ]
};

client.checkout.create(input).then((checkout) => {
  // Do something with the newly created checkout
});

fetch(id) → {Promise|GraphModel}

Fetches a checkout by ID.

Parameters:
Name Type Description
id String

The id of the checkout to fetch.

Source:
Returns:

A promise resolving with a GraphModel of the checkout.

Type
Promise | GraphModel
Example
client.checkout.fetch('FlZj9rZXlN5MDY4ZDFiZTUyZTUwNTE2MDNhZjg=').then((checkout) => {
  // Do something with the checkout
});

removeLineItems(checkoutId, lineItemIds) → {Promise|GraphModel}

Removes line items from an existing checkout.

Parameters:
Name Type Description
checkoutId String

The ID of the checkout to remove line items from.

lineItemIds Array.<String>

A list of the ids of line items to remove from the checkout.

Source:
Returns:

A promise resolving with the updated checkout.

Type
Promise | GraphModel
Example
const checkoutId = 'Z2lkOi8vc2hvcGlmeS9DaGVja291dC9kMTZmM2EzMDM4Yjc4N=';
const lineItemIds = ['TViZGE5Y2U1ZDFhY2FiMmM2YT9rZXk9NTc2YjBhODcwNWIxYzg0YjE5ZjRmZGQ5NjczNGVkZGU='];

client.checkout.removeLineItems(checkoutId, lineItemIds).then((checkout) => {
  // Do something with the updated checkout
});

updateLineItems(checkoutId, lineItems) → {Promise|GraphModel}

Updates line items on an existing checkout.

Parameters:
Name Type Description
checkoutId String

The ID of the checkout to update a line item on.

lineItems Array.<Object>

A list of line item information to update. See the Storefront API reference for valid input fields for each line item.

Source:
Returns:

A promise resolving with the updated checkout.

Type
Promise | GraphModel
Example
const checkoutId = 'Z2lkOi8vc2hvcGlmeS9DaGVja291dC9kMTZmM2EzMDM4Yjc4N=';
const lineItems = [
  {
    id: 'TViZGE5Y2U1ZDFhY2FiMmM2YT9rZXk9NTc2YjBhODcwNWIxYzg0YjE5ZjRmZGQ5NjczNGVkZGU=',
    quantity: 5,
    variantId: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8yOTEwNjAyMjc5Mg=='
  }
];

client.checkout.updateLineItems(checkoutId, lineItems).then(checkout => {
  // Do something with the updated checkout
});