fix: Corrigir bugs no sistema de cancelamento
🐛 BUGS CORRIGIDOS: 1. SubscriptionCancelledMail - Argumentos incorretos - Estava: (User, Plan, Carbon, bool) - Correto: (User, string, bool, ?string) - Linha: SubscriptionController.php:1214 2. PayPal - Evitar cancelar assinaturas admin-granted - Detectar paypal_subscription_id com prefixo 'ADMIN_GRANTED_' - Skip chamada PayPal para assinaturas gratuitas do admin - Aplica em: executeCancellation() e applyRetentionOffer() 3. Log melhorado - Adicionado paypal_id aos logs de erro ✅ Sistema de cancelamento agora funciona com: - Assinaturas PayPal normais - Assinaturas admin-granted (gratuitas) - Email de cancelamento correto
This commit is contained in:
parent
5d094c2f51
commit
02529adc18
@ -1109,13 +1109,14 @@ private function applyRetentionOffer($user, Subscription $subscription, $feedbac
|
|||||||
: now()->addMonths(3);
|
: now()->addMonths(3);
|
||||||
$subscription->save();
|
$subscription->save();
|
||||||
|
|
||||||
// Cancel PayPal subscription for 3 months (pause)
|
// Suspend PayPal subscription for 3 months (skip admin-granted subscriptions)
|
||||||
if ($subscription->paypal_subscription_id) {
|
if ($subscription->paypal_subscription_id && !str_starts_with($subscription->paypal_subscription_id, 'ADMIN_GRANTED_')) {
|
||||||
try {
|
try {
|
||||||
$this->paypal->suspendSubscription($subscription->paypal_subscription_id);
|
$this->paypal->suspendSubscription($subscription->paypal_subscription_id);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::warning('Failed to suspend PayPal subscription', [
|
Log::warning('Failed to suspend PayPal subscription', [
|
||||||
'subscription_id' => $subscription->id,
|
'subscription_id' => $subscription->id,
|
||||||
|
'paypal_id' => $subscription->paypal_subscription_id,
|
||||||
'error' => $e->getMessage(),
|
'error' => $e->getMessage(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -1177,13 +1178,14 @@ private function executeCancellation($user, Subscription $subscription, $reason,
|
|||||||
try {
|
try {
|
||||||
$withinGuaranteePeriod = $subscription->created_at->diffInDays(now()) <= 7;
|
$withinGuaranteePeriod = $subscription->created_at->diffInDays(now()) <= 7;
|
||||||
|
|
||||||
// Cancel on PayPal if exists
|
// Cancel on PayPal if exists (skip admin-granted subscriptions)
|
||||||
if ($subscription->paypal_subscription_id) {
|
if ($subscription->paypal_subscription_id && !str_starts_with($subscription->paypal_subscription_id, 'ADMIN_GRANTED_')) {
|
||||||
try {
|
try {
|
||||||
$this->paypal->cancelSubscription($subscription->paypal_subscription_id);
|
$this->paypal->cancelSubscription($subscription->paypal_subscription_id);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::warning('Failed to cancel PayPal subscription', [
|
Log::warning('Failed to cancel PayPal subscription', [
|
||||||
'subscription_id' => $subscription->id,
|
'subscription_id' => $subscription->id,
|
||||||
|
'paypal_id' => $subscription->paypal_subscription_id,
|
||||||
'error' => $e->getMessage(),
|
'error' => $e->getMessage(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -1213,9 +1215,9 @@ private function executeCancellation($user, Subscription $subscription, $reason,
|
|||||||
try {
|
try {
|
||||||
Mail::to($user->email)->send(new SubscriptionCancelledMail(
|
Mail::to($user->email)->send(new SubscriptionCancelledMail(
|
||||||
$user,
|
$user,
|
||||||
$subscription->plan,
|
$subscription->plan->name,
|
||||||
$subscription->ends_at,
|
$withinGuaranteePeriod,
|
||||||
$withinGuaranteePeriod
|
$withinGuaranteePeriod ? $subscription->plan->formatted_price : null
|
||||||
));
|
));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::warning('Failed to send cancellation email', [
|
Log::warning('Failed to send cancellation email', [
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user