Build Baskets and Place Orders

B2C Commerce API (SCAPI) supports checkout through the Shopper Baskets, Shopper Customers, and Shopper Orders API families.

This topic outlines best practices for constructing and submitting baskets, and provides high-level guidance on how to approach payment processing with SCAPI.

Never pass payment card data to B2C Commerce. Instead, have the shopper provide payment card data directly to the payment provider using the provider's script/iframe, and pass the token returned from the provider to the API. Validate the token, and if the token is valid, accept the order, otherwise reject it.

This article assumes that you are interacting with a payment gateway from which you get a payment token.

Only existing customers can access some of the links on this page. Visit Salesforce Commerce Cloud GitHub Repositories and Access for information about how to get access to the Commerce Cloud repositories.

Make sure that you have implemented:

  • A payment gateway
  • A strategy for how you will create orders. In SCAPI, the recommended strategy is to create an order before you validate payment.
  • A SLAS private client or SLAS public client. The code examples provided in this topic use a private client. For details, see Create a SLAS Client.

You have two options for building baskets:

  • Build a basket incrementally
  • Build a basket with a single request

When you build a basket incrementally, you enter the information as the shopper provides it. This persists the basket in the B2C Commerce backend, and is useful if you can’t easily persist the basket. It also allows you to perform validation and return API errors as you go, as shown in the following code examples. Note that the comments included in the code examples are provided for clarity and must be removed for the code to work.

You can also create the basket with just one request, and provide the relevant parts you want to fill. The following example builds an entire basket and its nested documents with one request:

To retrieve an existing basket, use the Shopper Customers API getCustomerBaskets endpoint.

The following example retrieves customer baskets using a customer ID:

The following example retrieves a basket using a basket ID: