Enabling Headless Guest Checkout with D2C Commerce Cloud

Enabling Headless Guest Checkout with D2C Commerce Cloud

Over the last several years the ‘Commerce on Core’ platform has evolved quite a bit. Several releases ago we got a new template called B2C Commerce, which was the first take at bringing direct to consumer use cases into the Salesforce platform. Up to that point, only the ‘Enterprise B2C Commerce Cloud’ (previously DemandWare) covered these use cases.?


We’ve seen a lot of growth in that template since its initial release, providing core B2C functionality along with the ability to service guest users on the site.?


As companies continue to adopt this template to serve their B2C users we’ve seen an uptick in the desire to create a headless solution attached to these Commerce on Core templates. I’ve written several articles and authored a few videos over the last few months on the best practices and steps to accomplish this primarily on the B2B template. Most of those steps and best practices are transferable between the templates, with the exception of guest checkout.??


While guest checkout does indeed work in the B2C template (checkout this video out https://youtu.be/A0e7E_ySslc), there are a few current limitations with the APIs that would need to be used when building a headless solution. (See this document for the list of commerce APIs i’ve referenced in the past – https://developer.salesforce.com/docs/atlas.en-us.chatterapi.meta/chatterapi/connect_resources_commerce.htm)

The base cart to checkout APIs can be found at the above link, there are a few references that indicate that you should be able to use these APIs to complete a guest checkout. One such is the initial cart creation api where you should be able to pass in an effectiveAccountId which would be used to create a guest cart.?

https://developer.salesforce.com/docs/atlas.en-us.chatterapi.meta/chatterapi/connect_resources_commerce_webstore_cart.htm


This however isn’t working in the current iteration of this API, however i’ve been assured that this will be resolved in future releases.?

No alt text provided for this image

What then are we to do today if you need to build out a headless B2C site that needs to support guest checkout? Well, luckily for us, we have a workaround!?


Workaround

First, let’s look at a fully functioning guest B2C store that utilizes the standard Salesforce template because this will give us the key we need in order to do this via a headless solution.?

No alt text provided for this image


When a user first loads a site that has been enabled for guest access you’ll notice in the screenshot above a cookie is created for that guest users session. This cookie is the key, and it must be used all the way throughout the browsing, cart and checkout experience.?


Let’s break this cookie down:

NAME: guest_uuid_essential_0DMDo000000wmqH

  • guest_uuid_essential - This is a static identifier used across all sites
  • 0DMDo000000wmqH - This is your 15 digit site id that can be found in Salesforce, please note that this has to be the 15 digit, if you try to use the 18 digit it will not work!

VALUE: 34933c07-bffd-4abc-9005-2d30a8bff675

  • This value is a generated GUID that gets created upon loading the site, this GUID must be used all the way throughout checkout for things to work properly


Now that we understand how the standard solution works, we’ll be able to use this same principle in a headless site. All we need to do is set this cookie and keep that context throughout the session and we’ll be golden. For this article, we’ll use Postman to demonstrate this.?


Thankfully you don’t have to start from scratch! There is a great postman collection that Sandra Golden, a TA at Salesforce, has put together that covers this exact use case! https://github.com/sandragolden/sf-scom-postman-collection#new-guest-cart-and-checkout-using-cookies-dtc


Once you’ve downloaded the postman collection and imported that into your postman instance, make sure you start by going to the environment that is also imported and updating all the details to the instance you’re testing with.?


Once you have that done, you’ll want to follow the below steps in order to successfully complete a checkout:?

  1. Query Site Id, URL Prefix, Set Site URL
  2. Create a Guest Cart
  3. Get Cart by ID
  4. Add Item to Cart
  5. Create Checkout
  6. Patch Contact Info
  7. Patch Delivery Address
  8. Create Payment Token
  9. Authorize Payment
  10. Cart to Order


There are a few things that I thought I'd explain in a bit more detail.?


Request Base URL

It’s important to start your first cart creation with step #1 indicated above, this step sets up the collection variables that are used throughout the postman steps. In my case, when I made this post I only got back partial information from my instance. One of the key pieces I was missing in the response was the base URL that is used for this call. This is critical because the base url is much different then the commerce apis that I linked to above.?


If you also run into this issue, the following is an example URL that I used in my project that you can use to modify for your own usage.

https://sf-mojo.my.site.com/THB2C/webruntime/api/services/data/v{{version}}/commerce/webstores/{{_webStoreId}}/carts        


Cookie generation

This goes back to the secret sauce that makes this whole process work. On step #2, you can navigate to the ‘Pre-request Script’ section and you’ll find the following code.?

No alt text provided for this image

This is the function that creates the GUID I referenced earlier that will be used and passed through all of the calls. If this GUID is not saved, or changes as you go throughout your calls you won’t be able to successfully move forward.?

This GUID is referenced in the ‘Headers’ section of your call where you can set a cookie.?

No alt text provided for this image


Checkout

Lastly, I strongly recommend everyone to go through a successful guest checkout in the native solution before trying to use this collection. If checkout doesn’t work there, then it won’t work here either!?


There are a few nuances to the initial setup that might cause a few issues, you can find a step by step guide on one of the latest videos on my youtube channel.?


While we wait for Salesforce to update the general authenticated buyer APIs that will eventually long term be used for a headless solution, the above workaround does provide an end to end cart to checkout process.?


Good luck building your headless B2C commerce storefront!

Michael Falato

GTM Expert! Founder/CEO Full Throttle Falato Leads - 25 years of Enterprise Sales Experience - Lead Generation Automation, US Air Force Veteran, Brazilian Jiu Jitsu Black Belt, Muay Thai, Saxophonist, Scuba Diver

2 周

Shane, thanks for sharing! Any good events coming up for you or your team? I am hosting a live monthly roundtable every first Wednesday at 11am EST to trade tips and tricks on how to build effective revenue strategies. I would love to have you be one of my special guests! We will review topics such as: -LinkedIn Automation: Using Groups and Events as anchors -Email Automation: How to safely send thousands of emails and what the new Google and Yahoo mail limitations mean -How to use thought leadership and MasterMind events to drive top-of-funnel -Content Creation: What drives meetings to be booked, how to use ChatGPT and Gemini effectively Please join us by using this link to register: https://www.eventbrite.com/e/monthly-roundtablemastermind-revenue-generation-tips-and-tactics-tickets-1236618492199

回复
Monikaben Lala

Chief Marketing Officer | Product MVP Expert | Cyber Security Enthusiast | @ GITEX DUBAI in October

5 个月

Shane, thanks for sharing!

回复
Hope Frank

Global Chief Marketing, Digital & AI Officer, Exec BOD Member, Investor, Futurist | Growth, AI Identity Security | Top 100 CMO Forbes, Top 50 CXO, Top 10 CMO | Consulting Producer Netflix | Speaker | #CMO #AI #CMAIO

7 个月

Shane, thanks for sharing! How are you doing?

回复
Amalia Murray

Director of Marketing at Salesforce

2 年

So much great stuff on your channel. Thanks for walking us through it. ????

要查看或添加评论,请登录

Shane Smyth的更多文章

  • TDX `24 Recap

    TDX `24 Recap

    At TDX 2024, the Salesforce community gathered to witness the unveiling of the latest innovations, with Einstein Studio…

    5 条评论
  • Innovation, at the heart of Saltbox

    Innovation, at the heart of Saltbox

    As many of you know, I joined Saltbox about 18 months ago with a few others on the leadership team to build the next…

    8 条评论
  • Dreamforce 21 Manufacturing Innovation

    Dreamforce 21 Manufacturing Innovation

    Day 2 at Dreamforce 21 has lead to several great conversations with Parker about where the platform is going, along…

    2 条评论

社区洞察

其他会员也浏览了