Project

General

Profile

Edit Copy Actions

Feature #10237

open

Fix E-Commerce Loyalty Points Redemption, Stripe Total Sync, API Performance, and Admin Reward Statistics for Orders

Added by Ajit A about 21 hours ago. Updated 2 minutes ago.

Status:
In Progress
Priority:
Normal
Assignee:
Target version:
-
Start date:
08/05/2026
Due date:
% Done:

100%

Estimated time:
12:00 h
Spent time:

Add

Subtasks


Add

Related issues

Updated by Ajit A about 21 hours ago

  • % Done changed from 0 to 60

Resolved issues with E-commerce loyalty reward points redemption where points were not reflecting in Stripe Gateway totals, API performance was degraded, and redeemed points were not deducting from Customer Reward Statistics and Reward Points Ledger in the Admin Dashboard

1. Stripe Checkout Total & Discount Synchronization
Files Modified:

payment.service.js

shop-controller.js
Changes:
Integrated loyaltyDiscount with promo coupon discounts in processPaymentForOrder so Stripe Gateway displays the Reward Points Discount line item and charges the exact reduced total.
Added robust multi-key body parsing (pointsToRedeem, redeemPoints, loyaltyDiscount, rewardDiscount) with automatic points-to-currency inter-derivation ($\text{Points} = \text{Discount} \times 100$).
Ensured pointsToRedeem and loyaltyDiscount propagate from PendingCheckout to OrderModel during session sync.
2. API Performance Optimization (<50ms)
Files Modified:

loyaltyProgram.service.js
Changes:
Removed heavy synchronous 50-order database query loop in listTenantLoyaltyAccounts.
Reduced GET /api/v1/loyalty/customers response time from 3,553ms to <50ms.
3. Customer Resolution & Wallet Synchronization
Files Modified:

sale.service.js
Changes:
Client Resolution Helper (resolveLoyaltyClientId): Created helper to resolve the customer's primary profile in ClientModel by checking customerId AND email (customerEmail). This fixed a bug where points were being debited from temporary orphan IDs instead of the customer's main account ().
Idempotency Query Guard: Fixed blank-string matching in $or idempotency query in processLoyaltyEcomCheckout and processLoyaltyEcomEarning.
Payment Status Filter: Enforced payment_status === "completed" || payment_status === "paid" in processLoyaltyEcomEarning to prevent premature point earning on pending/unpaid orders.
Ledger Email Persistence: Saved guestEmail on debitLedger records during checkout redemption.
4. Dual-Index Ledger & Wallet Aggregation
Files Modified:

loyaltyProgram.service.js
Changes:
Refactored listTenantLoyaltyAccounts to index wallets and ledger entries by Client ID AND Customer Email.
Synchronized the mathematical formula: $$\text{Balance} = \max(0, \text{Earned Points} - \text{Redeemed Points})$$
Ensured Redeemed points and Balance update accurately across Admin Dashboard tables

Actions #2

Updated by Ajit A about 21 hours ago

  • Status changed from New to In Progress

Updated by Ajit A 2 minutes ago

  • % Done changed from 60 to 100

Completed for orders

Actions #4

Updated by Ajit A 2 minutes ago

  • Subject changed from Fix E-Commerce Loyalty Points Redemption, Stripe Total Sync, API Performance, and Admin Reward Statistics to Fix E-Commerce Loyalty Points Redemption, Stripe Total Sync, API Performance, and Admin Reward Statistics for Orders
Edit Copy Actions

Also available in: Atom PDF