Skip to content

fix: product variants cannot be purchased (checkout and webhook)#512

Open
devprashant19 wants to merge 2 commits into
niharika-mente:mainfrom
devprashant19:fix/product-variants-checkout
Open

fix: product variants cannot be purchased (checkout and webhook)#512
devprashant19 wants to merge 2 commits into
niharika-mente:mainfrom
devprashant19:fix/product-variants-checkout

Conversation

@devprashant19

Copy link
Copy Markdown
Contributor

Description

This PR fixes a critical bug where users were unable to purchase product variants. Previously, the checkout logic always checked the baseStock and used basePrice, causing errors and crashes for products with variants.
Fixes #487

Changes

  • BACKEND/controllers/checkout.controller.js:
    • Updated createCheckoutSession to dynamically identify if a product has variants, validate the requested variantId, and correctly use the variant's price and stock.
    • Added variantId tracking into the Stripe session metadata.
    • Updated the stripeWebhook logic to parse the variantId and correctly decrement variants.$.stock instead of baseStock.
    • Updated the restoreStock helper to support restoring variant inventory upon payment failures.

@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown

@devprashant19 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.

Aamod007
Aamod007 previously approved these changes Jul 2, 2026

@Aamod007 Aamod007 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Aamod007 Aamod007 self-requested a review July 2, 2026 17:40
@devprashant19

Copy link
Copy Markdown
Contributor Author

@Aamod007 solved conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] :Product Variants Cannot Be Purchased

2 participants