Skip to content

feat: automated order confirmation emails after checkout#379

Open
swetalin-10 wants to merge 4 commits into
niharika-mente:mainfrom
swetalin-10:feat/order-confirmation-email
Open

feat: automated order confirmation emails after checkout#379
swetalin-10 wants to merge 4 commits into
niharika-mente:mainfrom
swetalin-10:feat/order-confirmation-email

Conversation

@swetalin-10

Copy link
Copy Markdown
Contributor

Fixes #133

What changed

After a successful Stripe checkout, the customer now receives an HTML email receipt automatically.

BACKEND/services/email.service.js (new)

Shared nodemailer transport initialized once at startup from EMAIL_HOST / EMAIL_PORT / EMAIL_USER / EMAIL_PASS env vars. Two exports:

  • sendOrderConfirmationEmail(email, order) — branded receipt with item table, order ID, estimated delivery (+5 days), and total charged
  • sendPasswordResetEmail(email, resetUrl) — ready for the password-reset flow

No SMTP config? The service logs a warning and skips silently — no crashes, no required setup for local dev.

BACKEND/controllers/checkout.controller.js (modified)

After Order.create in the Stripe webhook handler:

  1. Reads session.customer_details.email (always present in Stripe Checkout) — preferred source
  2. Falls back to looking up the user by session.metadata.userId if no Stripe email

The call is non-blocking: .catch() logs the error server-side but never interrupts fulfillment or the 200 { received: true } response Stripe expects.

Email preview

Order confirmation email

Environment variables required

Add to BACKEND/.env:

EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USER=your@gmail.com
EMAIL_PASS=your-app-password
EMAIL_FROM=Product Store <your@gmail.com>   # optional

For Gmail, generate an App Password (2FA must be on). Works with any SMTP provider (SendGrid, Mailgun, etc.) by swapping the host/port.

Testing

  1. Trigger a checkout in Stripe test mode (stripe listen --forward-to localhost:5000/api/checkout/webhook)
  2. Complete payment with card 4242 4242 4242 4242
  3. Check the inbox of the email used during checkout — receipt arrives with items, total, and estimated delivery date
  4. To test without SMTP: omit EMAIL_HOST — server logs [Email] Would send "Order Confirmation…" to … and continues normally

- BACKEND/services/email.service.js: shared nodemailer transport;
  sendOrderConfirmationEmail builds a branded HTML receipt (item table,
  order ID, estimated delivery +5 days, total charged) and sends it;
  also exports sendPasswordResetEmail for the password-reset flow;
  graceful no-op with console.log when SMTP env vars are not set

- BACKEND/controllers/checkout.controller.js: after Order.create in
  the Stripe webhook, fires sendOrderConfirmationEmail using
  session.customer_details.email (preferred, always present in Stripe
  Checkout) with fallback to looking up the User document by userId
  stored in session metadata; email is non-blocking — failures are
  caught and logged, never breaking order fulfillment

- nodemailer added to BACKEND dependencies
@vercel

vercel Bot commented Jun 21, 2026

Copy link
Copy Markdown

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

Resolved add/add conflict in BACKEND/services/email.service.js:
- kept sendOrderConfirmationEmail (this PR)
- kept sendPasswordResetEmail from upstream (niharika-mente#360)
- unified on single createTransporter() factory
Aamod-Dev
Aamod-Dev previously approved these changes Jun 21, 2026

@Aamod-Dev Aamod-Dev 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.

..

Resolved 2 conflicts in checkout.controller.js:
- imports: kept sendOrderConfirmationEmail (this PR) + processReferralOnPurchase (upstream)
- webhook body: kept both post-Order.create blocks — confirmation email and referral reward

@Aamod-Dev Aamod-Dev 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.

Needs changes: There are merge conflicts. Please resolve them.

@swetalin-10

Copy link
Copy Markdown
Contributor Author

Now their is no merge conflicts.

@swetalin-10 swetalin-10 requested a review from Aamod-Dev June 21, 2026 18:42
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.

Feature: Automated Order Confirmation Emails

2 participants