Broadleaf Microservices
  • v1.0.0-latest-prod

Cart Checkout

Initiate checkout as a guest

Operation

CheckoutClient#checkoutAsGuest(cartId, emailAddress, options);

Parameters

Parameter Type Required? Description

contactInfoRequest

ContactInfoRequest

The guest’s contact information to add to the cart.

cartId

string

The id of the cart.

options

CheckoutClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a GuestTokenResponse.

Example

Example of initiating checkout as a guest
const contactInfo = {
  emailAddress: 'some@person.com'
}
const { cart, token } = await checkoutClient.checkoutAsGuest('CART_ID', contactInfo, { accessToken });

console.log(cart);

Generate a guest checkout token

Operation

CheckoutClient#generateGuestToken(cartId, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

options

CartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a GuestTokenResponse.

Example

Example of generating a guest checkout token
const tokenResponse = await checkoutClient.generateGuestToken('CART_ID', { accessToken });

console.log(tokenResponse);

Validate a guest checkout token

Operation

CheckoutClient#validateGuestToken(cartId, token, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

token

string

The guest checkout token to validate.

options

CartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a GuestTokenValidationResponse.

Example

Example of validating an existing guest checkout token
const validationResponse = await checkoutClient.validateGuestToken('CART_ID', 'TOKEN', { accessToken });

console.log(validationResponse);

Update contact information

Operation

CheckoutClient#updateContactInfoInCart(cartId, contactInfoRequest, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

contactInfoRequest

ContactInfoRequest

The contact information to add to the cart.

options

PriceableCartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a Cart.

Example

Example of adding a contact email address to the cart
const contactInfo = {
  emailAddress: 'some@person.com'
}
const cart = await checkoutClient.updateContactInfoInCart('CART_ID', contactInfo, { accessToken });

console.log(cart);

Get available fulfillment options for a cart

Note
Use getPricedFulfillmentOptionsForCart instead if using Fulfillment Services.

Operation

CheckoutClient#getFulfillmentOptionsForCart(cartId, referenceNumber, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

referenceNumber

string

The id of the fulfillment group to retrieve fulfillment options for.

options

CartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns an array of FulfillmentOptionPricedResponse.

Example

Example of retrieving available fulfillment options
const fulfillmentOptions = await checkoutClient.getFulfillmentOptionsForCart(
  'CART_ID',
  'FULFILLMENT_GROUP_ID',
  { accessToken }
);

console.log(cart);

Get available fulfillment options for a cart

Note
Since 1.5.3 (Release Train 1.8.2)

Retrieve available priced fulfillment options for the cart

Operation

CheckoutClient#getPricedFulfillmentOptionsForCart(cartId, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

options

CartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

Example

Example of retrieving available priced fulfillment options
const fulfillmentOptions = await checkoutClient.getPricedFulfillmentOptionsForCart(
  'CART_ID',
  'FULFILLMENT_GROUP_ID',
  { accessToken }
);

console.log(cart);

Update a fullfillment group

Operation

CheckoutClient#updateFulfillmentGroupInCart(cartId, referenceNumber, fulfillmentGroupRequest, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

referenceNumber

string

The id of the fulfillment group to update.

fulfillmentGroupRequest

UpdateFulfillmentGroupRequest

The updated fulfillment option information for the fulfillment group.

options

PriceableCartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a Cart.

Example

Example of adding a fulfillment option to a fulfillment group
const fulfillmentGroupRequest: UpdateFulfillmentGroupRequest = {
  type: 'SHIP',
  fulfillmentOption: {
    name: 'Ship to Home',
    useFlatRates: true,
    taxCode: 'us',
    taxable: true
  },
  address: {
    addressLine1: '123 Street'
  }
};
const cart = await checkoutClient.updateFulfillmentGroupInCart(
  'CART_ID',
  'FULFILLMENT_GROUP_ID',
  fulfillmentGroupRequest,
  { accessToken }
);

console.log(cart);

Get available payment method options for a cart

Operation

CheckoutClient#getPaymentMethodOptionsForCart(cartId, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

options

CartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns an array of PaymentMethodOptionResponse.

Example

Example of retrieving available payment method options
const paymentMethodOptions = await checkoutClient.getPaymentMethodOptionsForCart(
  'CART_ID',
  { accessToken }
);

console.log(paymentMethodOptions);

Add a payment

Operation

CheckoutClient#addPaymentToCart(cartId, addPaymentRequest, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

addPaymentRequest

PaymentRequest

The payment information to add to the cart.

options

PriceableCartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a Cart.

Example

Example of adding a payment request to a cart
const payment: PaymentRequest = {
  savedPaymentMethodId: '1',
  type: 'CREDIT_CARD',
  gatewayType: 'PASS_THROUGH',
  amount: { amount: 100, currency: 'USD' },
  billingAddress: {
    addressLine1: '123 Street'
  },
  shouldSavePaymentForFutureUse: false,
  paymentMethodProperties: {}
};
const cart = await checkoutClient.addPaymentToCart('CART_ID', payment, { accessToken });

console.log(cart);

Update an existing payment

Operation

CheckoutClient#updatePaymentInCart(cartId, paymentId, updatePaymentRequest, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

paymentId

string

The id of the payment to update.

updatePaymentRequest

PaymentRequest

The payment information to add to the cart.

options

PriceableCartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a Cart.

Example

Example of updating a payment on a cart
const payment: PaymentRequest = {
  savedPaymentMethodId: '1',
  type: 'CREDIT_CARD',
  gatewayType: 'PASS_THROUGH',
  amount: { amount: 100, currency: 'USD' },
  billingAddress: {
    addressLine1: '123 Street'
  },
  shouldSavePaymentForFutureUse: false,
  paymentMethodProperties: {}
};
const cart = await checkoutClient.addPaymentToCart('CART_ID', 'PAYMENT_ID', payment, { accessToken });

console.log(cart);

Remove an existing payment

Operation

CheckoutClient#removePaymentInCart(cartId, paymentId, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

paymentId

string

The id of the payment to remove.

options

PriceableCartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a Cart.

Example

Example of removing an existing payment on a cart
const cart = await checkoutClient.removePaymentInCart('CART_ID', 'PAYMENT_ID', { accessToken });

console.log(cart);

Recalculate taxes

Operation

CheckoutClient#recalculateTaxesForCart(cartId, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

options

RecalculateTaxesClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a Cart.

Example

Example of recalculating taxes for a cart
const cart = await checkoutClient.recalculateTaxesForCart('CART_ID', { accessToken });

console.log(cart);

Request Cart Approval (for B2B)

Operation

CheckoutClient#requestCartApproval(request, cartId, options);

Parameters

Parameter Type Required? Description

request

CartApprovalProcessRequest

Request DTO used for providing information for the cart approval flows, such as submitting cart for approval or rejecting cart.

cartId

string

The id of the cart.

options

ClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a CartApprovalProcessResponse if successful. If the request fails, a CartApprovalValidationApiError is thrown.

Example

const request = {
    comment: 'This is for John Doe\'s Truck Fleet'
};
const { cart } = await checkoutClient.requestCartApproval(request, 'CART_ID', { accessToken });

console.log(cart);

Reject Cart Approval (for B2B)

Operation

CheckoutClient#rejectCartApproval(request, cartId, options);

Parameters

Parameter Type Required? Description

request

CartApprovalProcessRequest

Request DTO used for providing information for the cart approval flows, such as submitting cart for approval or rejecting cart.

cartId

string

The id of the cart.

options

ClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a CartApprovalProcessResponse if successful. If the request fails, a CartApprovalValidationApiError is thrown.

Example

const request = {
    comment: 'The cart total is too high. Please remove some items or reduce their quantities.'
};
const { cart } = await checkoutClient.rejectCartApproval(request, 'CART_ID', { accessToken });

console.log(cart);

Process the checkout

Operation

CheckoutClient#processCheckoutForCart(cartId, requestId, options);

Parameters

Parameter Type Required? Description

cartId

string

The id of the cart.

requestId

string

The request id of the cart.

options

CartClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a CheckoutResponse.

Example

Example of processing a checkout
const response = await checkoutClient.processCheckoutForCart('CART_ID', 'REQUEST_ID', { accessToken });

console.log(response);