Overview
The Payments API integrates with Razorpay to handle premium template purchases. It provides endpoints for creating payment orders and verifying payment signatures.All payment endpoints require authentication. Include your Clerk JWT token in the
Authorization header.Create Payment Order
Create a Razorpay order for purchasing a premium template.Headers
Bearer token from Clerk authentication
Must be
application/jsonRequest Body
The name/title of the template to purchaseExample:
"Modern Portfolio", "Developer Showcase"Currency for the transaction
INR- Indian RupeeUSD- US Dollar
Response
true if order created successfully, false otherwiseHuman-readable status message
Razorpay order details (only present on success)
Example Request
Success Response
Status: 201 CreatedAmount is in smallest currency unit:
- INR: 49900 paise = ₹499
- USD: 999 cents = $9.99
Error Responses
Unauthorized
Status: 401 UnauthorizedInvalid Parameters
Status: 400 Bad RequestTemplate Not Found
Status: 404 Not FoundFree Template
If you try to create an order for a free template: Status: 200 OKOrder Creation Failed
Status: 200 OKServer Error
Status: 500 Internal Server ErrorVerify Payment
Verify the payment signature after user completes payment on Razorpay.Headers
Bearer token from Clerk authentication
Must be
application/jsonRequest Body
The Razorpay order ID from the create-order response
The Razorpay payment ID returned after successful payment
The payment signature generated by Razorpay
Response
true if payment verified successfully, false otherwiseHuman-readable status message
Example Request
Success Response
Status: 200 OK- The template is added to the user’s purchased templates
- The payment record is updated with
SUCCESSstatus - The user can now use the premium template
Error Responses
Unauthorized
Status: 401 UnauthorizedInvalid Parameters
Status: 400 Bad RequestVerification Failed
Status: 403 Forbidden- Invalid signature
- Payment ID doesn’t match order
- Tampered payment data
- Payment was not successful
Server Error
Status: 500 Internal Server ErrorPayment Flow
The complete payment flow involves multiple steps:Step 1: Create Order
Create a Razorpay order on your server:Step 2: Initialize Razorpay Checkout
Use the Razorpay client SDK to collect payment:Step 3: Verify Payment
After user completes payment, verify the signature:Complete Integration Example
Template Pricing
Templates have different pricing based on category:- Free Templates: No payment required, category =
"Free" - Premium Templates: Require payment, have both INR and USD pricing
- Rejects payment creation for free templates
- Selects the correct pricing based on currency
- Converts to smallest unit (paise/cents) for Razorpay
Payment Records
All payments are tracked in the database with the following statuses:Payment status in the database
PENDING- Order created, payment not yet completedSUCCESS- Payment verified successfullyFAILED- Payment failed or verification failed
Security Best Practices
Never trust client-side verification
Never trust client-side verification
Always verify payment signatures on the server:
- Client sends payment response to server
- Server verifies signature using Razorpay secret
- Only grant access after server verification
Validate order ownership
Validate order ownership
The API automatically checks:
- User is authenticated
- Order belongs to the authenticated user
- Payment ID matches the order
Handle webhooks (future)
Handle webhooks (future)
For production, implement Razorpay webhooks to:
- Get payment confirmation asynchronously
- Handle failed payments
- Process refunds
- Update subscription status
Never expose Razorpay secret
Never expose Razorpay secret
- Keep Razorpay secret key on server only
- Use key ID on client-side only
- Don’t log sensitive payment data
Testing
Test Mode
Razorpay provides test mode for development:- Use test API keys (starts with
rzp_test_) - Use test card numbers for payments
- No real money is charged
Test Cards
Razorpay test card numbers: Successful Payment:- Card:
4111 1111 1111 1111 - CVV: Any 3 digits
- Expiry: Any future date
- Card:
4000 0000 0000 0002 - CVV: Any 3 digits
- Expiry: Any future date
Currency Support
Currently supported currencies:| Currency | Code | Smallest Unit |
|---|---|---|
| Indian Rupee | INR | Paise (1/100) |
| US Dollar | USD | Cents (1/100) |
- Add pricing columns to Template model
- Update create-order logic
- Configure Razorpay account for multi-currency