Razorpay Payment Gateway Integration Template#1969
Razorpay Payment Gateway Integration Template#1969AchuAshwath wants to merge 4 commits intofastapi:masterfrom
Conversation
… pnpm and uv for development
- Add payment models, CRUD functions, and Razorpay service - Add payment API routes and frontend components - Add database migration for payment tables - Add .gitignore entry for .env - Add .env.example with placeholder Razorpay keys - Keep upstream-contribution README style
|
@AchuAshwath, thanks for your work. Why should this razorpayment, as a special service code, be part of a general fastapi template like this repository is good for? From my point of view, it makes more sense that you maintain a up to date branch with this feature under your name. Cheers, |
|
Now that i think about it more, your point makes more sense @stevleibelt . I was thinking, any web application thats being developed has a goal of being monetised, so I thought for a massive starter template like this repo would benefit from having a ready to configure payment integration, because I would like a repo to be like this. My goal was to implement many payment services, not just razorpayment but to include many more widely used payment gateways - it would make the general template more complex and add unwanted scope to the project. if the scope is ready to be be explored, How should I make this a more compelling addition to the project? Thanks for being nice even though I gave slop of a PR 🤣 , I am just starting out with Open source contribution. If you would like to nudge me on better path I would really appreciate it. Cheers, |
|
@AchuAshwath being nice pays of in the long run. Thank you to for noticing the choice of my words. Since I am not a project maintainer, I am not in the power to guide you the right way. Maybe, this project has reached a size that it make sense to create a "list of cool projects/additional implementations" file. This created file contains of links to other branches like yours to show how easy it is to implement things like your payment service.
Again, thanks for your work and welcome to the world of open source :-). Have a great day, |
|
I'll keep my repo up to date with the payment implementation, thank you for being such a chad. it was nice knowing you @stevleibelt and also I used to use arch btw 🥂 |
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.