feat(webhooks): enhance Polar webhook processing with proper event handling

- Add support for subscription.uncanceled webhook event
  - Fix spelling mismatch for subscription.canceled (Polar) vs subscription.cancelled (code)
  - Implement proper cancel_at_period_end handling in subscription.canceled events
  - Add cancelled_at field updates for subscription.updated events
  - Handle Polar's spelling variants (canceled_at vs cancelled_at) consistently
  - Remove non-existent pause_reason column from subscription uncanceled handler
  - Enhance webhook logging with detailed field update tracking
  - Add comprehensive cancellation metadata storage in provider_data
  - Gracefully handle null provider_subscription_id in payment confirmation polling

  All Polar webhook events now properly sync subscription state including
  cancellation timing, reasons, and billing period details.
This commit is contained in:
idevakk
2025-12-07 00:57:46 -08:00
parent 289baa1286
commit 1b438cbf89
4 changed files with 182 additions and 11 deletions

View File

@@ -36,6 +36,7 @@ Polar webhook endpoints are automatically configured based on your payment provi
- `subscription.resumed`
- `subscription.trial_will_end`
- `subscription.trial_ended`
- `subscription.uncanceled`
- `customer.state_changed`
## Security Features
@@ -155,6 +156,11 @@ Webhook processing is idempotent to prevent duplicate processing:
- **Action**: Converts trial to active subscription
- **Data**: Trial end date, new billing period
#### `subscription.uncanceled`
- **Trigger**: Previously cancelled subscription is reactivated before cancellation takes effect
- **Action**: Reactivates subscription and clears cancellation details
- **Data**: Subscription ID, new billing period dates, cancellation status cleared
### Customer Events
#### `customer.state_changed`