Skip to content

chore(chat): migrate GET /api/credits#1725

Closed
arpitgupta1214 wants to merge 6 commits intotestfrom
migrate/billing-group3
Closed

chore(chat): migrate GET /api/credits#1725
arpitgupta1214 wants to merge 6 commits intotestfrom
migrate/billing-group3

Conversation

@arpitgupta1214
Copy link
Copy Markdown
Collaborator

@arpitgupta1214 arpitgupta1214 commented May 1, 2026

Repoints useCredits at recoup-api (Privy bearer) and deletes chat's local /api/credits/get route. Will only merge once api PR #500 lands.

Test plan

  • Logged-in user sees correct credits in the UI
  • Request resolves against recoup-api (network tab)

Group 3 (Billing read) of the chat→api migration plan. Repoints
usePayment's two reads at recoup-api and deletes the now-orphan local
routes + their helpers.

- hooks/useProStatus.ts: fetches ${getClientApiBaseUrl()}/api/subscription/status
  (inlines ProStatusResponse since the deleted route used to export it).
- lib/supabase/getCredits.tsx: fetches ${getClientApiBaseUrl()}/api/credits/get.
- Deleted app/api/credits/get/, app/api/subscription/status/,
  lib/credits/checkAndResetCredits.ts, lib/stripe/getOrgSubscription.ts
  (each only had the deleted route or that helper as a caller).

Will only merge once api PR #500 lands.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chat Ready Ready Preview May 9, 2026 1:40pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 1, 2026

Warning

Rate limit exceeded

@arpitgupta1214 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 26 minutes and 9 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a6942add-87dd-42b3-99f1-03f956eafbe3

📥 Commits

Reviewing files that changed from the base of the PR and between 9e94db1 and 8be0d87.

📒 Files selected for processing (6)
  • app/api/credits/get/route.ts
  • hooks/useCredits.ts
  • lib/credits/checkAndResetCredits.ts
  • lib/credits/getCredits.ts
  • lib/stripe/getOrgSubscription.ts
  • lib/supabase/getCredits.tsx
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch migrate/billing-group3

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

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

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 6 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: This PR migrates core billing and subscription logic to an external API. Such changes involve critical business paths and require human verification of the integration.

Mirrors the api PR: drops the `accountId` query param in favor of a
Privy access token, and uses the renamed paths.

- useCredits: now wraps usePrivy + passes accessToken to getCredits
- useProStatus: now wraps usePrivy and Bearer-authenticates against
  /api/subscriptions/status
- getCredits: signature changes from (accountId) to (accessToken); hits
  /api/credits

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 3 files (changes from recent commits).

Requires human review: This PR migrates core billing and subscription logic to an external API, which is high-impact and involves cross-service dependencies.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="hooks/useProStatus.ts">

<violation number="1" location="hooks/useProStatus.ts:13">
P1: The migrated URL appears to target the wrong endpoint (`/api/subscription` instead of `/api/subscription/status`). This can return the wrong payload or fail at runtime.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread hooks/useSubscription.ts Outdated
Mirrors the api refactor: there is only one subscription endpoint, so
"status" was redundant. The hook now returns the full Stripe Subscription
(account-level preferred over org-level) plus a `source` marker, while
usePayment still derives `isSubscribed` from `data.isPro`.

- hooks/useProStatus.ts → hooks/useSubscription.ts
- ProStatusResponse → SubscriptionResponse (now carries
  `subscription: Stripe.Subscription | null` and
  `source: "account" | "organization" | null`)
- usePayment: imports useSubscription instead

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 2 files (changes from recent commits).

Requires human review: Auto-approval blocked by 1 unresolved issue from previous reviews.

It's an HTTP client now (fetches /api/credits from recoup-api), not a
Supabase operation. Moves to lib/credits/getCredits.ts and drops the
.tsx extension since there is no JSX.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 2 files (changes from recent commits).

Requires human review: Auto-approval blocked by 1 unresolved issue from previous reviews.

@arpitgupta1214 arpitgupta1214 changed the title chore(chat): migrate GET /api/credits/get + GET /api/subscription/status chore(chat): migrate GET /api/credits May 9, 2026
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.

1 participant