managed stripe change in env to trigger db refresh
This commit is contained in:
parent
3be0967936
commit
7cbcaacda1
1 changed files with 45 additions and 21 deletions
|
|
@ -154,6 +154,23 @@ def _createStripePrice(stripe, productId: str, unitAmountCHF: float, interval: s
|
||||||
return price.id
|
return price.id
|
||||||
|
|
||||||
|
|
||||||
|
def _validateStripeIdsExist(stripe, mapping: StripePlanPrice) -> bool:
|
||||||
|
"""Quick check whether at least the stored product IDs still exist in Stripe.
|
||||||
|
Returns False when running against a different Stripe account or after DB copy."""
|
||||||
|
try:
|
||||||
|
if mapping.stripeProductIdUsers:
|
||||||
|
stripe.Product.retrieve(mapping.stripeProductIdUsers)
|
||||||
|
if mapping.stripeProductIdInstances:
|
||||||
|
stripe.Product.retrieve(mapping.stripeProductIdInstances)
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
code = getattr(e, "code", None)
|
||||||
|
if code == "resource_missing":
|
||||||
|
return False
|
||||||
|
logger.debug("Stripe validation check failed (non-critical): %s", e)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def bootstrapStripePrices() -> None:
|
def bootstrapStripePrices() -> None:
|
||||||
"""Ensure all paid plans have separate Stripe Products for users and instances."""
|
"""Ensure all paid plans have separate Stripe Products for users and instances."""
|
||||||
try:
|
try:
|
||||||
|
|
@ -183,6 +200,7 @@ def bootstrapStripePrices() -> None:
|
||||||
hasAllPrices = mapping.stripePriceIdUsers and mapping.stripePriceIdInstances
|
hasAllPrices = mapping.stripePriceIdUsers and mapping.stripePriceIdInstances
|
||||||
hasAllProducts = mapping.stripeProductIdUsers and mapping.stripeProductIdInstances
|
hasAllProducts = mapping.stripeProductIdUsers and mapping.stripeProductIdInstances
|
||||||
if hasAllPrices and hasAllProducts:
|
if hasAllPrices and hasAllProducts:
|
||||||
|
if _validateStripeIdsExist(stripe, mapping):
|
||||||
changed = False
|
changed = False
|
||||||
reconciledUsers = _reconcilePrice(
|
reconciledUsers = _reconcilePrice(
|
||||||
stripe, mapping.stripeProductIdUsers, mapping.stripePriceIdUsers,
|
stripe, mapping.stripeProductIdUsers, mapping.stripePriceIdUsers,
|
||||||
|
|
@ -207,6 +225,12 @@ def bootstrapStripePrices() -> None:
|
||||||
else:
|
else:
|
||||||
logger.debug("Stripe prices up-to-date for plan %s", planKey)
|
logger.debug("Stripe prices up-to-date for plan %s", planKey)
|
||||||
continue
|
continue
|
||||||
|
else:
|
||||||
|
logger.warning(
|
||||||
|
"Stored Stripe IDs for plan %s reference unknown objects "
|
||||||
|
"(likely wrong Stripe account or copied DB) — re-provisioning.",
|
||||||
|
planKey,
|
||||||
|
)
|
||||||
|
|
||||||
productIdUsers = None
|
productIdUsers = None
|
||||||
productIdInstances = None
|
productIdInstances = None
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue