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
This commit is contained in:
idevakk
2025-12-06 10:42:25 -08:00
parent 0724e6da43
commit 15e018eb88
4 changed files with 150 additions and 18 deletions

View File

@@ -482,6 +482,13 @@ class PolarProvider implements PaymentProviderContract
$polarSubscription = $response->json();
// Log the full Polar subscription response for debugging
Log::info('Polar subscription response received', [
'subscription_id' => $providerSubscriptionId,
'response_keys' => array_keys($polarSubscription),
'full_response' => $polarSubscription,
]);
if (! $polarSubscription || ! isset($polarSubscription['id'])) {
Log::error('Invalid Polar subscription response', [
'subscription_id' => $providerSubscriptionId,
@@ -495,13 +502,18 @@ class PolarProvider implements PaymentProviderContract
'status' => $polarSubscription['status'],
'customer_id' => $polarSubscription['customer_id'],
'price_id' => $polarSubscription['price_id'],
'current_period_start' => $polarSubscription['current_period_start'],
'current_period_end' => $polarSubscription['current_period_end'],
'current_period_start' => $polarSubscription['current_period_start'] ?? null,
'current_period_end' => $polarSubscription['current_period_end'] ?? null,
'cancel_at_period_end' => $polarSubscription['cancel_at_period_end'] ?? false,
'trial_start' => $polarSubscription['trial_start'] ?? null,
'trial_end' => $polarSubscription['trial_end'] ?? null,
'created_at' => $polarSubscription['created_at'],
'created_at' => $polarSubscription['created_at'] ?? null,
'updated_at' => $polarSubscription['modified_at'] ?? null,
'ends_at' => $polarSubscription['ends_at'] ?? null, // Check if Polar has ends_at
'expires_at' => $polarSubscription['expires_at'] ?? null, // Check if Polar has expires_at
'cancelled_at' => $polarSubscription['cancelled_at'] ?? null, // Check if Polar has cancelled_at
'customer_cancellation_reason' => $polarSubscription['customer_cancellation_reason'] ?? null,
'customer_cancellation_comment' => $polarSubscription['customer_cancellation_comment'] ?? null,
];
} catch (\Exception $e) {