Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Oct 3, 2025

Add brev redeem command for coupon code redemption

Summary

Adds a new brev redeem <code> CLI command that allows users to redeem coupon codes for credits in their Brev organization. The implementation includes:

  • New RedeemCouponCode method in the organization store that calls POST /api/organizations/{id}/credits/code/redeem
  • brev redeem command with --org flag support to specify target organization
  • Success message showing credits amount, organization, and operation duration
  • Organization name completion for the --org flag
  • Follows existing CLI patterns from the invite command

Usage:

# Redeem to active organization
brev redeem ABC123XYZ

# Redeem to specific organization  
brev redeem ABC123XYZ --org myorg

Review & Testing Checklist for Human

  • Test end-to-end with real coupon codes - Verify the command works with actual valid and invalid coupon codes
  • Verify API contract matches backend - Confirm the endpoint path /api/organizations/{id}/credits/code/redeem, request body structure {"Code": "..."}, and response format match the actual backend implementation
  • Test error scenarios - Try invalid codes, network failures, authentication issues, and malformed org names to ensure error messages are helpful
  • Test --org flag behavior - Verify organization selection works correctly with various org names, including edge cases like duplicate names

Notes

  • Implementation based on existing patterns from brev-environments-ui/src/server/index.ts and brev invite command
  • API endpoint reverse-engineered from UI code but not tested against live backend
  • Local tests pass except for unrelated version command test that fails due to GitHub API rate limiting

Link to Devin run: https://app.devin.ai/sessions/a77074d17cd54f40879cd855245492d0
Requested by: @theFong

@devin-ai-integration
Copy link
Contributor Author

devin-ai-integration bot commented Oct 3, 2025

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration bot and others added 2 commits October 31, 2025 11:16
- Add RedeemCouponCode method to organization store
- Create new redeem command with --org flag support
- Wire command into CLI command tree
- Include completion handler for org names
- Display success message with credits amount and duration

Co-Authored-By: Alec Fong <[email protected]>
@cloin cloin force-pushed the devin/1759450541-add-redeem-coupon-command branch from aab2df1 to 9a0633d Compare October 31, 2025 15:26
@cloin cloin requested a review from a team as a code owner October 31, 2025 15:26
@cloin cloin self-assigned this Oct 31, 2025
@patelspratik
Copy link
Contributor

so these coupon codes are for adding value to a Org almost like a gift card? How does this jive with the concept of the Coupon that we attached to launchables that do the like "first 10 deploys are free". Is this a separate concept?

@devin-ai-integration
Copy link
Contributor Author

Hi @patelspratik! Good question. Based on my implementation:

This coupon redemption feature (what I just added):

  • Adds USD credits to an organization's balance (like a gift card)
  • Uses the API endpoint POST /api/organizations/{id}/credits/code/redeem
  • The response includes transaction.amount_usd showing how much credit was added
  • This is the same endpoint that the Brev UI uses in the billing context

I implemented this based on the existing API endpoint I found in brev-environments-ui/src/contexts/BillingContext.tsx and src/server/index.ts. The endpoint appears to be specifically for adding dollar-amount credits to an org's balance.

As for how this relates to the launchables coupon system you mentioned (like "first 10 deploys free") - that's a product architecture question I'd defer to @theFong or the team. I just implemented the CLI command to match what the UI already supports for credit redemption.

@cloin
Copy link
Contributor

cloin commented Oct 31, 2025

That's a good call out. I think there's a difference between coupons and credit codes created from the admin portal. I'll have to look into it a bit more and may need to make the distinction here.

@cloin cloin merged commit 71cb57d into main Nov 3, 2025
9 checks passed
@cloin cloin deleted the devin/1759450541-add-redeem-coupon-command branch November 3, 2025 15:31
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.

3 participants