The LMS Backend uses Stripe Checkout to process course purchases. The flow works in three steps: your client calls the create-checkout-session endpoint to get a Stripe session URL, the student completes payment on Stripe’s hosted page, and Stripe calls the webhook endpoint to confirm the charge. TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Pragyat-Nikunj/Learning-Management-System-backend/llms.txt
Use this file to discover all available pages before exploring further.
CoursePurchase document starts in pending status and is updated to completed or failed based on the Stripe charge.succeeded or charge.failed event.
All payment endpoints are prefixed with
/api/v1/payments. Set STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET in your environment before using these endpoints. See Environment Setup for the full variable list.POST /api/v1/payments/create-checkout-session
Create a Stripe Checkout session for a course purchase. The server looks up the course price, creates the Stripe session inpayment mode, and records a CoursePurchase document with status: "pending". The Stripe session URL is returned in the response for your client to redirect the student to.
Auth required: Yes
Request body
MongoDB ObjectId of the course the student wants to purchase.
Response — 201
true on success."Stripe checkout initiated successfully."Errors
| Status | Condition |
|---|---|
401 | Missing or invalid auth cookie |
404 | Course not found |
500 | Stripe session creation failed |
POST /api/v1/payments/webhook
Receive and process Stripe webhook events. This endpoint must receive the raw request body (not JSON-parsed) so that Stripe’s signature verification can succeed. The route usesexpress.raw({ type: 'application/json' }) middleware for this reason.
Auth required: No — secured by Stripe signature verification using STRIPE_WEBHOOK_SECRET.
Headers
The
Stripe-Signature header set by Stripe on every webhook delivery. Used to verify the event payload has not been tampered with.Handled event types
charge.succeeded
charge.succeeded
Fired when a payment charge is successfully captured. The handler finds the matching
CoursePurchase record by paymentId (the charge ID) and updates its status to "completed".charge.failed
charge.failed
Fired when a payment charge fails. The handler finds the matching
CoursePurchase record by paymentId and updates its status to "failed".Response — 200
200 response is always returned once the event is acknowledged, even for unhandled event types. This tells Stripe not to retry delivery.
Errors
| Status | Condition |
|---|---|
400 | Stripe signature verification failed (wrong secret, tampered body, or body was pre-parsed) |
GET /api/v1/payments/courses/:courseId/purchase-status
Check whether the authenticated user has purchased a specific course and what the current status of that purchase is. Auth required: YesPath parameters
MongoDB ObjectId of the course to check.
Response — 200
"success"Example 200 response — completed purchase
Errors
| Status | Condition |
|---|---|
401 | Missing or invalid auth cookie |
404 | Course not found |
GET /api/v1/payments/purchased-courses
Retrieve all courses the authenticated user has purchased with a"completed" status. Results are sorted by most recently purchased and include the course title, description, and price.
Auth required: Yes
Response — 200
"success"Example 200 response
Errors
| Status | Condition |
|---|---|
401 | Missing or invalid auth cookie |