Building a Loyalty Points System
Learn how to implement a loyalty points system with Blnk.
Overview
In this tutorial, we will build a simple loyalty points system using the Blnk Ledger. Here’s what we’ll do:
- Create and manage multi-asset wallets in your ledger.
- Manage a pool of issued loyalty points.
- Award points to customers when they make purchases.
- Allow customers to redeem their points for discounts on future purchases.
Designing your map
Before writing code, it’s crucial to design a money movement map that outlines how money moves in your system. This serves as the blueprint for your implementation.
For our loyalty points system, we have two workflows — awarding points and redeeming points.
-
Awarding points:
Points are awarded to customers who qualify for the loyalty program. A customer purchase triggers the process: funds from the
Customer Main Wallet
are used for the purchase, contributing to@RevenueUSD
.Once the purchase is completed, points are awarded from the
@PointsPool
to theCustomer Points Wallet
.@RevenueUSD
: An internal balance representing the business’ revenue.@PointsPool
: An internal balance tracking the total points issued to customers.
-
Redeeming points:
Customers can redeem points to receive discounts on purchases. When a customer applies points to a transaction, the discount is deducted from the original price.
Once the purchase is completed, the redeemed points are transferred from the
Customer Points Wallet
to@PointsPool
.
@PointsPool
records all issued points using the debit_balance
parameter and tracks all redeemed points using the credit_balance
parameter.
Set up your implementation
Based on our map, we’ll implement the following:
- Create the main and points balances for the customer.
- Initiate a purchase transaction and award points to the customer.
- Redeem the points in a second purchase transaction.
Prerequisites
Before starting, ensure you have:
- A running Blnk server instance (e.g. at
http://localhost:5001
). - An API key for Blnk (replace
YOUR_API_KEY
in the code examples). Required for authenticated requests. - The Blnk CLI installed or a connected Blnk Cloud workspace to view your ledger data.
Create your ledgers
First, we need to create ledgers to organize our wallets::
Create balances for customer funds and loyalty points
Blnk Finance supports tracking of different assets (e.g., USD and POINTS) in your ledger.
Now, let’s create the main wallet and points wallet for the customer:
Awarding points after a purchase
When a customer makes a purchase, we need to:
- Process the payment from the customer’s main wallet to the revenue account.
- Award loyalty points based on the purchase amount.
Ensure your customer main wallet is funded. Learn how: Wallet Funding →
As shown above, you can set custom precision for each currency, like 100 for USD or 1 for POINTS in our example.
For ledger accuracy, ensure the source and destination currencies match when posting transactions.
Redeeming points during a purchase
When you make a purchase, you can use your loyalty points to get a discount. In our example, 10 points = 1 USD.
For example, a customer has 500 points and wants to buy something that costs $100:
- They choose to use 200 points from their
Points Wallet
. - Those 200 points convert to $20 (at the 10 points = $1 rate)
- Their final cost to pay from their
Main Wallet
would be $80 instead of $100.
Behind the scenes, here’s what we’ll do:
- Take points from the
Customer Points Wallet
to@PointsPool
. - Convert the points to its equivalent dollar value, apply it as discount, and calculate the final cost for the customer.
- Charge the
Customer Main Wallet
with the final discounted cost.
Conclusion
You now have a basic loyalty points system built with the Blnk Ledger. This system enables you to award points to customers based on their purchases and allows them to redeem those points for discounts.
The system is flexible and can be extended with additional features like:
- Points expiry management
- Tiered rewards based on customer spending levels
- Special promotions with bonus points
- Point transfers between customers
By leveraging Blnk’s transaction system, you can ensure all point movements are accurately tracked and reconciled, providing a reliable foundation for your loyalty program.
Can’t find your use case?
If you’re searching for a specific tutorial that isn’t included here, you’re welcome to contribute to our documentation by sharing your expertise or requesting a new tutorial in our Discord community.
We’re always thrilled to expand our resources with the help of our developer community!