Skip to main content
POST
/
api
/
payments
/
create-payment-intent
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"
  }'
{
  "clientSecret": "pi_3MtwBwLkdIwHu7ix28a3tqPa_secret_YrKJUKribcBjcG8HVhfZluoGH",
  "amount": 29.99
}
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

contentId
string
required
The MongoDB ObjectId of the content to purchase

Response

clientSecret
string
Stripe client secret for completing the payment on the frontend. Pass this to Stripe Elements or Stripe.js to collect payment details.
amount
number
The purchase amount in USD (dollars, not cents)

Payment Intent Metadata

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

  1. Client calls this endpoint with contentId
  2. Server validates content exists and is published
  3. Server checks user hasn’t already purchased the content
  4. Server creates Stripe payment intent with amount in cents (price × 100)
  5. Server creates pending Purchase record in database
  6. Client receives clientSecret to complete payment
  7. User completes payment using Stripe on frontend
  8. Stripe sends webhook to /api/payments/webhook
  9. 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"
  }'
{
  "clientSecret": "pi_3MtwBwLkdIwHu7ix28a3tqPa_secret_YrKJUKribcBjcG8HVhfZluoGH",
  "amount": 29.99
}

Error Codes

Status CodeDescription
200Payment intent created successfully
400Content already purchased by user
401Not authenticated
404Content not found or not published
500Server 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

Build docs developers (and LLMs) love