Fix net_amount double-deducting GST on Razorpay gateway fees#27
Open
TheShahnawaaz wants to merge 1 commit into
Open
Fix net_amount double-deducting GST on Razorpay gateway fees#27TheShahnawaaz wants to merge 1 commit into
TheShahnawaaz wants to merge 1 commit into
Conversation
Razorpay's payment object returns two fields: - `fee`: total amount deducted from settlement (base fee + GST, inclusive) - `tax`: the GST portion, which is already contained within `fee` The previous calculation subtracted both, causing net_amount to be understated by the GST amount on every confirmed payment: Before: net_amount = amount - fee - tax (GST counted twice) After: net_amount = amount - fee (correct) This made every financial report show a lower "Net received" than what Razorpay actually settled. The discrepancy per trip was exactly equal to the sum of gateway_tax across all confirmed payments. Changes: - payment.service.ts: fix net_amount calculation in all three paths (verify flow, webhook pending→confirmed, webhook already-confirmed) - 021_create_reports_module.sql: fix fallback formula in report_financials view for payments where net_amount is NULL, and fix total_gateway_deductions in reports_summary view (was summing gateway_fees + gateway_tax, double-counting) - 014_add_payment_fee_columns.sql: correct the net_amount column comment - ReportDetailPage.tsx: fix "Gateway fees" display to show gateway_fees only (not gateway_fees + gateway_tax), making the breakdown consistent with the actual settlement deduction
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Fixes incorrect “net received” calculations by removing a double-deduction of GST (tax) on Razorpay gateway fees across backend payment flows, reporting SQL views, and the admin report UI—aligning stored/reporting values with Razorpay settlements.
Changes:
- Backend: compute
net_amountasamount - fee(since Razorpayfeealready includes GST) in verification + webhook paths. - SQL: update
report_financialsandreports_summaryviews to stop subtracting/aggregatinggateway_taxon top ofgateway_fee. - Frontend: display “Gateway fees” as
gateway_feesonly (no longergateway_fees + gateway_tax).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| frontend/src/pages/admin/reports/ReportDetailPage.tsx | Updates gateway fees line item to match the corrected definition of deductions (avoid adding GST twice). |
| backend/src/services/payment/payment.service.ts | Fixes net_amount calculation in verify + webhook flows to avoid double-deducting GST. |
| backend/migrations/021_create_reports_module.sql | Fixes report views’ fallback and summary aggregations to avoid double-counting GST in deductions/net revenue. |
| backend/migrations/014_add_payment_fee_columns.sql | Updates net_amount column documentation to reflect the corrected calculation. |
Comment on lines
15
to
16
| COMMENT ON COLUMN payments.gateway_fee IS 'Payment gateway fee in paise'; | ||
| COMMENT ON COLUMN payments.gateway_tax IS 'GST on gateway fee in paise'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Root Cause
Razorpay's payment API returns two fields in the payment object:
fee— the total amount deducted from settlement, which isbase_fee + GST(all-in)tax— the GST portion only, which is already contained withinfeeThe previous code treated
taxas an additional deduction on top offee:This meant every confirmed payment stored a
net_amountthat was understated by exactly thetaxvalue (22 paise per ₹60 payment). Every financial report showed a lower "Net received" than what Razorpay actually settled.Example (29-payment trip):
fee)Changes
backend/src/services/payment/payment.service.tsFixed
net_amountcalculation in all three code paths:backend/migrations/021_create_reports_module.sqlreport_financialsview: fixed the NULL fallback formula fromamount - (fee + tax) / 100toamount - fee / 100reports_summaryview: fixedtotal_gateway_deductionsfromSUM(gateway_fees + gateway_tax)toSUM(gateway_fees)— was double-counting GST in the summarybackend/migrations/014_add_payment_fee_columns.sqlCorrected the
net_amountcolumn comment fromamount - fee - taxtoamount - feeso future developers don't reintroduce the same bug.frontend/src/pages/admin/reports/ReportDetailPage.tsxFixed the "Gateway fees" display line from
gateway_fees + gateway_taxtogateway_feesonly, making the on-screen breakdown self-consistent:Notes
gateway_taxcolumn is still stored for GST accounting/tax records — it is just no longer subtracted fromnet_amount