feat: implements activation key as payment provider and migrate activation key to use unified payment system
This commit is contained in:
@@ -5,7 +5,6 @@ namespace App\Livewire\Dashboard;
|
||||
use App\Models\ActivationKey;
|
||||
use App\Models\Plan;
|
||||
use App\Models\PlanTier;
|
||||
use App\Services\Payments\PaymentOrchestrator;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
@@ -125,29 +124,15 @@ class Pricing extends Component
|
||||
private function activateSubscriptionKey(ActivationKey $activation): bool
|
||||
{
|
||||
try {
|
||||
// Use PaymentOrchestrator for activation key processing
|
||||
$orchestrator = app(PaymentOrchestrator::class);
|
||||
|
||||
// Find the plan associated with this activation key
|
||||
$plan = null;
|
||||
if ($activation->plan_id) {
|
||||
$plan = Plan::find($activation->plan_id);
|
||||
} elseif ($activation->price_id) {
|
||||
// Fallback to legacy pricing_id lookup
|
||||
$plan = Plan::where('pricing_id', $activation->price_id)->first();
|
||||
}
|
||||
|
||||
if (! $plan) {
|
||||
Log::error('No plan found for activation key: '.$activation->id);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create subscription using orchestrator
|
||||
// Use the ActivationKeyProvider directly
|
||||
$provider = app(\App\Services\Payments\Providers\ActivationKeyProvider::class);
|
||||
$user = auth()->user();
|
||||
$subscription = $orchestrator->createSubscriptionFromActivationKey($user, $activation, $plan);
|
||||
|
||||
if ($subscription) {
|
||||
// Redeem the activation key using the provider
|
||||
$result = $provider->redeemActivationKey($activation->activation_key, $user);
|
||||
|
||||
if ($result['success']) {
|
||||
// Mark activation key as used
|
||||
$activation->is_activated = true;
|
||||
$activation->user_id = $user->id;
|
||||
$activation->save();
|
||||
@@ -155,6 +140,8 @@ class Pricing extends Component
|
||||
return true;
|
||||
}
|
||||
|
||||
Log::error('Activation key redemption failed: '.$result['message'] ?? 'Unknown error');
|
||||
|
||||
return false;
|
||||
} catch (Exception $e) {
|
||||
Log::error('Activation key processing failed: '.$e->getMessage());
|
||||
|
||||
Reference in New Issue
Block a user