Sending a user to a checkout session using the shopify-buy SDK sometimes redirects to the cart page

We have built a custom storefront and are using Shopify purely for the checkout flow. We use the shopify-buy SDK to create and send the user to the checkout flow as follows:

  • Creating a checkout (using client.checkout.create)
  • Adding a line item (using client.checkout.addLineItems)
  • Redirecting the user to the webUrl that is found in the response of client.checkout.addLineItems (which looks like https://shop.EXAMPLE.COM/12345/checkouts/12345?key=12345)

However sometimes instead of going to the checkout flow the user will be sent to the cart page (https://shop.EXAMPLE.COM/cart)). We managed to narrow down the problem to a specific cookie that is being set on the shop.EXAMPLE.COM domain, specifically when shopify_pay_redirect cookie has a value of true the user is redirected to the cart page.

Does anyone know why this is happening and how to stop it from occurring?

We never want a user to be directed to the Cart page (especially since we don’t use Shopify for the store UI), we always want them to go to the checkout page.

Thanks in advance.