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
This commit is contained in:
@@ -257,7 +257,7 @@ class PolarProvider implements PaymentProviderContract
|
||||
$subscription = Subscription::create([
|
||||
'user_id' => $user->id,
|
||||
'plan_id' => $plan->id,
|
||||
'type' => 'recurring',
|
||||
'type' => 'default',
|
||||
'stripe_id' => $checkout['id'], // Using stripe_id field for Polar checkout ID
|
||||
'stripe_status' => 'pending',
|
||||
'provider' => $this->getName(),
|
||||
@@ -529,20 +529,38 @@ class PolarProvider implements PaymentProviderContract
|
||||
try {
|
||||
$customer = $this->getOrCreateCustomer($user);
|
||||
|
||||
$response = $this->makeAuthenticatedRequest('POST', '/customer-portal', [
|
||||
// Create customer session using correct Polar API endpoint
|
||||
$response = $this->makeAuthenticatedRequest('POST', '/customer-sessions', [
|
||||
'customer_id' => $customer['id'],
|
||||
'return_url' => route('dashboard'),
|
||||
]);
|
||||
|
||||
if (! $response->successful()) {
|
||||
Log::error('Polar customer portal creation failed: '.$response->body());
|
||||
Log::error('Polar customer session creation failed: '.$response->body());
|
||||
throw new \Exception('Failed to create customer session');
|
||||
}
|
||||
|
||||
$portal = $response->json();
|
||||
$session = $response->json();
|
||||
|
||||
// Polar provides a direct customer_portal_url in the response
|
||||
if (! isset($session['customer_portal_url'])) {
|
||||
Log::error('Invalid Polar customer session response', [
|
||||
'response' => $session,
|
||||
]);
|
||||
throw new \Exception('Invalid customer session response - missing portal URL');
|
||||
}
|
||||
|
||||
Log::info('Polar customer portal session created successfully', [
|
||||
'user_id' => $user->id,
|
||||
'customer_id' => $customer['id'],
|
||||
'portal_url' => $session['customer_portal_url'],
|
||||
]);
|
||||
|
||||
return [
|
||||
'portal_url' => $portal['url'],
|
||||
'portal_url' => $session['customer_portal_url'],
|
||||
'customer_id' => $customer['id'],
|
||||
'session_token' => $session['token'] ?? null,
|
||||
'expires_at' => $session['expires_at'] ?? null,
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
Reference in New Issue
Block a user