Class: CheckoutResource

CheckoutResource()

The JS Buy SDK checkout resource

Constructor

new CheckoutResource()

Source:

Methods

addDiscount(checkoutId, discountCode) → {Promise|GraphModel}

Applies a discount to an existing checkout using a discount code.

Parameters:
Name Type Description
checkoutId String

The ID of the checkout to add discount to.

discountCode String

The discount code to apply to the checkout.

Source:
Returns:

A promise resolving with the updated checkout.

Type
Promise | GraphModel
Example
const checkoutId = 'Z2lkOi8vc2hvcGlmeS9DaGVja291dC9kMTZmM2EzMDM4Yjc4N=';
const discountCode = 'best-discount-ever';

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

addGiftCards(checkoutId, giftCardCodes) → {Promise|GraphModel}

Applies gift cards to an existing checkout using a list of gift card codes

Parameters:
Name Type Description
checkoutId String

The ID of the checkout to add gift cards to.

giftCardCodes Array.<String>

The gift card codes to apply to the checkout.

Source:
Returns:

A promise resolving with the updated checkout.

Type
Promise | GraphModel
Example
const checkoutId = 'Z2lkOi8vc2hvcGlmeS9DaGVja291dC9kMTZmM2EzMDM4Yjc4N=';
const giftCardCodes = ['6FD8853DAGAA949F'];

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

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.

presentmentCurrencyCode String <optional>

A presentment currency code. See the Storefront API reference for valid currency code values.

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
});

removeDiscount(checkoutId) → {Promise|GraphModel}

Removes the applied discount from an existing checkout.

Parameters:
Name Type Description
checkoutId String

The ID of the checkout to remove the discount from.

Source:
Returns:

A promise resolving with the updated checkout.

Type
Promise | GraphModel
Example
const checkoutId = 'Z2lkOi8vc2hvcGlmeS9DaGVja291dC9kMTZmM2EzMDM4Yjc4N=';

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

removeGiftCard(checkoutId, appliedGiftCardId) → {Promise|GraphModel}

Remove a gift card from an existing checkout

Parameters:
Name Type Description
checkoutId String

The ID of the checkout to add gift cards to.

appliedGiftCardId String

The gift card id to remove from the checkout.

Source:
Returns:

A promise resolving with the updated checkout.

Type
Promise | GraphModel
Example
const checkoutId = 'Z2lkOi8vc2hvcGlmeS9DaGVja291dC9kMTZmM2EzMDM4Yjc4N=';
const appliedGiftCardId = 'Z2lkOi8vc2hvcGlmeS9BcHBsaWVkR2lmdENhcmQvNDI4NTQ1ODAzMTI=';

client.checkout.removeGiftCard(checkoutId, appliedGiftCardId).then((checkout) => {
  // Do something with the updated 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
});

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

Replace line items on 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 set on 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.replaceLineItems(checkoutId, lineItems).then((checkout) => {
  // Do something with the updated checkout
});

updateAttributes(checkoutId, inputopt) → {Promise|GraphModel}

Replaces the value of checkout's custom attributes and/or note with values defined in the input

Parameters:
Name Type Attributes Description
checkoutId String

The ID of the checkout to update.

input Object <optional>

An input object containing zero or more of:

Properties
Name Type Attributes Description
allowPartialAddresses Boolean <optional>

An email connected to the checkout.

customAttributes Array.<Object> <optional>

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

note String <optional>

A note for the checkout.

Source:
Returns:

A promise resolving with the updated checkout.

Type
Promise | GraphModel
Example
const checkoutId = 'Z2lkOi8vc2hvcGlmeS9DaGVja291dC9kMTZmM2EzMDM4Yjc4N=';
const input = {customAttributes: [{key: "MyKey", value: "MyValue"}]};

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

updateEmail(checkoutId, email) → {Promise|GraphModel}

Replaces the value of checkout's email address

Parameters:
Name Type Description
checkoutId String

The ID of the checkout to update.

email String

The email address to apply to the checkout.

Source:
Returns:

A promise resolving with the updated checkout.

Type
Promise | GraphModel
Example
const checkoutId = 'Z2lkOi8vc2hvcGlmeS9DaGVja291dC9kMTZmM2EzMDM4Yjc4N=';
const email = 'user@example.com';

client.checkout.updateEmail(checkoutId, email).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
});

updateShippingAddress(checkoutId, shippingAddress) → {Promise|GraphModel}

Updates shipping address on an existing checkout.

Parameters:
Name Type Description
checkoutId String

The ID of the checkout to update shipping address.

shippingAddress Object

A shipping address.

Source:
Returns:

A promise resolving with the updated checkout.

Type
Promise | GraphModel
Example
const checkoutId = 'Z2lkOi8vc2hvcGlmeS9DaGVja291dC9kMTZmM2EzMDM4Yjc4N=';
const shippingAddress = {
   address1: 'Chestnut Street 92',
   address2: 'Apartment 2',
   city: 'Louisville',
   company: null,
   country: 'United States',
   firstName: 'Bob',
   lastName: 'Norman',
   phone: '555-625-1199',
   province: 'Kentucky',
   zip: '40202'
 };

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