Loading
Salesforce B2B Commerce
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Configure Checkout to Support Subscriptions for B2B Stores

          Configure Checkout to Support Subscriptions for B2B Stores

          To support subscriptions, your B2B store must use Custom Checkout with Salesforce Payments as your payment provider. You can customize the Salesforce native shipping service with an Apex extension to support subscriptions. Or, you can use a third-party shipping provider. After you configure checkout, you can sell subscription products in your store.

          Required Editions

          Available in: Lightning Experience
          Available in: Enterprise, Unlimited and Developer editions
          Available in: B2B Commerce

          Which Salesforce Commerce Product Do I Have?

          Before you begin,

          Note
          Note

          Starting in Spring ’24, the Cart Calculate API is enabled by default for LWR stores (OptionsCartCalculateEnabled is set to true). The Cart Calculate API must be enabled to sell subscription products. See Cart Calculate API.

          To configure checkout to support subscriptions,

          1. In the navigation sidebar, select a store from the Store dropdown.
          2. Click Settings | Checkout.
          3. In the Payments tab, configure Salesforce Payments as your payment provider.
            1. On the Payments tab, click the dropdown menu on the Salesforce Payments tile and select Open App. If you don't see a Salesforce Payments tile, contact your Salesforce account executive.
            2. On the Payments Merchant Accounts page, click Add Account, and follow the prompts to set up a merchant account. See Set Up a Merchant Account for Custom Checkout.
            3. Save your changes and return to your store's checkout settings.
          4. In the Taxes tab, update the values of the Tax Policy ID and the Merchant Account fields.
          5. Set up Salesforce native shipping.
            Salesforce’s native shipping service supports subscriptions with a custom Apex extension. If you prefer to use a third-party shipping service, see Add a Third-Party Shipping Service for Custom Checkout.
            1. At the top of the page, click Settings icon and select Setup.
            2. From Debug, click Open Execute Anonymous Window. An Apex Code editor opens.
            3. Copy this code snippet into the Apex editor window.
              ID webStoreId = '0ZE000000000000000'; // !!! please replace !!!
              
              // 1. Set up the default shipping profile (ShippingConfigurationSet entity object)
              ShippingConfigurationSet[] shippingConfigs = new List<ShippingConfigurationSet>();
              
              ShippingConfigurationSet shippingProfile = new ShippingConfigurationSet(Name='General',
              TargetRecordId=webStoreId, IsDefault=true);
              shippingConfigs.add(shippingProfile);
              insert shippingConfigs;
              
              
              // 2. Set up rate group (ShippingRateGroup entity)
              ShippingRateGroup[] shippingRateGroups = new List<ShippingRateGroup>();
              
              ShippingRateGroup shipRateGroup1 = new ShippingRateGroup(Name='Shipping rate group 1',
              ShippingProfileId=shippingProfile.Id);
              shippingRateGroups.add(shipRateGroup1);
              insert shippingRateGroups;
              
              
              // 3. Set up a shipping zone (ShippingRateArea entity)
              ShippingRateArea[] shippingRateArea = new List<ShippingRateArea>();
              
              ShippingRateArea shipRateArea1 = new ShippingRateArea(Name='Shipping rate area US',
              ShippingRateGroupId = shipRateGroup1.Id,
              Countries='US');
              shippingRateArea.add(shipRateArea1);
              insert shippingRateArea;
              
              // 4. Set up three simple shipping rates (StandardShippingRate entity)
              
              StandardShippingRate[] standardShippingRates = new List<StandardShippingRate>();
              
              StandardShippingRate shipRate1 = new StandardShippingRate(Name='Free Shipping 7-10 Days',
              ShippingZoneId = shipRateArea1.Id,
              Price=0.0);
              
              StandardShippingRate shipRate2 = new StandardShippingRate(Name='Overnight Shipping',
              ShippingZoneId = shipRateArea1.Id,
              Price=12.0);
              
              StandardShippingRate shipRate3 = new StandardShippingRate(Name='Express Shipping 2-3 Days',
              ShippingZoneId = shipRateArea1.Id,
              ConditionFactor='OrderPriceFactor',
              ConditionRangeMin=0.0,
              ConditionRangeMax=100.0,
              Price=5.0);
              
              
              standardShippingRates.add(shipRate1);
              standardShippingRates.add(shipRate2);
              standardShippingRates.add(shipRate3);
              
              insert standardShippingRates;
            4. Replace the store ID with your 18-character ID.
              You can find your ID in your store’s home page URL. It begins with “webStoreId=”.
            5. Execute the code.
          6. Extend the Salesforce native shipping service to support subscriptions.
            1. Copy the sample shipping calculator code from ShippingCartCalculatorSample.
            2. At the top of the page, click Settings icon and select Setup.
            3. In Quick Find, find and select Apex Classes.
            4. Click New.
            5. Paste the code sample into the Apex editor window.
            6. Save your changes and return to the Commerce app.
          7. Select the customized shipping extension as your provider.
            1. In the navigation sidebar, click Settings | Checkout.
            2. On the Shipping tab, click Select Provider on the Shipping–Cart & Checkout Calculator tile.
            3. Select SHIPPING_EXTENSION.
            4. Click Next, and confirm your changes.
          8. Create shipping profiles and rates to calculate shipping charges on order.
            1. In the navigation sidebar, click Settings | Checkout.
            2. Go to Shipping.
            3. Under Providers, click Add New Profile.
            4. Add shipping zones and shipping rates to the profile, and click Done.

          After you’ve configured your payment, tax, and shipping services, confirm that your store’s checkout page is set up to collect payment correctly using Salesforce Payments. See Customize the Payment Section of Checkout in a Commerce Store. Also, customize your store’s product and profile pages so that shoppers can browse and manage subscription products. See Configure Subscription Shopping in a Commerce Store.

          Optionally, assign a tax policy to individual products in your store. See Assign a Tax Policy to a Product.

           
          Loading
          Salesforce Help | Article