This commit is contained in:
LathanDevers
2026-07-16 09:05:24 +02:00
parent eb48f506cf
commit 151aca69de
3 changed files with 133 additions and 13 deletions
@@ -214,7 +214,7 @@ export default function SubscriptionManager({ order, onClose, onRefresh, onAlert
const currentPlanFromCatalog = catalog.find(p => p.id === currentPlanId);
const baseCurrent = parseFloat(currentPlanFromCatalog?.pricing?.recurrent?.['1M']?.price || 0);
const baseSelected = parseFloat(selectedPlan?.pricing?.recurrent?.['1M']?.price || 0);
if (selectedPlan.id === currentPlanId) {
actionType = 'cycle';
} else if (baseSelected < baseCurrent) {
@@ -225,11 +225,11 @@ export default function SubscriptionManager({ order, onClose, onRefresh, onAlert
const resp = await fetch(`${CUSTOM_API_BASE_URL}/custom_api/nexus_subscription.php`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({
action: 'migrate',
order_id: order.id,
target_plan_id: selectedPlan.id,
new_period: billingPeriod,
body: new URLSearchParams({
action: 'migrate',
order_id: order.id,
target_plan_id: selectedPlan.id,
new_period: billingPeriod,
new_price: finalInvoicePrice.toFixed(2),
action_type: actionType // 🎯 On envoie l'information au backend !
})
@@ -240,18 +240,29 @@ export default function SubscriptionManager({ order, onClose, onRefresh, onAlert
onClose?.();
setTimeout(() => window.location.href = '/facturation', 2000);
} else {
onAlert?.("Erreur", data.error, "error");
onAlert?.("Erreur", data.error, "error");
}
} catch (err) {
onAlert?.("Erreur", "Problème réseau", "error");
} finally {
setLoading(false);
} catch (err) {
onAlert?.("Erreur", "Problème réseau", "error");
} finally {
setLoading(false);
}
};
const handleCancel = async () => {
if (!window.confirm("Êtes-vous sûr de vouloir résilier cet abonnement ? Le service sera désactivé au prochain cycle de facturation.")) {
return;
try {
const response = await cancelSubscription(user.id, order.id);
// Le message s'adapte tout seul !
// Soit: "Annulé avec effet immédiat et remboursé"
// Soit: "Actif jusqu'à la fin de la période"
alert(response.message);
// Rafraîchir la liste des abonnements...
} catch (error) {
alert("Erreur lors de l'annulation : " + error.message);
}
}
setCancelLoading(true);