Initialize Subscription Payment
Subscriptions
Initialize Subscription Payment
Create a Razorpay order for subscription payment with automatic discount calculation
POST
Initialize Subscription Payment
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 theverifyJWT 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
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 receipt ID
Order status (e.g.,
"created")Pricing Calculation
The Pro plan uses the following pricing structure fromplanPrice.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
Calculation Formula
Database Records
On successful Razorpay order creation, aPendingOrder record is created:
userid: Authenticated user IDoderid: Razorpay order IDmonths: Subscription durationamount: Final calculated amountplan: Always"pro"for paid plansstatus:"pending"createdAt: Auto-expires after 2 hours (7200 seconds)
Request Examples
Free Plan
Pro Plan - 1 Month
Pro Plan - 12 Months (10% Discount)
Response Examples
Free Plan Success
Pro Plan Success (Razorpay Order)
Error Responses
Missing Plan
Missing Months for Paid Plan
Invalid Plan
Razorpay Error
Implementation Details
The endpoint is implemented ininit.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
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_idrazorpay_order_idrazorpay_signature
- Send these to the Verify Payment endpoint to activate the subscription