DEV Community

Warun C. ⚡
Warun C. ⚡

Posted on

5 3 2 1 1

Elevate Loyalty: Minting Polygon-Based Rewards with Wix Backend Events

This is a submission for the Wix Studio Challenge .

What I Built

I've developed an innovative loyalty program platform using Wix Studio and Velo (Service Plugins). This platform incentivizes user engagement and fosters brand loyalty through:

  • Polygon-Based Rewards: Users earn loyalty points in the form of Polygon tokens, offering them real value and the ability to participate in the wider Web3 ecosystem.
  • Event-Driven Minting: Points are minted automatically when users complete actions like making purchases, submitting reviews, or referring friends.
  • Gamified Experience: The platform encourages participation with a tiered rewards system and exciting redemption options.

Demo

https://ubinix5warun.wixstudio.io/wix-x-devto-airdrop

Development Journey

Purpose of onCheckoutCompleted()

This event is your golden ticket to trigger actions right after a customer successfully completes a purchase on your Wix store. It's a crucial point to:

  • Award Loyalty Points: Calculate and mint loyalty tokens on the Polygon blockchain based on the purchase amount or specific items bought.
  • Update User Balances: Increase the customer's loyalty point balance in your Wix database.
  • Trigger Personalized Messages: Send a thank-you email or notification, potentially including the newly earned loyalty point amount.
  • Analyze Purchase Data: Gather data for insights into purchasing trends, which can help refine your loyalty program.

Code Example (Velo - Backend):

import wixData from 'wix-data';
import { mintLoyaltyTokens } from 'backend/polygon-api'; // Your custom Polygon interaction module

export function wixEcom_onCheckoutCompleted(event) {
  const { checkout } = event;
  const customerId = checkout.buyerInfo.memberId; 
  const totalAmount = checkout.totals.total;

  // 1. Calculate Loyalty Points (Example logic: 1 point per $10 spent)
  const pointsEarned = Math.floor(totalAmount / 10);

  // 2. Mint Loyalty Tokens on Polygon (Assuming you have this function)
  mintLoyaltyTokens(customerId, pointsEarned);

  // 3. Update User's Loyalty Points in Database
  wixData.query("Members")
    .eq("_id", customerId)
    .find()
    .then((results) => {
      const member = results.items[0];
      member.loyaltyPoints += pointsEarned;
      wixData.update("Members", member);
    });

  // 4. (Optional) Trigger Personalized Email/Notification
  // ... (using Wix Automations or a 3rd-party service)
}
Enter fullscreen mode Exit fullscreen mode

How to Set Up

  • Backend Function: Create the wixEcom_onCheckoutCompleted function in a backend module (e.g., backend/events.js).
  • Event Registration: Register this function as an event handler in your site's backend (Wix dashboard -> Velo -> Backend).
  • Polygon Interaction: Develop the mintLoyaltyTokens function (or equivalent) to interact with your Polygon smart contract and mint the loyalty tokens.
  • Database: Ensure you have a "Members" collection in your Wix database to store user loyalty points.

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay