Skip to main content
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 the verifyJWT middleware.

Request Body

string
required
The subscription plan type. Use "pro" for paid plans or "free" for free plan.
number
required
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

boolean
Indicates successful project creation
object
The created project object
string
Project ID
string
User ID of the project owner
null
Null for free plan
string
Defaults to “free”
string
Razorpay order ID (e.g., order_rcptid_0.12345)
number
Order amount in paise (smallest currency unit). Calculated as: months × basePrice × (1 - discount/100)
string
Currency code (always "INR")
string
Order receipt ID
string
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

Calculation Formula

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

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 in init.controller.js:11 and:
  1. Validates the plan parameter
  2. For free plans, creates a project immediately with no payment
  3. 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
  4. 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:
  1. Use the Razorpay Checkout SDK on your frontend to collect payment
  2. On successful payment, Razorpay will provide:
    • razorpay_payment_id
    • razorpay_order_id
    • razorpay_signature
  3. Send these to the Verify Payment endpoint to activate the subscription