Skip to content

[Dashboard] Add crypto payment option for invoices #7270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2025

Conversation

jnsdls
Copy link
Member

@jnsdls jnsdls commented Jun 4, 2025

Add Crypto Payment Option for Invoices

This PR adds the ability to pay invoices with cryptocurrency. It includes:

  • A new API endpoint for crypto invoice payments
  • UI updates to display the crypto payment option alongside card payments
  • Refactoring of the checkout page to handle different payment types using a switch statement
  • Always showing the credit balance section on the billing page
  • Updating the "Top Up Credits" button to "Top Up With Crypto" with the Thirdweb logo

The implementation follows the same pattern as the existing crypto top-up functionality, creating a new getInvoicePaymentUrl function that communicates with the backend API.

Summary by CodeRabbit

  • New Features

    • Added the ability to pay invoices with cryptocurrency directly from the billing history, alongside traditional card payments.
    • Introduced a new checkout flow for invoice payments, supporting both crypto and card options.
  • Improvements

    • Updated the top-up credits button to display a crypto icon and clarified the action as "Top Up With Crypto".
    • Enhanced invoice due date handling for more accurate status display.
  • Bug Fixes

    • Corrected invoice date comparisons to ensure proper overdue status detection.

Copy link

changeset-bot bot commented Jun 4, 2025

⚠️ No Changeset found

Latest commit: 3b3a225

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Jun 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 4, 2025 6:59am
4 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Skipped (Inspect) Jun 4, 2025 6:59am
login ⬜️ Skipped (Inspect) Jun 4, 2025 6:59am
thirdweb_playground ⬜️ Skipped (Inspect) Jun 4, 2025 6:59am
wallet-ui ⬜️ Skipped (Inspect) Jun 4, 2025 6:59am

@vercel vercel bot temporarily deployed to Preview – wallet-ui June 4, 2025 06:52 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground June 4, 2025 06:52 Inactive
@vercel vercel bot temporarily deployed to Preview – docs-v2 June 4, 2025 06:52 Inactive
@vercel vercel bot temporarily deployed to Preview – login June 4, 2025 06:52 Inactive
Copy link
Contributor

coderabbitai bot commented Jun 4, 2025

Walkthrough

The changes extend the billing and checkout flows to support invoice payments with cryptocurrency. This includes refactoring the checkout logic to handle multiple SKU types, adding a utility for generating invoice payment URLs, updating billing history to offer crypto payment options for invoices, and adjusting UI components and types to support these features.

Changes

File(s) Change Summary
.../checkout/[team_slug]/[sku]/page.tsx Refactored checkout logic to a switch statement supporting multiple SKUs; added support for invoice payments via crypto, with parameter validation and error handling.
.../utils/billing.ts Modified getCryptoTopupUrl to use URL constructor; added getInvoicePaymentUrl for generating crypto invoice payment URLs.
.../settings/billing/components/credit-balance-section.client.tsx Updated top-up button to include a crypto logo and changed label to "Top Up With Crypto".
.../settings/billing/page.tsx Removed showCreditBalance from searchParams; simplified rendering logic for CreditBalanceSection.
.../settings/invoices/components/billing-history.tsx Added teamSlug prop; fixed due date comparison; replaced "Pay Now" with "Pay with crypto" and "Pay with Card" buttons for open invoices; added icons and adjusted styling.
.../settings/invoices/page.tsx Passed teamSlug prop to BillingHistory component.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CheckoutPage
    participant BillingUtils
    participant Redirect

    User->>CheckoutPage: Access /checkout/[team_slug]/[sku]
    CheckoutPage->>CheckoutPage: Parse SKU and searchParams
    alt SKU is "invoice"
        CheckoutPage->>BillingUtils: getInvoicePaymentUrl({ teamSlug, invoiceId })
        BillingUtils-->>CheckoutPage: Return payment URL or undefined
        alt Payment URL exists
            CheckoutPage->>Redirect: Redirect to payment URL
        else Payment URL missing/invalid
            CheckoutPage->>User: Show error page
        end
    else SKU is "topup"
        CheckoutPage->>BillingUtils: getCryptoTopupUrl({ teamSlug })
        BillingUtils-->>CheckoutPage: Return topup URL or undefined
        alt Topup URL exists
            CheckoutPage->>Redirect: Redirect to topup URL
        else Topup URL missing
            CheckoutPage->>User: Show error page
        end
    else Other SKU
        CheckoutPage->>BillingUtils: getBillingCheckoutUrl({ teamSlug, sku })
        BillingUtils-->>CheckoutPage: Return checkout URL or undefined
        alt Checkout URL exists
            CheckoutPage->>Redirect: Redirect to checkout URL
        else Checkout URL missing
            CheckoutPage->>User: Show error page
        end
    end
Loading

Possibly related PRs

  • thirdweb-dev/js#7239: Extends checkout and billing utilities to handle invoice payment URLs, directly building upon and expanding the same checkout logic and billing utility functions.

Suggested reviewers

  • joaquim-verges
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.

@github-actions github-actions bot added the Dashboard Involves changes to the Dashboard. label Jun 4, 2025
Copy link
Member Author

jnsdls commented Jun 4, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@jnsdls jnsdls marked this pull request as ready for review June 4, 2025 06:52
@jnsdls jnsdls requested review from a team as code owners June 4, 2025 06:52
Copy link

codecov bot commented Jun 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.57%. Comparing base (d4bc8e1) to head (3b3a225).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7270   +/-   ##
=======================================
  Coverage   55.57%   55.57%           
=======================================
  Files         909      909           
  Lines       58681    58681           
  Branches     4167     4167           
=======================================
  Hits        32612    32612           
  Misses      25961    25961           
  Partials      108      108           
Flag Coverage Δ
packages 55.57% <ø> (ø)
🚀 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.

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

🧹 Nitpick comments (2)
apps/dashboard/src/app/(app)/(stripe)/checkout/[team_slug]/[sku]/page.tsx (2)

22-42: Remove unreachable break statement.

The redirect() function throws/exits the execution, making the break statement unreachable. While not harmful, it's dead code that should be removed for cleanliness.

       redirect(topupUrl);
-      break;

43-59: Remove unreachable break statement and consider enhanced validation.

Similar to the topup case, the break statement is unreachable after redirect(). Additionally, consider validating the invoice ID format if there are specific requirements.

       redirect(invoice);
-      break;

For the validation, if invoice IDs have a specific format (e.g., Stripe invoice IDs start with "in_"), you could add:

       const invoiceId = (await props.searchParams).invoice_id;
-      if (!invoiceId) {
+      if (!invoiceId || typeof invoiceId !== 'string' || invoiceId.trim() === '') {
         return <StripeRedirectErrorPage errorMessage="Invalid invoice ID" />;
       }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d4bc8e1 and 3b3a225.

📒 Files selected for processing (6)
  • apps/dashboard/src/app/(app)/(stripe)/checkout/[team_slug]/[sku]/page.tsx (2 hunks)
  • apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts (2 hunks)
  • apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/settings/billing/components/credit-balance-section.client.tsx (2 hunks)
  • apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/settings/billing/page.tsx (1 hunks)
  • apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/settings/invoices/components/billing-history.tsx (4 hunks)
  • apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/settings/invoices/page.tsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
apps/dashboard/src/app/(app)/(stripe)/checkout/[team_slug]/[sku]/page.tsx (3)
apps/dashboard/src/app/(app)/(stripe)/_components/StripeRedirectErrorPage.tsx (1)
  • StripeRedirectErrorPage (3-16)
apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts (3)
  • getCryptoTopupUrl (124-161)
  • getInvoicePaymentUrl (163-199)
  • getBillingCheckoutUrl (7-42)
apps/dashboard/src/@/lib/billing.ts (1)
  • ProductSKU (2-16)
apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts (2)
apps/dashboard/src/@/constants/public-envs.ts (1)
  • NEXT_PUBLIC_THIRDWEB_API_HOST (21-22)
apps/dashboard/src/app/(app)/api/lib/getAuthToken.ts (1)
  • getAuthToken (6-14)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Unit Tests
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Size
  • GitHub Check: Lint Packages
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (13)
apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts (2)

134-137: LGTM! Improved URL construction consistency.

The refactor to use the URL constructor instead of string interpolation enhances consistency with the newly added getInvoicePaymentUrl function and provides better URL validation.


163-199: New invoice payment function follows established patterns correctly.

The getInvoicePaymentUrl function implementation is consistent with existing billing utility functions:

  • Proper authentication token handling
  • Consistent error handling pattern
  • Appropriate use of URL constructor
  • Matching request/response structure

The function correctly integrates with the new crypto invoice payment workflow.

apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/settings/invoices/page.tsx (1)

52-52: LGTM! Prop addition enables crypto payment functionality.

Adding the teamSlug prop to the BillingHistory component is necessary for constructing crypto payment links for invoices, as referenced in the component's updated implementation.

apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/settings/billing/page.tsx (1)

73-73: LGTM! Simplified conditional rendering improves UX.

Removing the showCreditBalance search parameter dependency makes the credit balance section consistently visible when stripeCustomerId exists, which aligns well with the enhanced crypto payment functionality.

apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/settings/billing/components/credit-balance-section.client.tsx (2)

19-19: LGTM! Clean import for crypto branding.

The ThirdwebMiniLogo import is appropriately added to support the crypto payment branding enhancement.


123-124: LGTM! Enhanced button clearly indicates crypto payment option.

The addition of the Thirdweb logo and updated text "Top Up With Crypto" provides clear visual indication of the payment method, improving user understanding and brand consistency.

apps/dashboard/src/app/(app)/(stripe)/checkout/[team_slug]/[sku]/page.tsx (2)

7-7: LGTM: Import addition supports new invoice payment functionality.

The import of getInvoicePaymentUrl correctly supports the new crypto invoice payment feature.


17-17: LGTM: SearchParams type updated for invoice payments.

The addition of the optional invoice_id parameter properly supports the new invoice payment flow.

apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/settings/invoices/components/billing-history.tsx (5)

21-21: LGTM: Imports added for new crypto payment functionality.

The imports of Link and ThirdwebMiniLogo properly support the new crypto payment button implementation.

Also applies to: 25-25


29-29: LGTM: TeamSlug prop enables crypto payment routing.

The addition of the teamSlug prop correctly provides the necessary context for constructing crypto payment URLs.


67-67: Excellent bug fix: Correct timestamp conversion for due date comparison.

This fixes a critical bug where Stripe timestamps (seconds) were being compared directly with Date.now() (milliseconds). The multiplication by 1000 correctly converts the Stripe timestamp to milliseconds for accurate comparison.


128-154: Well-implemented crypto payment option with fallback to card payments.

The payment button implementation effectively provides both crypto and card payment options:

  • Always shows crypto payment button for open invoices
  • Conditionally shows card payment if hosted invoice URL is available
  • Good use of appropriate icons and styling
  • Proper external link handling with security attributes

The user experience is enhanced by offering multiple payment methods while maintaining consistency with the existing UI patterns.


163-163: Minor styling adjustment.

Added spacing in the className for consistency.

Copy link
Contributor

github-actions bot commented Jun 4, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 62.57 KB (+0.05% 🔺) 1.3 s (+0.05% 🔺) 251 ms (+197.65% 🔺) 1.6 s
thirdweb (cjs) 345.38 KB (0%) 7 s (0%) 664 ms (+5.16% 🔺) 7.6 s
thirdweb (minimal + tree-shaking) 5.7 KB (0%) 114 ms (0%) 78 ms (+1807.36% 🔺) 192 ms
thirdweb/chains (tree-shaking) 531 B (0%) 11 ms (0%) 19 ms (+817.5% 🔺) 29 ms
thirdweb/react (minimal + tree-shaking) 19.56 KB (0%) 392 ms (0%) 96 ms (+808.32% 🔺) 487 ms

@jnsdls jnsdls merged commit 082d963 into main Jun 4, 2025
27 checks passed
@jnsdls jnsdls deleted the _Dashboard_Add_crypto_payment_option_for_invoices branch June 4, 2025 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dashboard Involves changes to the Dashboard.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant