Let's Connect

Reach out to us for a discussion, a Demo or both!

This post, and the next, shows one way, of many, how to establish a loyalty program using Sitecore OrderCloud and a bit of middleware.  

5.30.24

Roland Villemoes

Background

It’s almost impossible to avoid participating in a myriad of loyalty programs – they are everywhere. From airlines, hotels, food, retails etc. There’s a simple reason why there’s so many businesses that offer these loyalty programs: They work.

 

Through a couple of articles, I want to explore how to build configure and use loyalty programs with Sitecore OrderCloud (OC). OC is extremely flexible and the various configuration options make it a good fit for a wide range of setups – Loyalty Programs just one of them.

 

Note: To get a good overview of Sitecore OrderCloud and Customer Loyalty Programs – you should read this article by Steve Davis – “Customer Loyalty Programs”. This article is used as inspiration and basis for the various models, configurations and techniques I will dive into.

 

Our Loyalty Program setup

First things first - let’s list – on a high level – what loyalty programs normally consists of:

  • A way for customers to earn points, or rewards based on purchases, actions – anything. But normally based on past purchases.
  • A way for customers to spend these earned points – as payments, partial payments or other benefits.

 

OrderCloud will provide the framework on which we can establish our Loyalty Program. But first, we must define how we want it to work for our business. To make this simple, we define our loyalty program based on the following rules – and we’re assuming this is for a B2C setup only:

  • Join Reward: To sign up for our Loyalty Program a customer will get 500 points.
  • Purchase Reward: For each purchase – the customer earns 10 x the amount in $. Say you purchase something for $59, you’ll get 590 points added to your Loyalty account.
  • You can on any purchase, spend your points – 100 points equals $1.
  • For purchases where you use your points you will not earn any points – this also includes purchases where you make a split payment where part of the payment is done using your points.

 

These rules and logic are obviously something that would be set up or configured in a dedicated Loyalty System. We will implement these rules in some code to be able to try out the use cases.

 

Only the imagination will be the limit for what you can set up to get customers to make certain purchases. Starbucks is really active around this. Offers where you get customers to purchase certain products within a certain date will give you extra points (I must admit that it works!)

For inspiration for what other companies are doing, you can look at this article previously publish on our site: 7 Innovative Customer Loyalty Program Ideas to Boost Retention

Now, let’s get into the technicalities…

 

Architectural Overview

For the set-up we will make it as simple as possible. It will be a setup where we have a simple Next.Js app running locally. This app will be the Loyalty System as well as the endpoints for tax calculation, order submit and all other “events” that we will need for running these use cases.

What is needed then?

  • An OrderCloud instance
  • -ngrok to expose our local endpoint publicly so that OrderCloud can call it.
  • Local Next.Js app to handle the above-mentioned events as well as the Loyalty System.
  • Postman to run through the various test cases.

 

For the rest of this article, I will walk through how this is set up and begin configured. The next article will be on implementing our fictive loyalty program.

 

OrderCloud instance

It’s easy to get going – head over to ordercloud.io and create your account. If you haven’t got an account already, follow this article

 

Seeding example data

Then use this to seed your instance with some base data. The tool for seeding data can be found in this repository, as we will use the example seed data found there as well. The documentation on how to use the tool is clear. I chose to load the Simple-B2C.yml file using the example shown in the documentation:

Sitecore OrderCloud Seed Console Output

Please note that the seeding app will automatically create a new marketplace for you.

 

Default Next.js app

Create a default Next.Js App that we can use to implement our Loyalty Program logic, e.g. 

npx create-next-app@latest

Add a simple test page/endpoint  to be used to check the call-backs from OrderCloud to your local app.  Before you do that, install the OrderCloud SDK
Here’s a link to the Git Repo with the code.

I created a simple endpoint like the below, which include a bit of needed security as well:


import { VerifyRequest } from "@/lib/cryptoHelper";
import { baseOrderCloud } from "@/types/ordercloud/requestBodies";
import { NextRequest } from "next/server";

export async function POST(request: NextRequest) {
    if (process.env.REACT_APP_LOGGING === "true") {
        console.log(request.headers);   
        console.log(request.body);   
    }
    var VerificationHeaderName = process.env.VERIFICATION_HEADER as string
    if (!VerifyRequest(
            JSON.stringify(request.body),
            request.headers.get(VerificationHeaderName) as string)  
    )
    {
        if (process.env.REACT_APP_LOGGING === "true") 
            console.log('Unauthorized');
        return Response.json(JSON.parse('{"result":"Unauthorized"}'), { status: 401 })
    }

    const webhookRequest = request.body as unknown as baseOrderCloud;
    switch (webhookRequest.Verb) {
    //case "XXXXX": TODO
    //    break;

    default:
        return Response.json(JSON.parse('{"result":"Default! OK!"}'), { status: 200 })
    }  
}

 

With postman you can now verify that this endpoint gets triggered from a POST Webhook, I’ll leave a postman collection also with all the request I have used for this. For this one, it’s a simple POST to endpoint:

 

http://localhost:3000/api/loyalty/payment

 

I get this result back:

{
    "result": "Unauthorized"
}

 

This is as expected, since I had not passed a security header as described here: Link to OrderCloud documentation. Testing the VerifyRequest is a little hard, so we’ll skip this for now, and will check this later when the Web hooks have been setup in OrderCloud.

 

Ngrok

 

The last thing we want to do to have this initial setup tested – will be to make our locally running Next App publicly available. Without this, OrderCloud will not be able to do the calls/web hooks to our app. The easiest way to do this is to use Ngrok.

 

Go ahead and download ngrok if you don’t already use it. It’s just an awesome tool. Consider if you don’t want to spend a few $ to support the ngrok team and get the benefit of a fixed public URL. If not, your public URL changes every time, you restart and then you must re-configure OrderCloud.

 

Start ngrok locally – and with this running we can again use Postman to call our test endpoint, but this time hitting a publicly available URL: https://moose-chief-hippo.ngrok.app/api/loyalty/payment

 

As expected it shows up in our Ngrok console.

NGrok Console Output

 

At this point, we’re ready to start the actual work on the loyalty program. Stay tuned for the next post!

 

 

OrderCloud & Loyalty Programs

It's not obvious to build a loyalty program using OrderCloud. 

 

What I want to show with these articles are that OrderCloud is extremely flexible for a lot of VERY different use cases - and that is exactly what makes OrderCloud such a strong product.

 

Secondly, I have also seen customers investing in expensive Loyalty Software, that's extremely rigid, batch oriented (who said Oracle Unity and CrowdTwist?) - costing them a fortune in development and consultancy - and still not getting to where they wanted to be. 

 

It might be wise - to look at what software you already have - and see what you can build with that. If your systems are as flexible as OrderCloud, you can get far - really really far - with an impressive ROI. 

Sitecore OrderCloud – Loyalty Program - Part 1