Documentation Index
Fetch the complete documentation index at: https://docs.deployhub.cloud/llms.txt
Use this file to discover all available pages before exploring further.
This endpoint initializes a subscription payment by creating a Razorpay order. It calculates the final amount based on the selected plan and duration, applying volume discounts automatically.
Authentication
Requires JWT authentication via the verifyJWT middleware.
Request Body
The subscription plan type. Use "pro" for paid plans or "free" for free plan.
Subscription duration in months. Required for paid plans. Valid options:
1 - 1 month (0% discount)
3 - 3 months (4% discount)
6 - 6 months (8% discount)
12 - 12 months (10% discount)
24 - 24 months (15% discount)
Response
Free Plan Response
Indicates successful project creation
The created project objectUser ID of the project owner
Paid Plan Response (Razorpay Order)
Razorpay order ID (e.g., order_rcptid_0.12345)
Order amount in paise (smallest currency unit). Calculated as: months × basePrice × (1 - discount/100)
Currency code (always "INR")
Order status (e.g., "created")
Pricing Calculation
The Pro plan uses the following pricing structure from planPrice.js:1:
- Base Price: ₹799.00/month (79900 paise)
- Discounts by Duration:
- 1 month: 0% discount → ₹799
- 3 months: 4% discount → ₹2,300.64
- 6 months: 8% discount → ₹4,417.92
- 12 months: 10% discount → ₹8,629.20
- 24 months: 15% discount → ₹16,297.20
finalAmount = months × basePrice × (1 - discount / 100)
Database Records
On successful Razorpay order creation, a PendingOrder record is created:
userid: Authenticated user ID
oderid: Razorpay order ID
months: Subscription duration
amount: Final calculated amount
plan: Always "pro" for paid plans
status: "pending"
createdAt: Auto-expires after 2 hours (7200 seconds)
Pending orders automatically expire after 2 hours if payment is not completed.
Request Examples
Free Plan
curl -X POST https://api.deployhub.com/api/subscription/init \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"plan": "free"
}'
Pro Plan - 1 Month
curl -X POST https://api.deployhub.com/api/subscription/init \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"plan": "pro",
"months": 1
}'
Pro Plan - 12 Months (10% Discount)
curl -X POST https://api.deployhub.com/api/subscription/init \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"plan": "pro",
"months": 12
}'
Response Examples
Free Plan Success
{
"success": true,
"project": {
"_id": "507f1f77bcf86cd799439011",
"owner": "507f191e810c19729de860ea",
"paymentId": null,
"plan": "free",
"createdAt": "2026-03-04T10:30:00.000Z",
"updatedAt": "2026-03-04T10:30:00.000Z"
}
}
Pro Plan Success (Razorpay Order)
{
"id": "order_rcptid_0.8347562",
"entity": "order",
"amount": 862920,
"amount_paid": 0,
"amount_due": 862920,
"currency": "INR",
"receipt": "order_rcptid_0.8347562",
"status": "created",
"attempts": 0,
"notes": [],
"created_at": 1709548200
}
Error Responses
Missing Plan
{
"message": "Plan is required"
}
Missing Months for Paid Plan
{
"message": "Months required for paid plans"
}
Invalid Plan
{
"message": "Invalid plan"
}
Razorpay Error
{
"error": "Error creating Razorpay order"
}
Implementation Details
The endpoint is implemented in init.controller.js:11 and:
- Validates the plan parameter
- For free plans, creates a project immediately with no payment
- For paid plans:
- Validates the months parameter
- Retrieves pricing from
planPrice.js
- Calculates discount based on duration
- Creates Razorpay order
- Stores pending order in database
- Returns the appropriate response
The final amount is converted to an integer using parseInt(), which may cause precision issues. Ensure the calculation months * basePrice * (1 - discount / 100) results in a whole number.
Next Steps
After receiving the Razorpay order details:
- Use the Razorpay Checkout SDK on your frontend to collect payment
- On successful payment, Razorpay will provide:
razorpay_payment_id
razorpay_order_id
razorpay_signature
- Send these to the Verify Payment endpoint to activate the subscription