Skip to content

feat(billing): filter payment methods#1610

Merged
baktun14 merged 3 commits intomainfrom
fix/handle-stripe-payments
Jul 2, 2025
Merged

feat(billing): filter payment methods#1610
baktun14 merged 3 commits intomainfrom
fix/handle-stripe-payments

Conversation

@baktun14
Copy link
Contributor

@baktun14 baktun14 commented Jul 2, 2025

Summary by CodeRabbit

  • New Features

    • Expanded support for additional payment method types beyond cards when saving payment methods.
    • Payment methods list now displays non-card payment methods with appropriate labels for improved clarity.
  • Bug Fixes

    • Improved handling and display of payment methods that do not include card details, preventing missing or broken UI elements.

@baktun14 baktun14 requested a review from a team as a code owner July 2, 2025 14:39
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 2, 2025

Walkthrough

The changes expand payment method support in both backend and frontend. The backend now includes non-card payment methods in Stripe setup intents and when listing payment methods. The frontend updates its display logic to handle payment methods without card details. The shared type definition for payment methods marks the card property as optional.

Changes

File(s) Change Summary
apps/api/src/billing/services/stripe/stripe.service.ts Added support for multiple payment method types in setup intents; fetches all payment methods, not just cards.
apps/api/src/billing/services/stripe/stripe.service.spec.ts Updated tests to reflect added payment method types and removed card type filter in payment methods listing.
apps/deploy-web/src/components/user/payment/PaymentMethodsList.tsx Updated UI logic to display non-card payment methods gracefully.
packages/http-sdk/src/stripe/stripe.types.ts Made the card property in PaymentMethod interface optional.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Frontend
  participant API
  participant Stripe

  User->>Frontend: View payment methods
  Frontend->>API: GET /payment-methods
  API->>Stripe: List all payment methods (no card filter)
  Stripe-->>API: Payment methods (card and non-card)
  API-->>Frontend: Payment methods data
  Frontend->>User: Display card info if present, else show type
Loading

Poem

In fields of payment, options grow wide,
No longer just cards in the burrow we hide.
Now "link" and more, our service extends,
The UI adapts, and the backend amends.
Hop, hop—rabbits cheer,
For every method, far and near!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-02T15_51_07_762Z-debug-0.log


📜 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 2711b55 and 3f4a706.

📒 Files selected for processing (1)
  • apps/api/src/billing/services/stripe/stripe.service.spec.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.spec.{ts,tsx}`: Use `setup` function instead of `beforeEach` in test files...

**/*.spec.{ts,tsx}: Use setup function instead of beforeEach in test files
setup function must be at the bottom of the root describe block
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

📄 Source: CodeRabbit Inference Engine (.cursor/rules/setup-instead-of-before-each.mdc)

List of files the instruction was applied to:

  • apps/api/src/billing/services/stripe/stripe.service.spec.ts
🧠 Learnings (1)
apps/api/src/billing/services/stripe/stripe.service.spec.ts (5)
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-06-30T12:11:58.081Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function should accept a single parameter with inline type definition
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-06-30T12:11:58.081Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't specify return type of `setup` function
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-06-30T12:11:58.081Z
Learning: Applies to **/*.spec.{ts,tsx} : Use `setup` function instead of `beforeEach` in test files
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-06-30T12:11:58.081Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function creates an object under test and returns it
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-06-30T12:11:50.570Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use `queryBy` methods instead of `getBy` methods in test expectations in `.spec.tsx` files
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: Validate local packages
🔇 Additional comments (2)
apps/api/src/billing/services/stripe/stripe.service.spec.ts (2)

184-186: LGTM - Test correctly verifies expanded payment method types.

The test properly validates that the createSetupIntent method now includes both "card" and "link" payment method types, which aligns with the expanded payment method support mentioned in the PR objectives.


285-285: LGTM - Test correctly removes payment method type filter.

The test now properly validates that getPaymentMethods retrieves all payment methods without filtering by type, which aligns with the backend changes to support non-card payment methods.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Jul 2, 2025

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 42.58%. Comparing base (f567c75) to head (3f4a706).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...src/components/user/payment/PaymentMethodsList.tsx 0.00% 1 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    #1610      +/-   ##
==========================================
- Coverage   42.71%   42.58%   -0.14%     
==========================================
  Files         877      878       +1     
  Lines       21531    21605      +74     
  Branches     3943     3973      +30     
==========================================
+ Hits         9198     9200       +2     
+ Misses      12035    11697     -338     
- Partials      298      708     +410     
Flag Coverage Δ *Carryforward flag
api 76.20% <ø> (ø) Carriedforward from 2711b55
deploy-web 19.17% <0.00%> (-0.10%) ⬇️ Carriedforward from 2711b55
notifications 87.90% <ø> (ø) Carriedforward from 2711b55
provider-proxy 82.13% <ø> (ø) Carriedforward from 2711b55

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
.../api/src/billing/services/stripe/stripe.service.ts 85.93% <ø> (ø)
...src/components/user/payment/PaymentMethodsList.tsx 0.00% <0.00%> (ø)

... and 138 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

stalniy
stalniy previously approved these changes Jul 2, 2025
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: 1

🔭 Outside diff range comments (1)
packages/http-sdk/src/stripe/stripe.types.ts (1)

37-42: Guard optional card property in UI components

The card field is now optional on PaymentMethod. We’ve identified direct accesses that will throw at runtime if card is undefined—those need to be updated to handle the optional case.

Affected locations:

  • apps/deploy-web/src/components/user/payment/PaymentMethodsList.tsx
    • method.card.brand
    • method.card.last4
    • method.card.exp_month / method.card.exp_year

Suggested fixes (choose one per usage):

  • Use optional chaining:
    - {method.card.brand}
    + {method.card?.brand}
  • Guard with a conditional render:
    {method.card && (
      <>
        <span className="font-medium capitalize">{method.card.brand}</span>
        {/* … */}
      </>
    )}

Please update these references to safely handle the now-optional card property.

🧹 Nitpick comments (1)
apps/api/src/billing/services/stripe/stripe.service.ts (1)

38-40: Consider making payment method types configurable.

The addition of payment_method_types: ["card", "link"] correctly expands support beyond cards. However, the hardcoded array might benefit from being configurable through the billing config service for easier maintenance.

Consider extracting the payment method types to the billing configuration:

+ const paymentMethodTypes = this.billingConfig.get("STRIPE_PAYMENT_METHOD_TYPES")?.split(",") || ["card", "link"];
  return await this.setupIntents.create({
    customer: customerId,
    usage: "off_session",
-   payment_method_types: ["card", "link"]
+   payment_method_types: paymentMethodTypes
  });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d6cd3c5 and 9de0595.

📒 Files selected for processing (3)
  • apps/api/src/billing/services/stripe/stripe.service.ts (2 hunks)
  • apps/deploy-web/src/components/user/payment/PaymentMethodsList.tsx (1 hunks)
  • packages/http-sdk/src/stripe/stripe.types.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
apps/deploy-web/src/components/user/payment/PaymentMethodsList.tsx (1)
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-06-30T12:11:50.570Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use `queryBy` methods instead of `getBy` methods in test expectations in `.spec.tsx` files
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: Validate local packages
🔇 Additional comments (1)
apps/api/src/billing/services/stripe/stripe.service.ts (1)

90-95: LGTM - Correctly removes card-only restriction.

Removing the type: "card" filter allows the method to return all payment methods for a customer, which aligns perfectly with the goal of supporting multiple payment method types.

@baktun14 baktun14 merged commit 3db9833 into main Jul 2, 2025
57 of 58 checks passed
@baktun14 baktun14 deleted the fix/handle-stripe-payments branch July 2, 2025 16:19
stalniy pushed a commit that referenced this pull request Nov 20, 2025
* feat(billing): filter payment methods

* fix(billing): replace all _

* fix(billing): stripe tests
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