Commit Graph

13 Commits

Author SHA1 Message Date
idevakk
0d33c57b32 feat(notifications): implement comprehensive telegram notifications for payment providers
- Add NotifyMe trait with centralized Telegram bot integration
  - Implement webhook notifications for Polar, OxaPay, and ActivationKey providers
  - Add subscription lifecycle notifications (create, activate, cancel, pause, resume)
  - Enhance Polar webhook processing with user context and error handling
  - Fix subscription.updated and subscription.canceled webhook column errors
  - Add idempotent webhook processing to prevent duplicate handling
2025-12-08 09:25:19 -08:00
idevakk
5fabec1f9d fix(plans): prevent deletion of plans with active subscriptions
- Fix bulk delete and individual delete actions using before() hook with halt()
  - Add daily/weekly billing cycle options to plan resource and Polar provider
  - Enhance payment confirmation with dynamic polling and loading states
  - Add graceful handling for deleted plans in subscription display
  - Update Polar provider to support dynamic billing cycles
2025-12-07 02:23:14 -08:00
idevakk
1b438cbf89 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.
2025-12-07 00:57:46 -08:00
idevakk
289baa1286 feat(payments): implement standard webhooks validation system
Add comprehensive webhook validation and processing system with Polar.sh integration:

  - Create built-in Standard Webhooks package following official specification
  - Implement HMAC-SHA256 signature validation with base64 encoding
  - Add webhook factory for multi-provider support (Polar, Stripe, generic)
  - Replace custom Polar webhook validation with Standard Webhooks implementation
  - Add proper exception handling with custom WebhookVerificationException
  - Support sandbox mode bypass for development environments
  - Update Polar provider to use database-driven configuration
  - Enhance webhook test suite with proper Standard Webhooks format
  - Add PaymentProvider model HasFactory trait for testing
  - Implement timestamp tolerance checking (±5 minutes) for replay protection
  - Support multiple signature versions and proper header validation

  This provides a secure, reusable webhook validation system that can be extended
  to other payment providers while maintaining full compliance with Standard
  Webhooks specification.

  BREAKING CHANGE: Polar webhook validation now uses Standard Webhooks format
  with headers 'webhook-id', 'webhook-timestamp', 'webhook-signature' instead of
  previous Polar-specific headers.
2025-12-06 22:49:54 -08:00
idevakk
15e018eb88 feat(payment): implement comprehensive Polar subscription sync with proper date and cancellation handling
- Add Polar-specific date field mapping in PaymentOrchestrator (current_period_start, current_period_end, cancelled_at, trial_end)
  - Handle both cancellation scenarios: cancel_at_period_end=true and existing cancelled_at timestamp
  - Map customer_cancellation_reason and customer_cancellation_comment from Polar to database
  - Update billing page to show correct renewal vs expiry dates based on cancellation status
  - Restrict cancel button to activation_key provider only (Polar uses customer portal)
  - Fix button spacing between "Manage in Polar" and "Sync" buttons
  - Ensure both "Sync" and "Recheck Status" buttons use identical sync functionality
2025-12-06 10:42:25 -08:00
idevakk
0724e6da43 feat(payments): implement smart Polar subscription sync with checkout tracking
- Add provider_checkout_id column to separate checkout ID from subscription ID
   - Update Polar provider to store checkout ID separately and set subscription ID to null initially
   - Implement smart sync logic that queries Polar API when subscription ID is missing
   - Add fetchPolarSubscriptionId method to find active subscriptions via customer ID
   - Update webhook handlers to use provider_checkout_id for subscription lookup
   - Make makeAuthenticatedRequest public to enable Subscription model API access
   - Support plan metadata matching for accurate subscription identification
   - Add fallback to most recent active subscription when no exact match found

   This resolves sync button issues by properly tracking checkout vs subscription IDs
   and enables automatic subscription ID recovery when webhooks fail.
2025-12-06 02:37:52 -08:00
idevakk
5ee5c5b8dc feat(billing): implement Polar customer portal integration
- Add comprehensive billing page with current subscription display and transaction history
   - Integrate Polar.sh customer portal for subscription management
   - Fix Polar API endpoint from /customer-portal to /customer-sessions
   - Use Polar's direct customer_portal_url response for seamless redirect
   - Add responsive button layout with cursor-pointer styling
   - Implement human-readable timestamps using diffForHumans()
   - Add subscription sync functionality with 30-minute recheck window
   - Include subscription cancellation with modal confirmation
   - Support activation key provider with pending activation display
   - Add proper error handling and user feedback messages
2025-12-06 02:03:56 -08:00
idevakk
34183dc3cb feat(payment): implement secure 1:1 Polar customer binding system
- Add polar_cust_id column to users table for direct customer mapping
  - Rewrite PolarProvider customer logic to use stored customer IDs
  - Eliminate email-based customer lookup to prevent cross-user contamination
  - Implement self-healing mechanism for invalid customer IDs
  - Maintain external_id binding for Polar's reference system
  - Add comprehensive logging for customer lookup operations
2025-12-04 13:05:47 -08:00
idevakk
cd8d6f1165 feat(payments): add error sanitization for Polar payment provider
- Add sanitizePolarErrorMessage() method to convert API errors to user-friendly messages
  - Improve error logging with structured data instead of raw response bodies
  - Add validation error handling with field-specific messages
  - Remove sensitive information (emails, domains, UUIDs) from error messages
  - Update checkout, subscription, customer, and product error handling
  - Add status code-based error mapping for better user experience
2025-12-04 12:30:39 -08:00
idevakk
8950988eac feat(payment): implement beautiful payment confirmation page with real-time status checking
- Add PaymentSuccessController with authentication and subscription selection logic
   - Create PaymentConfirmation Livewire component with polling mechanism
   - Implement real-time subscription status verification via Polar provider API
   - Add confetti animation for successful payment confirmation
   - Design responsive payment success page with dark mode support
   - Fix Polar provider field mapping (updated_at -> modified_at)
   - Add comprehensive error handling and logging
   - Support multiple subscription status states (verifying, activated, pending, error)
   - Implement automatic polling with 30-second intervals (max 5 attempts)
   - Add fallback redirects and user-friendly status messages
2025-12-04 11:59:09 -08:00
idevakk
75086ad83b feat(payment): integrate Polar.sh payment provider with checkout flow
- Build PolarProvider from scratch with proper HTTP API integration
  - Add encrypted configuration loading from payment_providers table via model
  - Implement sandbox/live environment switching with proper credential handling
  - Fix product creation API structure for Polar.sh requirements
  - Add comprehensive error handling and logging throughout checkout flow
  - Fix PaymentController checkout URL handling to support Polar's checkout_url response
  - Add debug logging for troubleshooting checkout session creation
  - Support both regular and trial checkout flows for Polar payments
2025-12-04 10:29:25 -08:00
idevakk
ad89b84471 feat(payments): enhance Polar.sh provider with official API compliance
- Add comprehensive rate limiting (300 req/min) with automatic throttling
  - Implement centralized API request method for consistent authentication
  - Add support for Polar-specific webhook events (order.created, order.paid, subscription.active, customer.state_changed, benefit_grant.created)
  - Update API endpoints to match Polar's official structure (remove /v1 prefix)
  - Add external_id support for reliable customer-user mapping
  - Implement sandbox mode with separate credentials configuration
  - Add discount code support in checkout flow
  - Add credential validation method for API connectivity testing
  - Update webhook signature validation and event handling
  - Enhance error handling and logging throughout provider
  - Add proper metadata structure with user and plan information
  - Update services configuration and environment variables for sandbox support

  BREAKING CHANGE: Updated API endpoint structure and webhook event handling to comply with Polar.sh official API specification.
2025-11-22 06:19:27 -08:00
idevakk
27ac13948c feat: implement comprehensive multi-provider payment processing system
- Add unified payment provider architecture with contract-based design
  - Implement 6 payment providers: Stripe, Lemon Squeezy, Polar, Oxapay, Crypto, Activation Keys
  - Create subscription management with lifecycle handling (create, cancel, pause, resume, update)
  - Add coupon system with usage tracking and trial extensions
  - Build Filament admin resources for payment providers, subscriptions, coupons, and trials
  - Implement payment orchestration service with provider registry and configuration management
  - Add comprehensive payment logging and webhook handling for all providers
  - Create customer analytics dashboard with revenue, churn, and lifetime value metrics
  - Add subscription migration service for provider switching
  - Include extensive test coverage for all payment functionality
2025-11-19 09:37:00 -08:00