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.
This commit is contained in:
idevakk
2025-11-22 06:19:27 -08:00
parent 38ae2770ea
commit ad89b84471
4 changed files with 330 additions and 82 deletions

View File

@@ -63,6 +63,9 @@ return [
'polar' => [
'api_key' => env('POLAR_API_KEY'),
'webhook_secret' => env('POLAR_WEBHOOK_SECRET'),
'sandbox' => env('POLAR_SANDBOX', false),
'sandbox_api_key' => env('POLAR_SANDBOX_API_KEY'),
'sandbox_webhook_secret' => env('POLAR_SANDBOX_WEBHOOK_SECRET'),
'success_url' => env('POLAR_SUCCESS_URL', '/payment/success'),
'cancel_url' => env('POLAR_CANCEL_URL', '/payment/cancel'),
'access_token' => env('POLAR_ACCESS_TOKEN'),