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

@@ -100,6 +100,9 @@ LEMON_SQUEEZY_CANCEL_URL=/payment/cancel
# Polar.sh Payment Provider
POLAR_API_KEY=
POLAR_WEBHOOK_SECRET=
POLAR_SANDBOX=false
POLAR_SANDBOX_API_KEY=
POLAR_SANDBOX_WEBHOOK_SECRET=
POLAR_ACCESS_TOKEN=
POLAR_SUCCESS_URL=/payment/success
POLAR_CANCEL_URL=/payment/cancel