Setting Up Loyalty & Referrals on SFCC Controllers and Pipelines

      Setting Up Loyalty & Referrals on SFCC Controllers and Pipelines


        Article summary

        Products


        Loyalty
        Supported plans

        Premium, Enterprise

        eCommerce Platform

        Salesforce Commerce Cloud

        Yotpo’s suite of integrated solutions for loyalty and referrals helps commerce companies accelerate growth by enabling advocacy and maximizing customer lifetime value. With Yotpo's Loyalty and Referrals solutions, brands can effectively leverage social proof to increase trust and sales, cultivate loyal customer advocates, and make better business decisions based on real customer feedback.

        This document provides a technical overview and step-by-step instructions for installing Yotpo's Salesforce Commerce Link Cartridge - enabling you to integrate various Yotpo features within a Salesforce Commerce storefront.

        This article covers the installation of the Yotpo Loyalty & Referrals Cartridge for Salesforce Commerce Cloud's Controllers or Pipelines versions.

        For instructions on how to install Yotpo Loyalty & Referrals Cartridge for Salesforce SFRA, please see this article.

        Merchants using Yotpo's Salesforce Commerce Link Cartridge can access the following features:

        • Loyalty Program (Earning and redeeming points)
        • Referral Program 
        • In order to use the Salesforce Commerce Link Cartridge, you must be subscribed to an eligible Yotpo premium plan.
        • Use of the Yotpo LINK cartridge by itself does not grant nor enable the use of Yotpo product offerings. You must first enter a contractual agreement with Yotpo in order for the loyalty and referral program to run. 
        • To learn more, please reach out to Yotpo Sales at: sales@yotpo.com

        Cartridge overview

        Important!
        • The cartridge is compatible with Site Genesis version 13.6 or later.
        • For the storefront functionality to work properly, the Purchasers Feed Export Generation integration must be set up within your Salesforce Business Manager.

        The Loyalty & Referrals integration makes use of the following cartridges: 

        CartridgeDescriptionService
        bm_yotpoBusiness ManagerSwell Loyalty & Referrals 

        Terms of service

        In using the Yotpo LINK cartridge, you agree to Yotpo's terms of service.

        Step 1: Configuration

        Files download

        Make sure to download the installation files.

        Cartridge registration

        Navigate to the following path: Administration > Manage Sites  > Business Manager  >  Settings

        Add the cartridge name: bm_yotpo within the Cartridges path as shown below:

        The cartridge includes a custom interface within the Salesforce Business Manager to manage logins to the Yotpo Loyalty & Referrals control panel.

        SiteGenesis Controller cartridge configuration

        The Yotpo cartridge relies on a “guard” script from SiteGenesis Controller cartridge if the integration is being implemented with the Controller version. 

        • The default name used in Salesforce is:  app_storefront_controllers
        • If the controller cartridge name differs from the default name, you need to change the constant in Yotpo's code. This is the constant that needs to change; exports.SITEGENESIS_CARTRIDGE_NAME = "app_storefront_controllers";
        • You need to change it in Yotpo's code under int_yotpo/cartridge/scripts/yotpo/utils/Constants.js

        Uploading Metadata configurations

        The downloaded files include a metadata.zip file that needs to be uploaded to your Salesforce admin. 

        To upload the file, go to Administration > Site development > Import & Export > Manage Import Files and upload the metadata.zip file:



        Once the file is uploaded, click the Import button next to "Meta data". You'll be guided through a Salesforce Commerce Cloud installation wizard.

        This process automatically adds all the necessary Yotpo attributes to your platform.

        Services details

        In this section, we are defining where Yotpo's cartridge will send Salesforce information (such as orders, customers, etc) to Yotpo's backend. 

        1. Navigate to Administration > Operations > Services > Click on the Credentials tab
        2. Click New
        3. In the Name field (Required) add the following: int_yotpo.https.post.swell.api.cred
        4. In the URL field add: https://app.swellrewards.com/commerce-cloud/
        5. User and Password fields are not required
        6. Once the setting is saved, this is what you will see in Salesforce: 
        NameProfileCredentials
        int_yotpo.https.post.swell.apiint_yotpo.rest.api.profileint_yotpo.https.post.swell.api.cred

        Step 2: Setting up the integration

        Adding logged-in customer and cart tracking

        Yotpo Loyalty needs to have information about the customer on the website's front end. We need to know if the customer is logged in and we also need to know the cart information. We need this information in order to present the customer with their points balance, redemption options, etc. In order for Yotpo to get this information, the following template must be included within the storefront footer file i.e. footer.isml in SiteGenesis:

        <isinclude template="include/yotpofooter" />
        Where should the HTML code be placed?
        You can place this code anywhere on the page. We recommend placing it in the footer.

        After you place the above html template snippet in your page (in the example below, it's in the footer), it will be rendered on your site as follows (swell customer identification and swell cart identification tags were added):

        Adding Data Observers

        Yotpo needs to get all orders and customers in order to be able to reward points, give coupons, place customers in tiers, etc. The loyalty cartridge is responsible for sending this information from SFCC to Yotpo by using two site genesis controllers described below. The details of controllers are described below.

        Order observer

        The order observer hook should be added into COSummary-Submit (checkout summary submit) controller after order creation with the following code snippet:

                var SwellExporter = require('int_yotpo/cartridge/scripts/yotpo/swell/export/SwellExporter');
                var result = SwellExporter.exportOrder({
                    orderNo: order.orderNo,
                    orderState: 'created'
                });

        Customer observer

        The customer observer hook should be added into Account-RegistrationForm and Account-EditForm controllers using the following code snippet:

                var SwellExporter = require('int_yotpo/cartridge/scripts/yotpo/swell/export/SwellExporter');
                var result = SwellExporter.exportCustomer({
                       customerNo: customer.profile.customerNo
                });

        After adding the above code snippet your controllers will look like this:

        Account registration form

        Account edit form

        Adding Yotpo cartridge required endpoints

        On top of orders and customers that Yotpo is listening to through the above controllers, Yotpo needs to get more information from the cartridge in order for the loyalty and referral program to perform properly. This step is crucial in the setup of the integration. 

        In this section, we are mapping the methods required in the cartridge to URLs (endpoints) that will be available in SFCC for Yotpo to pull data. 

        Steps to adding the required endpoints mapping

        Navigate to Merchant Tools > SEO > URL Rules > Pipeline URLs  

        Add the following mappings URLs in Pipeline URLs

        Please Note:
        If you don't see the Pipeline URLs route in your BM, please contact Salesforce support.
        Alias (URL in BM)Pipeline (Method in Yotpo's Cartridge)Why is this needed
        swell/index/customerSwellYotpo-GetCustomerWhen Yotpo needs specific information on a single customer
        swell/index/customersSwellYotpo-GetCustomersWhen a new merchant onboards, Yotpo pulls past customers
        swell/index/orderSwellYotpo-GetOrderWhen Yotpo needs specific information on a single order (for processing refunds for example)
        swell/index/ordersSwellYotpo-GetOrdersWhen a new merchant onboards, Yotpo pulls past orders
        swell/index/thirty-day-order-volumeSwellYotpo-GetOrderCountByVolumeVerifying communication between SFCC and the cartridge
        swell/index/create-gift-certificateSwellYotpo-CreateGiftCertificateWhen the merchant uses gift certificates, this endpoint is used

        After adding the endpoints, your setting page will look like this: 

        Step 3: Setting up refunds

        If you'd like to deduct or re-issue points redeemed at checkout for refunded orders, you'll need to send Yotpo Loyalty & Referrals the refund data. If you're using product-specific requirements or restrictions for campaigns, you'll also need to include specific item information along with the required refund data. This should be done by sending a new refund to the Swell API via the POST: Create A Refund endpoint outlined below to modify the previously processed order.

        This endpoint records a refund for an existing order. It will apply the refund to the relevant order and then adjust any reward given by the original order. 

        Please see the API specifications and parameters here.

        Step 4: Enabling loyalty

        In order for the cartridge to work you need to enable Loyalty:

        1. Navigate to Merchant Tools > Site Preferences > Custom Preferences > Yotpo Configs
        2. Enable the Yotpo Loyalty & Referrals settings by updating the Swell Loyalty Enabled field to "Yes"
        Custom Attribute NameFunction
        Yotpo Cartridge EnabledEnables/disables the Yotpo cartridge
        Swell Loyalty EnabledEnables/disables Swell Loyalty
        Yotpo Static Content URLThe base URL to load static content from Yotpo
        Yotpo Conversion Tracking Pixel URLConversion tracking pixel URL
        Import Reviews RealtimeDesignates whether reviews are imported in real-time
        Product Information From MasterMakes production information configurable whether the information will be exported from master or from variants.
        Export Group ID in OrderUsed to make the logic configurable that whether the master product if will be exported as JSON or not.
        Yotpo Orders Batch SizeThis attribute contains batch size for the number of orders that should be processed at one time, while exporting purchase feed.
        Yotpo Swell Static Content URLThe URL used to load static content for Swell JavaScript
        Yotpo Info Log EnabledThe flag controls the info log level in whole Yotpo cartridge. By default, the info log will be disabled, therefore to enable the checkbox should be checked.
        Yotpo Debug Log EnabledThe flag controls the debug log level in whole Yotpo cartridge. By default, the debug log will be disabled, therefore to enable the checkbox should be checked.

        Step 5: Giving Yotpo OCAPI permissions

        Yotpo uses OCAPI (Salesforce's Open Commerce API) as part of the loyalty integration. In order to give Yotpo permissions to OCAPI, you need to create a user on Salesforce that has the relevant OCAPI permissions. Then you will provide Yotpo with the user and password in the integration phase (step 7).

        Important!

        The user login and password credentials have to be that of an actual user (meaning, can be used to log into the SFCC Business Manager).

        These credentials expire every 90 days. The loyalty/integrations/integration_disabled event will be sent to the webhook URL and the integration will be disabled.

        You will have to update the new password in the Loyalty & Referrals admin to ensure that Yotpo is able to access your SFCC store to generate rewards, as well as retrieve customers and orders.

        Endpoints

        Yotpo uses two types of endpoints on OCAPI - Shop and Data. The following endpoints are needed for the Yotpo integration: See here the full documentation on Salesforce. 

        EndpointDescription
        /baskets/#{basket_id}/payment_instrumentsAdd payment instrument to basket. When the customer  redeems points for a gift certificate and applies it to the basket - this endpoint is used. 
        /baskets/#{basket_id}/payment_instruments/#{payment_instrument_id}Remove Payment instrument from basket. When the customer removes a gift certificate from the basket, this endpoint is used. 
        /baskets/#{basket_id}/itemsAdd product to basket. When there is a free product redemption (customers redeems points for product), this endpoint is used to add the product to the basket. 
        /baskets/#{basket_id}/items/#{item_id}Remove product from basket. If the customer decides they do not want the free product, this endpoint is used to remove the product from the basket. 
        /baskets/#{basket_id}/price_adjustmentsAdd price adjustment to basket. When using fixed amount/ percentage/ variable redemption, this endpoint is used in order to give the discount to the customer. 
        /baskets/#{basket_id}/price_adjustments/#{price_adjustment_id}Remove price adjustment from basket. If the customer decides to remove the discount from the basket, this endpoint is used to remove it. 
        /baskets/#{basket_id}Get information on basket. Used to understand which redemptions are part of the basket in order to know how many points to present to the customer. 
        /baskets/
        /baskets/#{basket_id}/storefront
        Create basket. Mainly used for free product redemptions, when there is no basket and the customer redeemed a product, we create the basket for the customer. 
        /baskets/#{basket_id}/couponsAutomatically add coupon to basket. Used for the referred friend coupon to auto apply it to the basket. 

        Adding the endpoints to Salesforce

        In order to give Yotpo permissions for all of the above endpoints, You will need to upload two files to the business manager. One to the shop OCAPI and one to the data OCAPI. Navigate to Administration > Site Development > Open Commerce API SettingsUnder the Shop settings, copy the endpoints from this file.

        Under the Data settings, copy the endpoints from this file.

        Important!

        A basic configuration for these OCAPI settings is included in the metadata import. 

        This configuration is located under the “client_id” section inside of the “Open Commerce API Settings” and must be set to the appropriate client ID for both the “Shop” and “Data” dropdown selections.

        We recommend changing the default Client ID from its default setting. This also applies to staging/dev accounts.

        Make sure this ID matches the one you use in the integration page of your Yotpo Loyalty admin. 

        Step 6: Enabling login to Yotpo via Salesforce

        In this section, we explain how to add a Yotpo login function to your Salesforce admin. This is important in SFCC to have Yotpo credentials. Permission to access the Loyalty module must be granted to a specific role. 

        1. Navigate to the following path: Administration > Organization > Roles & Permissions
        2. Select the relevant role to be granted e.g. Administrator
        3. Open the Business Manager Module tab as shown below in the animation below.
        4. Choose the relevant site
        5. Check the box adjacent to Yotpo Swell Login
        6. Click Update

        Step 7: Yotpo Loyalty & Referrals admin registration

        Lastly, complete the integration through the Yotpo Loyalty & Referrals admin dashboard which can be accessed via the Business Manager module:

        1. Navigate to Merchant Tools > Site Preferences > Yotpo Swell Login
        2. Select the specific locale configured in Yotpo Configurations (custom object). Your Yotpo Loyalty & Referrals GUID and API Key will be automatically populated.
        3. Click the Login button to access your Yotpo Loyalty & Referrals admin.
        4. Within the Loyalty Admin, click Integrations
        5. Select Commerce Cloud from the dropdown list of integrations
        6. Fill in the fields with the relevant details/ identifiers and click Add Integration when you're done
        Please note:
        Upon clicking Add Integration for the first time, all historical order and customer data will be retrieved.

        FieldDescription
        Instance TypeSelect Production or Sandbox environment. Note that each instance must be connected to a different Yotpo Loyalty & Referrals account.
        Client IDSalesforce Client ID
        Client PasswordSalesforce Client Password
        User LoginSalesforce User Login - this user needs to have permission to add price adjustments to a basket.
        User PasswordSalesforce User Password
        HostnameYour store's URL e.g. https://amizingstore.com
        You may choose to temporarily protect your site with a username and password. You can add those details to the Yotpo Loyalty admin so that Yotpo can have access to your protected site.
        Simply add the storefront credentials to the Salesforce integration page in your Yotpo Loyalty admin in the following format:
        If the storefront URL is: https://yotpo03-tech-prtnr-eu03-dw.demandware.net/
        and the storefront credentials are as follow: user_name: userpassword: strong_password
        then the Hostname value should be added like this:https://user:strong_password@yotpo03-tech-prtnr-eu03-dw.demandware.net/
        Site IDSalesforce Site ID. The Site Id can be found in your SFCC admin under Administration > Sites > Manage Sites
        Note: If you have implemented any URL redirections after the initial locale, make sure to add them to this field as part of the integration.
        OCAPI VersionSpecify which Open Cart API version is used in the following format:v19_1The value must match the latest OCAPI version available.
        Cartridge VersionPlease select V1 to ensure that you are seeing all of the relevant features for this integration
        Important!

        The user login and password credentials have to be that of an actual user (meaning, can be used to log into the SFCC Business Manager).

        These credentials expire every 90 days. The loyalty/integrations/integration_disabled event will be sent to the webhook URL and the integration will be disabled.

        You will have to update the new password in the Loyalty & Referrals admin to ensure that Yotpo is able to access your SFCC store to generate rewards, as well as retrieve customers and orders.

        Registration error

        If you see an error message in your Yotpo Loyalty & Referrals admin at the point of registration, follow the instruction below to see how to resolve it and continue with the integration:

        ErrorSolution
        Invalid client id, client password, user login, or user passwordThis means that the OCAPI credentials are invalid. You can review this section of the process here.
        Either one of these fields is wrong (Hostname, Site ID, OCAPI Version) or Cartridge configured incorrectly in Commerce Cloud adminThis means that the URL mapping may not have been added correctly. You can review this section of the process here.

        Suffix - Data storage

        Yotpo uses custom attributes - special fields used to add details to objects. This is an SFCC feature that allows you to add additional info to objects.

        This allows us to receive additional information about the shoppers, orders, and redemptions to fully correlate these details within our system to present in our Loyalty dashboards (link)

        Below you can see a breakdown of the attributes added as part of the cartridge that we then use to showcase within the boards:

        Order custom attributes

        IDNameDescriptionType
        userAgentUser AgentThis attribute stores the user agent information at the time of order placementString
        userIPAddressUser IP AddressThis attribute stores the user IP address information at the time of order placementString

        PriceAdjustment custom attributes

        IDNameDescriptionType
        swellPointsUsedSwell Points UsedThe number of points used as part of the  redemptionInteger
        swellRedemptionIdSwell Redemption IdThe detail required to associate Yotpo's internal redemption ID with the price adjustment happening on siteString

        ProductLineItem custom attributes

        IDNameDescriptionType
        swellPointsUsedSwell Points UsedThe number of points used as part of the  redemptionInteger
        swellRedemptionIdSwell Redemption IdThe detail required to associate Yotpo's internal redemption ID with the price adjustment happening on siteString

        OrderPaymentInstrument custom attributes

        IDNameDescriptionType
        swellPointsUsedSwell Points UsedThe number of points used as part of the  redemptionInteger
        swellRedemptionIdSwell Redemption IdThe detail required to associate Yotpo's internal redemption ID with the price adjustment happening on siteString

        GiftCertificate Custom Attributes

        IDNameDescriptionType
        swellPointsUsedSwell Points UsedThe number of points used as part of the  redemptionInteger
        swellRedemptionIdSwell Redemption IdThe detail required to associate Yotpo's internal redemption ID with the price adjustment happening on siteString

        Configuring order processing flow

        The Settings section of your Yotpo Loyalty & Referrals admin allows you to choose an order status that will trigger point deduction and an order status that will trigger the rewarding of points.

        • Point deduction

        Set a trigger that will deduct the points a shopper used to redeem coupons or discounts when making the purchase. Yotpo will deduct the points as the status is registered in our system. 

        We recommend deducting points at the point of order creation to avoid a time gap where shoppers may try to redeem points that are no longer available to them.

        • Rewarding points

        If you are using a payment processing provider such as WorldPay, the payment approval process for a new order may take some time. Ideally, we do not want to reward a shopper with points before the payment has been approved.

        Setting up an order status 'COMPLETED' as the trigger for rewarding points will ensure that points will be given only after the payment has been processed and confirmed.

        We recommend setting the trigger post-payment approval so as not to reward customers with points for an unsuccessful purchase.


        Was this article helpful?