Skip to content

fix(billing): cleanup discount payments#1969

Merged
baktun14 merged 5 commits intomainfrom
fix/cleanup-discount-payments
Oct 3, 2025
Merged

fix(billing): cleanup discount payments#1969
baktun14 merged 5 commits intomainfrom
fix/cleanup-discount-payments

Conversation

@baktun14
Copy link
Contributor

@baktun14 baktun14 commented Sep 25, 2025

Why

Previously the coupon were claimed, then shown as a receipt with sub total in the payment page, and then users were expected to either do a 0$ amount payment or greater to claim the coupon amount. That logic was removed in favor of just adding to the balance directly when claiming the coupon.

In this pr, I cleaned up the remnents of the old coupon logic.

Summary by CodeRabbit

  • Refactor

    • Simplified payments: removed discount handling so final charge equals entered amount; removed discount UI and final-amount previews; applying a coupon clears input and shows success without refetch.
  • API

    • Removed customer-discounts endpoint and discount-related response types; payment intents and webhooks no longer apply, track, or consume discounts and use actual payment amounts.
  • Tests

    • Removed discount-related tests and scenarios.

@baktun14 baktun14 requested a review from a team as a code owner September 25, 2025 12:44
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 25, 2025

Walkthrough

Removed discount/coupon support across backend and web: deleted discount schemas and types, removed controller endpoint and route, stripped discount logic from services and webhook, eliminated related tests, hooks, query keys, and UI coupon elements — payment flows now use direct amount handling without discount metadata.

Changes

Cohort / File(s) Summary
API — Controller & Routes
apps/api/src/billing/controllers/stripe/stripe.controller.ts, apps/api/src/billing/routes/stripe-coupons/stripe-coupons.router.ts
Removed getCustomerDiscounts method, its route/OpenAPI registration, and discount-related imports/usages.
API — Schemas
apps/api/src/billing/http-schemas/stripe.schema.ts
Deleted DiscountSchema, CustomerDiscountsResponseSchema, and exported types Discount / CustomerDiscountsResponse.
API — Services & Webhook
apps/api/src/billing/services/stripe/stripe.service.ts, apps/api/src/billing/services/stripe-webhook/stripe-webhook.service.ts
Removed discount helpers and consumption logic; stopped reading/writing discount metadata; createPaymentIntent and webhook top-up now use direct amount values.
API — Service Tests
apps/api/src/billing/services/stripe/stripe.service.spec.ts
Removed tests covering discount metadata, zero-amount-with-discount, and consumeActiveDiscount scenarios.
Web — Payment UI
apps/deploy-web/src/components/user/payment/PaymentForm.tsx, apps/deploy-web/src/pages/payment.tsx
Removed discounts / getFinalAmount props and coupon UI; final amount parsed directly from input; coupon apply no longer refetches discounts.
Web — Queries & Tests
apps/deploy-web/src/queries/usePaymentQueries.ts, apps/deploy-web/src/queries/queryKeys.ts, apps/deploy-web/src/queries/usePaymentQueries.spec.tsx
Removed usePaymentDiscountsQuery, QueryKeys.getPaymentDiscountsKey, discount-related invalidations and associated tests/mocks.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  rect #eef8ff
  participant U as User
  participant W as Web App
  participant A as API (StripeService)
  participant S as Stripe
  end

  U->>W: Enter amount & payment method
  W->>A: POST /payment-intent (amount in cents)
  A->>S: Create PaymentIntent (no discount metadata)
  S-->>A: PaymentIntent client_secret
  A-->>W: PaymentIntentResult
  W->>S: Confirm PaymentIntent
  S-->>W: Confirmation result
  W-->>U: Show success/failure
Loading
sequenceDiagram
  autonumber
  rect #fff7ec
  participant S as Stripe
  participant A as API Webhook
  participant W as Wallet Service
  end

  S->>A: payment_intent.succeeded webhook
  A->>A: Read paymentIntent.amount / amount_received (ignore discount metadata)
  A->>W: Top up wallet with amount
  W-->>A: Success/Failure
  A-->>S: 2xx/5xx response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • ygrishajev
  • stalniy

Poem

"I nibble code with careful paws,
Coupons folded, gone because—
Cents hop straight into the chest,
No metadata to clutter rest.
Hop, merge, and onward—what a cause! 🥕"

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “fix(billing): cleanup discount payments” succinctly captures the primary change of removing outdated discount payment logic in the billing codebase. It directly reflects the refactoring of discount-related flows without extra noise, guiding teammates reviewing history. The scope and intent match the described changes in controllers, services, schemas, and UI. Therefore the title is clear, specific, and fully relevant to the changeset.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/cleanup-discount-payments

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c42145d and 8a90e61.

📒 Files selected for processing (1)
  • apps/api/src/billing/services/stripe/stripe.service.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/api/src/billing/services/stripe/stripe.service.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: test-build
  • GitHub Check: test-build
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: test-build

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Sep 25, 2025

Codecov Report

❌ Patch coverage is 20.00000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.71%. Comparing base (1088516) to head (8a90e61).
⚠️ Report is 10 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...oy-web/src/components/user/payment/PaymentForm.tsx 0.00% 3 Missing ⚠️
apps/deploy-web/src/pages/payment.tsx 0.00% 3 Missing ⚠️
.../services/stripe-webhook/stripe-webhook.service.ts 0.00% 2 Missing ⚠️

❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1969      +/-   ##
==========================================
+ Coverage   45.44%   45.71%   +0.26%     
==========================================
  Files        1005     1009       +4     
  Lines       28496    28498       +2     
  Branches     7470     7461       -9     
==========================================
+ Hits        12951    13027      +76     
- Misses      14324    15177     +853     
+ Partials     1221      294     -927     
Flag Coverage Δ
api 81.87% <50.00%> (+0.30%) ⬆️
deploy-web 23.85% <0.00%> (+0.05%) ⬆️
log-collector 75.35% <ø> (ø)
notifications 88.16% <ø> (+0.21%) ⬆️
provider-console 81.48% <ø> (ø)
provider-proxy 84.98% <ø> (ø)
Files with missing lines Coverage Δ
...rc/billing/controllers/stripe/stripe.controller.ts 19.10% <ø> (+0.15%) ⬆️
apps/api/src/billing/http-schemas/stripe.schema.ts 100.00% <ø> (ø)
...ing/routes/stripe-coupons/stripe-coupons.router.ts 72.72% <100.00%> (+6.06%) ⬆️
.../api/src/billing/services/stripe/stripe.service.ts 89.15% <100.00%> (+0.41%) ⬆️
apps/deploy-web/src/queries/queryKeys.ts 100.00% <ø> (ø)
apps/deploy-web/src/queries/usePaymentQueries.ts 91.11% <ø> (-1.49%) ⬇️
.../services/stripe-webhook/stripe-webhook.service.ts 41.48% <0.00%> (+3.98%) ⬆️
...oy-web/src/components/user/payment/PaymentForm.tsx 0.00% <0.00%> (ø)
apps/deploy-web/src/pages/payment.tsx 0.00% <0.00%> (ø)

... and 236 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/api/src/billing/services/stripe/stripe.service.ts (1)

113-140: Guard against zero- or sub-cent payment intents

We now compute amountCents = Math.round(params.amount * 100) and always call Stripe. If the caller passes 0 (or something that rounds to 0), Stripe will throw invalid_request_error: Amount must be at least 1. Before the cleanup we short-circuited zero-amount flows via handleZeroAmountPayment, but that branch is gone even though the helper is still present.

Please either:

  • bail out early and call handleZeroAmountPayment when amountCents <= 0, or
  • throw a validation error before touching Stripe (so the controller can surface a clean 4xx response).

Without that, a malicious/buggy client can still force Stripe rejects (and we log + surface them as generic failures).

   const amountCents = Math.round(params.amount * 100);
 
+  if (amountCents <= 0) {
+    return await this.handleZeroAmountPayment(params.customer, amountCents);
+  }
+
   const paymentIntent = await this.paymentIntents.create({
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f8ef172 and 1fd0f70.

⛔ Files ignored due to path filters (1)
  • apps/api/test/functional/__snapshots__/docs.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (11)
  • apps/api/src/billing/controllers/stripe/stripe.controller.ts (1 hunks)
  • apps/api/src/billing/http-schemas/stripe.schema.ts (0 hunks)
  • apps/api/src/billing/routes/stripe-coupons/stripe-coupons.router.ts (1 hunks)
  • apps/api/src/billing/services/stripe-webhook/stripe-webhook.service.ts (1 hunks)
  • apps/api/src/billing/services/stripe/stripe.service.spec.ts (0 hunks)
  • apps/api/src/billing/services/stripe/stripe.service.ts (3 hunks)
  • apps/deploy-web/src/components/user/payment/PaymentForm.tsx (2 hunks)
  • apps/deploy-web/src/pages/payment.tsx (3 hunks)
  • apps/deploy-web/src/queries/queryKeys.ts (0 hunks)
  • apps/deploy-web/src/queries/usePaymentQueries.spec.tsx (1 hunks)
  • apps/deploy-web/src/queries/usePaymentQueries.ts (1 hunks)
💤 Files with no reviewable changes (3)
  • apps/api/src/billing/services/stripe/stripe.service.spec.ts
  • apps/deploy-web/src/queries/queryKeys.ts
  • apps/api/src/billing/http-schemas/stripe.schema.ts
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/api/src/billing/controllers/stripe/stripe.controller.ts
  • apps/deploy-web/src/queries/usePaymentQueries.ts
  • apps/deploy-web/src/queries/usePaymentQueries.spec.tsx
  • apps/api/src/billing/services/stripe-webhook/stripe-webhook.service.ts
  • apps/api/src/billing/routes/stripe-coupons/stripe-coupons.router.ts
  • apps/api/src/billing/services/stripe/stripe.service.ts
  • apps/deploy-web/src/pages/payment.tsx
  • apps/deploy-web/src/components/user/payment/PaymentForm.tsx
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/api/src/billing/controllers/stripe/stripe.controller.ts
  • apps/deploy-web/src/queries/usePaymentQueries.ts
  • apps/deploy-web/src/queries/usePaymentQueries.spec.tsx
  • apps/api/src/billing/services/stripe-webhook/stripe-webhook.service.ts
  • apps/api/src/billing/routes/stripe-coupons/stripe-coupons.router.ts
  • apps/api/src/billing/services/stripe/stripe.service.ts
  • apps/deploy-web/src/pages/payment.tsx
  • apps/deploy-web/src/components/user/payment/PaymentForm.tsx
**/*.spec.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/no-jest-mock.mdc)

Don't use jest.mock() to mock dependencies in test files. Instead, use jest-mock-extended to create mocks and pass mocks as dependencies to the service under test.

**/*.spec.{ts,tsx}: Use setup function instead of beforeEach in test files
setup function must be at the bottom of the root describe block in test files
setup function creates an object under test and returns it
setup function should accept a single parameter with inline type definition
Don't use shared state in setup function
Don't specify return type of setup function

Files:

  • apps/deploy-web/src/queries/usePaymentQueries.spec.tsx
apps/{deploy-web,provider-console}/**/*.spec.tsx

📄 CodeRabbit inference engine (.cursor/rules/query-by-in-tests.mdc)

Use queryBy methods instead of getBy methods in test expectations in .spec.tsx files

Files:

  • apps/deploy-web/src/queries/usePaymentQueries.spec.tsx
🧠 Learnings (3)
📓 Common learnings
Learnt from: baktun14
PR: akash-network/console#1933
File: apps/deploy-web/src/pages/payment.tsx:92-116
Timestamp: 2025-09-18T07:44:29.079Z
Learning: In the payment system, discount calculation is not applied during payment processing. Instead, when users claim coupons/discounts, the discount amount is applied directly to their account balance. Therefore, the payment flow should charge parseFloat(amount) as entered, not a discounted amount.
📚 Learning: 2025-07-21T08:24:27.953Z
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-07-21T08:24:27.953Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use `queryBy` methods instead of `getBy` methods in test expectations in `.spec.tsx` files

Applied to files:

  • apps/deploy-web/src/queries/usePaymentQueries.spec.tsx
📚 Learning: 2025-09-18T07:44:29.079Z
Learnt from: baktun14
PR: akash-network/console#1933
File: apps/deploy-web/src/pages/payment.tsx:92-116
Timestamp: 2025-09-18T07:44:29.079Z
Learning: In the payment system, discount calculation is not applied during payment processing. Instead, when users claim coupons/discounts, the discount amount is applied directly to their account balance. Therefore, the payment flow should charge parseFloat(amount) as entered, not a discounted amount.

Applied to files:

  • apps/api/src/billing/services/stripe/stripe.service.ts
  • apps/deploy-web/src/pages/payment.tsx
  • apps/deploy-web/src/components/user/payment/PaymentForm.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
🔇 Additional comments (5)
apps/api/src/billing/routes/stripe-coupons/stripe-coupons.router.ts (1)

5-40: Removal aligns with API surface simplification

Thanks for pruning the unused customer-discounts route and keeping only the apply flow—nothing else in the router (or OpenAPI registration) references the removed schemas anymore.

apps/api/src/billing/controllers/stripe/stripe.controller.ts (1)

9-120: Controller changes look consistent

Imports and method surface now match the slimmer discount-free Stripe service; confirmPayment/applyCoupon paths remain intact.

apps/deploy-web/src/queries/usePaymentQueries.ts (1)

88-95: Front-end mutation updates LGTM

The apply-coupon mutation now matches the new “credit wallet directly” behavior—no stray discount invalidations left behind.

apps/deploy-web/src/queries/usePaymentQueries.spec.tsx (1)

4-127: Tests track the updated exports correctly

No dangling expectations for discounts—test coverage still exercises the remaining hooks.

apps/deploy-web/src/components/user/payment/PaymentForm.tsx (1)

3-83: UI cleanup matches the new flow

Props and display logic now focus on raw amounts, which is exactly what we want after removing discount math.

@stalniy
Copy link
Contributor

stalniy commented Sep 25, 2025

@baktun14 could you please add "Why" section to explain the motivation behind this change

@baktun14
Copy link
Contributor Author

@baktun14 could you please add "Why" section to explain the motivation behind this change

Sure, done.

@baktun14 baktun14 force-pushed the fix/cleanup-discount-payments branch from 9424a5d to c42145d Compare September 30, 2025 12:12
@baktun14 baktun14 merged commit 0a72177 into main Oct 3, 2025
60 of 62 checks passed
@baktun14 baktun14 deleted the fix/cleanup-discount-payments branch October 3, 2025 10:14
ygrishajev pushed a commit that referenced this pull request Oct 6, 2025
* fix(billing): remove discounts calculations from ui

* fix(billing): remove discount calculations from api

* fix(billing): disable coupon button when loading

* fix(billing): pr fixes

* fix: remove unused function
ygrishajev pushed a commit that referenced this pull request Oct 6, 2025
* fix(billing): remove discounts calculations from ui

* fix(billing): remove discount calculations from api

* fix(billing): disable coupon button when loading

* fix(billing): pr fixes

* fix: remove unused function
stalniy pushed a commit that referenced this pull request Nov 20, 2025
* fix(billing): remove discounts calculations from ui

* fix(billing): remove discount calculations from api

* fix(billing): disable coupon button when loading

* fix(billing): pr fixes

* fix: remove unused function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments