Skip to content

feat(api): include user emails in metadata - #559

Merged
steebchen merged 1 commit into
mainfrom
feat/stripe-meteadata
Aug 2, 2025
Merged

steebchen merged 1 commit into
mainfrom
feat/stripe-meteadata

Conversation

@steebchen

@steebchen steebchen commented Aug 2, 2025 •

Copy link
Copy Markdown
Member

Add user email metadata in payment transactions and subscriptions for better traceability. Update worker processes to query and include user emails associated with organizations.

Summary by CodeRabbit

  • New Features
    • User email addresses are now included in the metadata for Stripe payment intents and subscription checkout sessions, providing enhanced payment information visibility.

Add user email metadata in payment transactions and subscriptions for better traceability. Update worker processes to query and include user emails associated with organizations.
@steebchen
steebchen requested a review from Copilot August 2, 2025 00:21
@coderabbitai

coderabbitai Bot commented Aug 2, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The changes update Stripe payment integration logic across multiple modules to include the user's email address in the metadata for payment intents and subscription sessions. This enhancement is applied to payment creation, saved method top-ups, and auto top-up workflows by augmenting the metadata sent to Stripe with the user's email.

Changes

Cohort / File(s) Change Summary
Payments Route Metadata Update
apps/api/src/routes/payments.ts
Added the user's email (userEmail) to the metadata in Stripe payment intent creation for payment and top-up APIs.
Subscriptions Route Metadata Update
apps/api/src/routes/subscriptions.ts
Included the user's email in both top-level and nested subscription metadata when creating Stripe checkout sessions.
Auto Top-Up Metadata Enhancement
apps/gateway/src/worker.ts
Fetched the first user for each organization and added their email to the metadata in Stripe payment intents during auto top-up processing.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant Stripe

    Client->>API: Initiate payment or subscription
    API->>API: Retrieve user and organization details
    API->>Stripe: Create PaymentIntent/CheckoutSession (metadata includes userEmail)
    Stripe-->>API: PaymentIntent/Session confirmation
    API-->>Client: Return payment/session info
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/stripe-meteadata

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 generate unit tests to generate unit tests for 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.

@steebchen
steebchen enabled auto-merge August 2, 2025 00:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds user email metadata to payment transactions and subscriptions to improve traceability and audit capabilities. The changes ensure that user emails are consistently included in Stripe metadata across different payment flows.

Key changes:

  • Enhanced worker process to query and include user emails for auto top-up transactions
  • Added user email metadata to subscription creation
  • Added user email metadata to payment intents and saved payment method transactions

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
apps/gateway/src/worker.ts Queries user organization relationship to include user email in auto top-up transaction metadata
apps/api/src/routes/subscriptions.ts Adds user email to both checkout session and subscription metadata during pro subscription creation
apps/api/src/routes/payments.ts Includes user email metadata in payment intent creation and top-up with saved payment method

Comment thread apps/gateway/src/worker.ts
@steebchen
steebchen added this pull request to the merge queue Aug 2, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
apps/api/src/routes/payments.ts (1)

94-94: LGTM! Consider adding null safety for user email.

The addition of user email to payment intent metadata is consistent and aligns with the PR objective. Both implementations follow the same pattern as existing metadata fields.

Consider adding a null safety check to ensure robust handling:

 metadata: {
   organizationId,
   baseAmount: amount.toString(),
   totalFees: feeBreakdown.totalFees.toString(),
-  userEmail: user.email,
+  ...(user.email && { userEmail: user.email }),
 },

Also applies to: 543-543

apps/api/src/routes/subscriptions.ts (1)

110-110: LGTM! Consider adding null safety for user email.

Good approach adding user email to both session metadata and subscription metadata - this ensures the email is available for both checkout tracking and subscription management.

For consistency with the suggestion in payments.ts, consider adding null safety:

 metadata: {
   organizationId: organization.id,
   plan: "pro",
   billingCycle,
-  userEmail: user.email,
+  ...(user.email && { userEmail: user.email }),
 },

Apply the same pattern to both metadata objects.

Also applies to: 118-118

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ed06261 and d24d0aa.

📒 Files selected for processing (3)
  • apps/api/src/routes/payments.ts (2 hunks)
  • apps/api/src/routes/subscriptions.ts (1 hunks)
  • apps/gateway/src/worker.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

Use localStorage instead of cookies for client-side data persistence

Files:

  • apps/api/src/routes/payments.ts
  • apps/api/src/routes/subscriptions.ts
  • apps/gateway/src/worker.ts
**/*.{js,ts}

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

**/*.{js,ts}: Use drizzle with the latest object syntax for database operations
For read queries, always use db().query.<table>.findMany() or db().query.<table>.findFirst()

Files:

  • apps/api/src/routes/payments.ts
  • apps/api/src/routes/subscriptions.ts
  • apps/gateway/src/worker.ts
{apps/api,apps/gateway,packages/db}/**/*.ts

📄 CodeRabbit Inference Engine (CLAUDE.md)

{apps/api,apps/gateway,packages/db}/**/*.ts: Use Drizzle ORM with latest object syntax for database operations
For reads, use db().query.<table>.findMany() or db().query.<table>.findFirst()

Files:

  • apps/api/src/routes/payments.ts
  • apps/api/src/routes/subscriptions.ts
  • apps/gateway/src/worker.ts
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/general.mdc)

Never use as any or : any in TypeScript files.

Files:

  • apps/api/src/routes/payments.ts
  • apps/api/src/routes/subscriptions.ts
  • apps/gateway/src/worker.ts
🧬 Code Graph Analysis (1)
apps/gateway/src/worker.ts (2)
packages/db/src/db.ts (1)
  • db (13-17)
apps/api/src/stripe.ts (1)
  • handlePaymentIntentSucceeded (316-425)
⏰ 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). (3)
  • GitHub Check: build / run
  • GitHub Check: e2e / run
  • GitHub Check: autofix
🔇 Additional comments (2)
apps/gateway/src/worker.ts (2)

126-136: LGTM! Good implementation of organization user lookup.

The query correctly uses Drizzle ORM with the latest object syntax as specified in the coding guidelines. Fetching the first user associated with the organization is a reasonable approach for auto top-up metadata.


185-185: Excellent null safety pattern.

The conditional spread syntax ...(orgUser?.user?.email && { userEmail: orgUser.user.email }) provides robust null safety and should be the preferred pattern across all implementations.

This approach could be adopted in the payments.ts and subscriptions.ts files for consistency.

Merged via the queue into main with commit b3a7af1 Aug 2, 2025
@steebchen
steebchen deleted the feat/stripe-meteadata branch August 2, 2025 00:26
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