-
Notifications
You must be signed in to change notification settings - Fork 25
feat: subscriptions are here #117
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
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
# Some dev notes | ||
|
||
Test webhooks locally with event forwarding instead of exposing a URL | ||
|
||
```bash | ||
stripe login | ||
|
||
|
||
# This created a webhook secret, then add this to the .env.local file | ||
stripe listen --forward-to https://localhost:1926/api/billing/webhook | ||
|
||
# Manual trigger an event if needed | ||
stripe trigger payment_intent.succeeded | ||
``` | ||
|
||
# Stripe Integration Setup | ||
|
||
This document provides instructions for setting up the Stripe integration for subscription management in the Hopp application. | ||
|
||
## Prerequisites | ||
|
||
1. A Stripe account (https://stripe.com) | ||
2. Products and prices configured in your Stripe Dashboard | ||
3. Webhook endpoint configured in Stripe | ||
|
||
## Environment Variables | ||
|
||
Add the following environment variables to your backend configuration: | ||
|
||
```bash | ||
# Stripe Configuration | ||
STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key_here | ||
STRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key_here | ||
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret_here | ||
|
||
# Stripe Price ID for paid tier (usage-based) | ||
STRIPE_PAID_PRICE_ID=price_paid_plan_id | ||
|
||
# Domain for Stripe redirects (optional) | ||
STRIPE_SUCCESS_URL=http://localhost:3000/subscription/success | ||
STRIPE_CANCEL_URL=http://localhost:3000/subscription/cancel | ||
``` | ||
|
||
## Stripe Dashboard Setup | ||
|
||
### 1. Create Products and Prices | ||
|
||
Create the following product in your Stripe Dashboard: | ||
|
||
#### Paid Plan (Usage-Based) | ||
|
||
- **Name**: Paid Plan | ||
- **Billing Model**: Per-seat or usage-based | ||
- **Price**: $5 per user per month | ||
- **Lookup Key**: `paid_plan` (recommended) | ||
- Copy the Price ID to `STRIPE_PAID_PRICE_ID` | ||
|
||
**Note**: This is a simplified pricing model with only two tiers: | ||
|
||
- **Free**: Up to 5 team members, 3 rooms | ||
- **Paid**: $5 per team member per month, unlimited rooms and members | ||
|
||
### 2. Configure Webhook Endpoint | ||
|
||
1. Go to **Developers > Webhooks** in your Stripe Dashboard | ||
2. Click **Add endpoint** | ||
3. Set the endpoint URL to: `https://your-domain.com/api/billing/webhook` | ||
4. Select the following events to listen for: | ||
- `customer.subscription.created` | ||
- `customer.subscription.updated` | ||
- `customer.subscription.deleted` | ||
- `customer.subscription.trial_will_end` | ||
- `checkout.session.completed` | ||
5. Copy the webhook signing secret to `STRIPE_WEBHOOK_SECRET` | ||
|
||
### 3. Enable Customer Portal (Optional) | ||
|
||
1. Go to **Settings > Billing > Customer portal** | ||
2. Activate the customer portal | ||
3. Configure the allowed features (cancel subscriptions, update payment methods, etc.) | ||
|
||
## API Endpoints | ||
|
||
The following API endpoints are available for Stripe integration: | ||
|
||
### Public Endpoints | ||
|
||
- `GET /api/billing/pricing` - Get pricing information | ||
- `POST /api/billing/webhook` - Stripe webhook handler | ||
|
||
### Protected Endpoints (Require Authentication) | ||
|
||
- `GET /api/auth/billing/subscription` - Get current subscription status | ||
- `POST /api/auth/billing/create-checkout-session` - Create Stripe checkout session | ||
- `POST /api/auth/billing/create-portal-session` - Create billing portal session | ||
- `POST /api/auth/billing/update-usage` - Update current user count for billing | ||
- `POST /api/auth/billing/manual-upgrade` - Manually upgrade a team (admin only) | ||
|
||
## Frontend Integration | ||
|
||
The subscription management is available in the web app: | ||
|
||
1. **Admin-only Access**: Only team administrators can access the subscription page | ||
2. **Subscription Tab**: A "Subscription" tab appears in the sidebar for admin users | ||
3. **Pricing Display**: Shows all available tiers with features and pricing | ||
4. **Current Plan**: Displays the team's current subscription status | ||
5. **Upgrade/Manage**: Allows admins to upgrade plans or manage billing | ||
|
||
## Database Models | ||
|
||
### Subscription Model | ||
|
||
The `Subscription` model tracks subscription details: | ||
|
||
- Team association | ||
- Stripe customer and subscription IDs | ||
- Subscription status and tier | ||
- Billing period information | ||
- Trial information | ||
|
||
### Team Model Updates | ||
|
||
The `Team` model now includes: | ||
|
||
- `Tier` field indicating the subscription tier | ||
- Relationship to `Subscription` model | ||
|
||
## Subscription Tiers and Features | ||
|
||
### Free Tier | ||
|
||
- **Price**: $0 | ||
- **Max Rooms**: 3 | ||
- **Max Team Members**: 5 | ||
- **Features**: Basic video calls, Screen sharing, Chat | ||
|
||
### Paid Tier | ||
|
||
- **Price**: $5 per team member per month | ||
- **Max Rooms**: Unlimited | ||
- **Max Team Members**: Unlimited | ||
- **Features**: Everything in Free + Unlimited rooms, Unlimited team members, Recording, Custom backgrounds, Priority support, Advanced analytics | ||
|
||
## Manual Upgrades | ||
|
||
Teams can be manually upgraded without billing using the `IsManualUpgrade` flag: | ||
|
||
- Manual upgrades give teams access to paid features without Stripe billing | ||
- Useful for special cases, partnerships, or internal teams | ||
- Can be managed via the `/api/auth/billing/manual-upgrade` endpoint | ||
|
||
## Testing | ||
|
||
### Test Mode | ||
|
||
Use Stripe test keys for development: | ||
|
||
- Test Secret Key: `sk_test_...` | ||
- Test Publishable Key: `pk_test_...` | ||
|
||
### Test Cards | ||
|
||
Use Stripe's test card numbers: | ||
|
||
- **Success**: `4242 4242 4242 4242` | ||
- **Decline**: `4000 0000 0000 0002` | ||
- **Authentication Required**: `4000 0025 0000 3155` | ||
|
||
## Security Considerations | ||
|
||
1. **Environment Variables**: Never commit Stripe keys to version control | ||
2. **Webhook Verification**: Always verify webhook signatures | ||
3. **Admin Access**: Subscription management is restricted to team admins | ||
4. **HTTPS**: Use HTTPS in production for webhook endpoints | ||
|
||
## Troubleshooting | ||
|
||
### Common Issues | ||
|
||
1. **Webhook Signature Verification Failed** | ||
|
||
- Ensure `STRIPE_WEBHOOK_SECRET` is correctly set | ||
- Check that the webhook endpoint URL is accessible | ||
|
||
2. **Price ID Not Found** | ||
|
||
- Verify the price IDs in your environment variables | ||
- Ensure the prices exist in your Stripe account | ||
|
||
3. **Subscription Page Not Visible** | ||
- Check that the user is marked as an admin (`is_admin: true`) | ||
- Verify the user is part of a team | ||
|
||
### Logs | ||
|
||
Check the backend logs for Stripe-related errors. The application logs webhook events and API interactions for debugging. | ||
|
||
## Support | ||
|
||
For additional support with Stripe integration: | ||
|
||
1. Check the [Stripe Documentation](https://stripe.com/docs) | ||
2. Review the [Stripe Go SDK](https://github.com/stripe/stripe-go) | ||
3. Contact your development team for application-specific issues |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,5 @@ tmp/ | |
|
||
web/web-app.html | ||
web/web-app-debug.html | ||
|
||
env-files/.env.internal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.