ADORSYS-GIS / ADORSYS-GIS/likelee-ai
Bug: Creator subscription trial not upgrading plan on staging - webhook fires but database status unchanged
- Vorherrschende Sprache
- TypeScript
- Sterne
- 3
- Forks
- 1
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
# Bug Report: Creator Subscription Trial Not Working on Staging
## Description
When creators subscribe to trial plans (Basic/Pro free trial), they should get access to all features for the trial duration (30 days). This works correctly locally, but on the staging server, creators remain on the Free plan after applying for a trial. The webhook is fired, but the database `plan_tier` status is never updated.
## Expected Behavior
1. Creator initiates checkout with `start_trial: true`
2. Stripe creates subscription with status `trialing`
3. Webhook `checkout.session.completed` fires
4. `sync_creator_subscription_from_stripe()` updates creator record:
- `plan_tier` → "basic" or "pro"
- `trial_started_at`, `trial_basic_started_at`/`trial_pro_started_at` timestamps
- `subscription_status` → "trialing"
5. Creator gets elevated entitlements via `get_creator_entitlement_tier()`
## Actual Behavior (Staging)
- Webhook fires successfully
- Creator remains on `plan_tier = "free"`
- Trial timestamps may not be set
- Entitlements stay at Free tier level
## Code Analysis
### Key Files Involved
- `likelee-server/src/payouts.rs:1614-1650` - Webhook handler for `checkout.session.completed` with `billing_domain == "creator"`
- `likelee-server/src/payouts.rs:5118-5232` - `sync_creator_subscription_from_stripe()` function
- `likelee-server/src/billing.rs:3086-3118` - Creator checkout session creation with trial
- `likelee-server/src/entitlements.rs:521-556` - `get_creator_entitlement_tier()` trial evaluation
### Potential Root Causes
1. **Status matching in sync function** (`payouts.rs:5135-5150`):
```rust
let (plan_tier, plan_interval) = match (
stripe_subscription_to_plan_tier(state, &sub),
status.as_str(),
) {
(Some(t), "active") | (Some(t), "trialing") => {
// Only sets plan tier if status is active or trialing
}
_ => ("none", "month"), // Falls back to "none" for other statuses
};
```
If the subscription status isn't "trialing" at the time of webhook processing, plan_tier becomes "none".
2. **Metadata not passed correctly**: The checkout session sets metadata (`plan_tier`, `trial_started_from_checkout`), but the subscription retrieved in `sync_creator_subscription_from_stripe()` may not have this metadata.
3. **Price ID matching failure**: `stripe_subscription_to_plan_tier_from_price_id()` (`payouts.rs:4101-4140`) may not match trial subscription price IDs if staging has different Stripe price configurations.
4. **Silent failures**: All database updates use `let _ =`, meaning errors are silently ignored:
```rust
let _ = state.pg.from("creators").eq("id", creator_id).update(...).execute().await;
```
## Debugging Steps Needed
### 1. Add Logging
Add comprehensive logging to `sync_creator_subscription_from_stripe()`:
- Log the subscription status received from Stripe
- Log the metadata fields
- Log the price IDs being matched
- Log the final plan_tier being set
- Log any database update errors
### 2. Check Staging Stripe Configuration
Verify these environment variables are set correctly on staging:
- `STRIPE_CREATOR_BASIC_PRICE_ID`
- `STRIPE_CREATOR_PRO_PRICE_ID`
- `STRIPE_CREATOR_BASIC_ANNUAL_PRICE_ID`
- `STRIPE_CREATOR_PRO_ANNUAL_PRICE_ID`
- `STRIPE_WEBHOOK_SECRET`
### 3. Test Webhook Flow
- Trigger a test checkout session on staging
- Monitor webhook delivery in Stripe Dashboard
- Check `webhook_events` table for the event
- Check `creator_subscription_events` table for sync attempts
- Verify the creator record in `creators` table
### 4. Compare Local vs Staging
- Check Stripe API version differences
- Check if webhooks are configured identically
- Verify database schema matches (trial columns exist)
## Reproduction Steps
1. Deploy to staging environment
2. Create a creator account
3. Navigate to creator subscription/upgrade page
4. Select a trial plan (Basic or Pro)
5. Complete checkout
6. Check creator `plan_tier` in database - should be "basic" or "pro" but remains "free"
7. Verify entitlements - should have trial access but doesn't
## Environment
- **Local**: Works correctly
- **Staging**: Fails - plan_tier not updated
- **Webhook**: Fires but database unchanged
## Priority
**High** - This blocks creator subscription functionality on staging and potentially production.
## Suggested Fix
1. Add error logging to all `let _ =` database operations in the webhook handler
2. Add debug logging for subscription status, metadata, and price ID matching
3. Ensure metadata from checkout session is properly propagated to subscription
4. Consider adding a retry mechanism for failed webhook processing
5. Add monitoring/alerting for webhook processing failures
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Bewertung
Dieses Issue wurde noch nicht bewertet.