feat: implements activation key as payment provider and migrate activation key to use unified payment system

This commit is contained in:
idevakk
2025-11-21 12:14:20 -08:00
parent 7ca3d44d59
commit 0baacdc386
4 changed files with 407 additions and 93 deletions

View File

@@ -335,24 +335,47 @@ class ActivationKeyProvider implements PaymentProviderContract
'is_activated' => true,
]);
// Find or create subscription
$plan = Plan::findOrFail($keyRecord->price_id);
// Find the plan associated with this activation key
$plan = Plan::where('pricing_id', $keyRecord->price_id)->first();
if (! $plan) {
throw new \Exception('No plan found for activation key with pricing_id: '.$keyRecord->price_id);
}
// Calculate subscription end date based on plan billing cycle
$endsAt = null;
if ($plan->billing_cycle_days && $plan->billing_cycle_days > 0) {
$endsAt = now()->addDays($plan->billing_cycle_days);
}
$subscription = Subscription::create([
'user_id' => $user->id,
'plan_id' => $plan->id,
'type' => 'activation_key',
'stripe_id' => 'ak_'.$keyRecord->id.'_'.uniqid(),
'type' => 'default',
'stripe_id' => 'ak_'.$keyRecord->id.'_'.uniqid('', true),
'stripe_status' => 'active',
'provider' => $this->getName(),
'provider_subscription_id' => $keyRecord->id,
'status' => 'active',
'starts_at' => now(),
'ends_at' => null, // No expiration for activation keys
'ends_at' => $endsAt,
'provider_data' => [
'activation_key' => $activationKey,
'key_id' => $keyRecord->id,
'redeemed_at' => now()->toISOString(),
'plan_details' => [
'name' => $plan->name,
'price' => $plan->price,
'billing_cycle_days' => $plan->billing_cycle_days,
'billing_cycle_display' => $plan->getBillingCycleDisplay(),
'plan_tier' => $plan->planTier ? $plan->planTier->name : null,
'features' => $plan->getFeaturesWithLimits(),
],
'provider_info' => [
'name' => $this->getName(),
'version' => '1.0',
'processed_at' => now()->toISOString(),
],
],
]);