Creates a Stripe payment intent to initiate the payment flow for content purchase. This endpoint verifies the content exists, checks for duplicate purchases, and creates a pending purchase record.
Authentication
Requires authentication. Include the JWT token in the Authorization header.
Request Body
The MongoDB ObjectId of the content to purchase
Response
Stripe client secret for completing the payment on the frontend. Pass this to Stripe Elements or Stripe.js to collect payment details.
The purchase amount in USD (dollars, not cents)
The created Stripe payment intent includes the following metadata:
contentId - The MongoDB ObjectId of the content
userId - The MongoDB ObjectId of the purchasing user
contentTitle - The title of the content being purchased
Payment Flow
Client calls this endpoint with contentId
Server validates content exists and is published
Server checks user hasn’t already purchased the content
Server creates Stripe payment intent with amount in cents (price × 100)
Server creates pending Purchase record in database
Client receives clientSecret to complete payment
User completes payment using Stripe on frontend
Stripe sends webhook to /api/payments/webhook
Server updates Purchase status to completed
Validation
Content must exist and have status published
User cannot purchase the same content twice
User must be authenticated
curl -X POST https://api.vaniykempire.com/api/payments/create-payment-intent \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"contentId": "507f1f77bcf86cd799439011"
}'
200 Success
404 Content Not Found
400 Already Purchased
500 Server Error
{
"clientSecret" : "pi_3MtwBwLkdIwHu7ix28a3tqPa_secret_YrKJUKribcBjcG8HVhfZluoGH" ,
"amount" : 29.99
}
Error Codes
Status Code Description 200 Payment intent created successfully 400 Content already purchased by user 401 Not authenticated 404 Content not found or not published 500 Server error or Stripe API error
Implementation Notes
Currency is hardcoded to USD
Stripe amounts are in cents (price is multiplied by 100)
A pending Purchase record is created immediately
The Purchase status is updated to completed via webhook when payment succeeds
Source: src/controllers/paymentController.js:6-61