Payments
Refund Payment
Admin endpoint to process refunds for completed purchases
POST
Administrator endpoint for issuing refunds on completed purchases. Creates a refund in Stripe and updates the purchase status to
refunded.
Authentication
Requires authentication with administrator privileges.Path Parameters
The MongoDB ObjectId of the purchase to refund. Must be a completed purchase.
Refund Rules
- Only purchases with status
completedcan be refunded - Cannot refund purchases that are
pending,failed, or alreadyrefunded - Refund is processed through Stripe’s refund API
- Full amount is refunded (partial refunds not supported)
- Purchase status is updated to
refundedupon success
Response
Success message confirming the refund
Updated purchase object with
refunded statusStripe Refund Process
- Endpoint receives refund request with
purchaseId - Server validates purchase exists and has status
completed - Server calls Stripe refund API:
stripe.refunds.create({ payment_intent: stripePaymentIntentId }) - Stripe processes full refund to original payment method
- If Stripe refund succeeds, purchase status updated to
refunded - Refunded amount returns to customer’s card in 5-10 business days
Stripe Refund Details
- Refund amount: Full payment amount (partial refunds not supported)
- Refund destination: Original payment method
- Refund timeline: 5-10 business days for card refunds
- Stripe fees: Stripe fees are not returned for refunds
- Refund status: Must be
succeededfor purchase to be marked as refunded
Error Scenarios
| Scenario | Status Code | Error Message |
|---|---|---|
| Purchase not found | 404 | ”Purchase not found” |
| Purchase is pending | 400 | ”Only completed purchases can be refunded” |
| Purchase is failed | 400 | ”Only completed purchases can be refunded” |
| Already refunded | 400 | ”Only completed purchases can be refunded” |
| Stripe refund fails | 400 | ”Refund failed” |
| Not authenticated | 401 | ”Not authenticated” |
| Not admin | 403 | ”Admin access required” |
| Server error | 500 | Error message details |
Refund Limitations
Best Practices
- Verify purchase details before refunding
- Document refund reason in admin logs or external system
- Notify the customer about the refund via email
- Check Stripe Dashboard to confirm refund processed
- Consider partial refunds for specific use cases (requires code modification)
Use Cases
- Customer requests refund for purchased content
- Content was incorrectly charged
- Quality issues with content
- Duplicate purchase by user
- Accidental purchase
- Customer service resolution
Notifications
This endpoint does NOT automatically notify users. Implement email notifications separately to inform customers about refunds.
Idempotency
Calling this endpoint multiple times on the same purchase:- First call: Creates refund, updates status to
refunded, returns success - Subsequent calls: Returns 400 error “Only completed purchases can be refunded”
Stripe Dashboard
After issuing a refund:- Go to Stripe Dashboard → Payments
- Search for payment intent ID
- View refund details and status
- Monitor refund completion
Related Endpoints
- List All Payments - Find purchases to refund
- Get Payment Status - Verify purchase status
- Create Payment Intent - How purchases are created
Implementation Notes
- Requires
authenticateandrequireAdminmiddleware - Full refund only (entire payment intent amount)
- User and content fields are not populated in response
- Refund is synchronous (waits for Stripe response)
- Stripe refund status must be
succeededfor purchase update - Source:
src/controllers/paymentController.js:182-217
Testing
Test Mode
Use Stripe test mode to test refunds without real money:Test Cards
Stripe provides test cards that simulate different refund scenarios:4242 4242 4242 4242- Successful refunds4000 0000 0000 0259- Successful charges with dispute risk
Monitoring
Track refund metrics:- Total refunds per month
- Refund rate (refunds / total purchases)
- Average refund amount
- Common refund reasons (requires manual tracking)
- Refund processing time