Feature #10237
openFix E-Commerce Loyalty Points Redemption, Stripe Total Sync, API Performance, and Admin Reward Statistics for Orders
Subtasks
Related issues
Updated by Ajit A 1 day 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 (ajthor@yopmail.com).
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
Updated by Ajit A about 5 hours 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