Skip to content

Rewards & Cashback SystemΒ #19

Description

@VisibleNasir

πŸ“˜ Overview

Implement a Rewards & Cashback system to incentivize users with cashback (1–5%), scratch cards, and referral bonuses (β‚Ή50–200).
This drives user engagement, increases transaction frequency, and promotes organic growth through referrals.


πŸ’‘ Why Add It

  • Engagement Boost: Cashback encourages repeat transactions (PhonePe’s model drives +20% volume).
  • Acquisition: Referrals bring in new users with minimal marketing cost.
  • Revenue: More transactions β†’ higher Razorpay MDR earnings (1–2%).

βš™οΈ Implementation

πŸ§‘β€πŸ’» Userapp (Next.js)

  • Page: /app/rewards/page.tsx β†’ Central rewards dashboard.

  • UI Components:

    • Cashback balance display.
    • Recent rewards list.
    • Scratch card animation (react-scratchcard or canvas).
    • Referral input field and share button.
    • Consistent styling: bg-zinc-800, text-zinc-100, border-zinc-700.
  • API Routes:

    • GET /app/api/rewards/fetch β†’ Fetch user rewards and balance.
    • POST /app/api/rewards/scratch β†’ Trigger random scratch reward (β‚Ή10–₹100).
    • POST /app/api/rewards/referral β†’ Validate and credit referral bonuses.
  • Razorpay Integration:

    • For cashback payouts β†’ direct UPI transfer via RazorpayX.
  • State Management:

    • useState β†’ Scratch state, referral code input.
    • TanStack Query β†’ Fetch & refresh reward data dynamically.
  • Error Handling:

    • Invalid inputs β†’ show inline errors (border-red-500, bg-zinc-700).
    • Loading states β†’ disabled:bg-zinc-600/50.

🌐 Webhook (Express)

  • Endpoint: /webhook/reward

  • Trigger Conditions:

    • payment.succeeded
    • referral.completed
  • Logic Flow:

    1. Webhook receives payment event from Razorpay.
    2. Calculate cashback (e.g., 2% of amount).
    3. Insert reward record into DB (type: CASHBACK).
    4. Send notification β†’ /api/notify/push (e.g., β€œYou earned β‚Ή20 cashback!”).
  • Security:

    • Validate Razorpay webhook signature.
    • Rate-limit with express-rate-limit.

πŸ—„οΈ Database (Prisma)

Add to schema.prisma:

model Reward {
  id             Int      @id @default(autoincrement())
  userId         Int
  type           String   // CASHBACK, SCRATCH, REFERRAL
  amount         Int      // in paise
  status         String   // PENDING, CREDITED, FAILED
  transactionId  Int?     // link to Transaction table
  createdAt      DateTime @default(now())
  updatedAt      DateTime @updatedAt
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions