mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-30 02:23:47 +00:00
fix(subscription): forward subscription_id to purchaseTariff to fix renew race
Companion to bedolaga-bot a527df23. Bot's purchase-tariff endpoint now accepts optional subscription_id to resolve the EXACT target row by ID instead of doing a (user_id, tariff_id) re-lookup that races with concurrent panel webhooks (produces 'Тариф уже активен' + refund + no extension). Frontend changes: * subscriptionApi.purchaseTariff() — new optional subscriptionId arg appended after trafficGb. Forwarded as subscription_id in POST body. * SubscriptionPurchase.tsx — forwards URL searchParam subscriptionId (set when user lands here from 'Renew this subscription'). * SubscriptionCardExpired.tsx — passes subscription.id when renewing an expired daily tariff (the .purchaseTariff(tariff_id, 1) call).
This commit is contained in:
@@ -305,7 +305,17 @@ export default function SubscriptionPurchase() {
|
||||
: selectedTariffPeriod?.days || 30;
|
||||
const trafficGb =
|
||||
useCustomTraffic && selectedTariff.custom_traffic_enabled ? customTrafficGb : undefined;
|
||||
return subscriptionApi.purchaseTariff(selectedTariff.id, days, trafficGb);
|
||||
// Forward the subscription_id when the user landed here via the
|
||||
// "Renew this subscription" flow (?subscriptionId=N). The backend
|
||||
// uses it to resolve the exact target row by ID, avoiding the
|
||||
// race with concurrent panel webhooks that would otherwise hit
|
||||
// the partial UNIQUE on uq_subscriptions_user_tariff_active.
|
||||
return subscriptionApi.purchaseTariff(
|
||||
selectedTariff.id,
|
||||
days,
|
||||
trafficGb,
|
||||
subscriptionId ?? undefined,
|
||||
);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['subscription'] });
|
||||
|
||||
Reference in New Issue
Block a user