feat: Promo Codes and Coupon System#375
Merged
Merged
Conversation
Backend: - Coupon model: code (unique, uppercase), type (percentage|flat), value, minOrderAmount, maxUses, usedCount, expiresAt, isActive - POST /api/coupons/validate — public, validates code + cart total, returns discount and final total - POST /api/coupons — admin: create coupon - GET /api/coupons — admin: list all coupons - PATCH /api/coupons/:code/deactivate — admin: soft-deactivate - checkout.controller: accepts optional couponCode, validates it, applies discount by scaling Stripe line item unit_amounts proportionally; stores couponCode in session metadata; webhook increments usedCount after successful payment Frontend (Navbar cart drawer): - Promo code input with Apply button; validates against API - Applied coupon shown as dismissable tag with savings amount - Total section shows strikethrough original + discounted price - couponCode forwarded to /api/checkout on Proceed to Checkout
|
@swetalin-10 is attempting to deploy a commit to the niharika-mente's projects Team on Vercel. A member of the Team first needs to authorize it. |
Collaborator
|
@swetalin-10 can u resolve conflicts |
Resolved conflict in BACKEND/app.js — kept couponRoutes (this PR), newsletterRoutes and analyticsRoutes (upstream)
Aamod-Dev
previously approved these changes
Jun 21, 2026
Aamod-Dev
left a comment
Collaborator
There was a problem hiding this comment.
Looks good, approved!
Resolved conflict in BACKEND/controllers/checkout.controller.js: - kept coupon usedCount increment (this PR) - kept processReferralOnPurchase call (upstream) Both run after Order.create in the Stripe webhook handler.
Aamod-Dev
previously approved these changes
Jun 21, 2026
Aamod-Dev
left a comment
Collaborator
There was a problem hiding this comment.
Looks good, approved!
Resolved conflict in Navbar.jsx handleCheckout: - kept setAppliedCoupon(null) from this PR (clear coupon after checkout) - dropped emptyCart() — SuccessPage already handles it on mount - kept window.location.href = data.url from upstream (Stripe redirect fix)
Aamod-Dev
approved these changes
Jun 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #138
What's changed
Backend
BACKEND/models/coupon.model.js(new)codetype'percentage'|'flat'valueminOrderAmountmaxUsesusedCountexpiresAtisActiveBACKEND/controllers/coupon.controller.js(new)POST /api/coupons/validate— public; checks code validity, expiry, usage limit, and minimum order; returnsdiscountandfinalTotalPOST /api/coupons— admin: create couponGET /api/coupons— admin: list all couponsPATCH /api/coupons/:code/deactivate— admin: soft-deactivateBACKEND/controllers/checkout.controller.jscouponCodealongsideitemsunit_amountproportionally so Stripe sees the correct discounted totalcouponCodeanddiscountAmountin Stripe session metadatausedCountafter successful payment fulfillmentFrontend — Cart Drawer (
Navbar.jsx)Promo code input — visible only when cart has items:
POST /api/coupons/validatewith current cart totalUpdated totals section:
couponCodeforwarded toPOST /api/checkouton proceedCreating coupons (admin)
Screenshots
Entering a promo code
After applying — discount reflected in total