I’m using the Buy SDK for iOS to create a custom storefront. Currently I’m working on the cart and checkout features. I noticed that the API offers two very similar mutations - cartCreate and checkoutCreate.
Both take similar output and return similar responses. One big difference I see from the docs is that cartCreate allows you to pass in the customerAccessToken while checkoutCreate doesn’t.
I want to know what are the main differences between these two and which one I should when. Especially when I’m developing a cart and checkout flow.
The cartCreate and checkoutCreate mutations are indeed similar but they are used in different contexts and for different purposes.
The cartCreate mutation is used to create a new cart. A cart is a collection of items that a customer wants to buy. Carts are used to track items customers want to purchase, as well as the total cost of the items before taxes and shipping. The cart is created before the checkout process begins. In certain cases, you might want to allow customers to save their cart and come back to it later, which is where the customerAccessToken can come in handy.
On the other hand, the checkoutCreate mutation is used to create a new checkout. A checkout is the process of purchasing the items in a cart. During checkout, the customer provides the information needed to fulfill their order, such as shipping address and payment details. The checkout process begins after the customer decides to buy the items in their cart.
In a typical e-commerce flow, you would use cartCreate to allow customers to add items to their cart. When the customer is ready to purchase the items, you would then use checkoutCreate to start the checkout process.
The main difference between the two is that cartCreate is used for managing what items a customer wants to buy, while checkoutCreate is used to manage the actual process of buying those items.