Razorpay Payment Gateway Integration Template #1969
                
     Closed
            
            
          
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Summary
This PR adds Razorpay payment gateway integration to the Full Stack FastAPI Template, enabling one-time payments with complete frontend checkout UI, payment verification, and webhook handling.
What's Added
Backend
Payment API Endpoints (
/api/v1/payments/*):POST /create-order- Create Razorpay orders and save to databasePOST /verify- Verify payment signaturesPOST /webhook- Handle Razorpay webhook eventsGET /orders- List user orders (paginated)GET /orders/{order_id}- Get order detailsDatabase Models:
Ordermodel - Stores payment orders with Razorpay order IDsPaymentmodel - Stores payment records linked to ordersServices:
RazorpayService- Encapsulates Razorpay API interactionsConfiguration:
RAZORPAY_KEY_ID,RAZORPAY_KEY_SECRET,RAZORPAY_WEBHOOK_SECRETFrontend
Payment Components:
/checkout) with integrated payment form and analytics dashboardIntegration:
Key Features
✅ Complete Payment Flow: Order creation → Razorpay checkout → Signature verification → Database updates
✅ Secure: Payment signature verification using Razorpay's secure hash
✅ Webhook Support: Real-time payment status updates via webhooks
✅ Analytics: Built-in payment dashboard showing totals, success rates, and history
✅ Type-Safe: Full TypeScript support with auto-generated API client
✅ Optional: Gracefully handles missing Razorpay configuration (returns 503)
Breaking Changes
None - This is a purely additive feature. Existing functionality remains unchanged.
Testing
Prerequisites
.env:Test Steps
docker compose watch/checkoutpage4111 1111 1111 1111Test Cards
4111 1111 1111 11114000 0000 0000 0002Files Changed
Backend
backend/app/models.py- Added Order and Payment modelsbackend/app/crud.py- Added payment CRUD operationsbackend/app/api/routes/payments.py- New payment endpointsbackend/app/services/razorpay_service.py- Razorpay service wrapperbackend/app/core/config.py- Added Razorpay configurationbackend/app/api/main.py- Registered payments routerbackend/pyproject.toml- Addedrazorpaydependencybackend/app/alembic/versions/7c4cf1d2308a_add_payment_models.py- Database migrationFrontend
frontend/src/components/Payments/Checkout.tsx- Checkout page componentfrontend/src/components/Payments/PaymentSuccess.tsx- Success pagefrontend/src/components/Payments/PaymentFailure.tsx- Failure pagefrontend/src/components/Payments/PaymentAnalytics.tsx- Analytics componentfrontend/src/routes/_layout/checkout.tsx- Checkout routefrontend/src/routes/payment-success.tsx- Success routefrontend/src/routes/payment-failure.tsx- Failure routefrontend/src/components/Common/SidebarItems.tsx- Added checkout navigationfrontend/index.html- Added Razorpay Checkout.js scriptfrontend/src/vite-env.d.ts- Added Razorpay type definitionsDocumentation
README.md- Added payment integration sectionbackend/README.md- Added payment API documentation and migration guideDocumentation
Dependencies Added
razorpay>=1.4.2(Python package)Checklist
Notes
This enables teams to quickly add payment capabilities to their FastAPI applications without building the integration from scratch.