DEV Community

Ali Hamza
Ali Hamza

Posted on

Day 149 of Learning MERN Stack

Hello Dev Community! 👋

It is officially Day 149 of my full-stack engineering track! Today, I crossed one of the biggest milestones for any e-commerce application: Implementing a production-ready Stripe Gateway Checkout & Self-Healing Payment Verification Pipeline (orderController.js)! ⚛️💳🔒

Handling digital money workflows requires an exact architecture. If a payment succeeds, you must unlock the order state and instantly drop the cart contents; if it fails, you must cleanly wipe out the unfulfilled draft order to keep your databases clear of dead records.


🛠️ Deconstructing the Day 149 Payment Architecture

As structured inside my application files visible in "Screenshot (347).png" through "Screenshot (351).jpg", my checkout logic manages transaction lifetimes cleanly:

1. Dynamic Stripe Checkout Sessions Creation

  • As mapped inside the tracking module in "Screenshot (350).jpg", products and structural elements like shipping rates are calculated down to basic subunits (e.g., deliveryCharges * 100 for cents syntax) before generating the redirect:

javascript
  success_url: `${origin}/verify?success=true&orderId=${newOrder._id}` const session = await stripe.checkout.sessions.create({
    success_url: `${origin}/verify?success=true&orderId=${newOrder._id}`,
    cancel_url: `${origin}/verify?success=false&orderId=${newOrder._id}`,
    line_items,
    mode: "payment",
})
Enter fullscreen mode Exit fullscreen mode

Top comments (0)