From e9bd07a9bf7ba6288c2db0164f5b0fe2c17be0ca Mon Sep 17 00:00:00 2001 From: Tsvetozar Penov Date: Mon, 21 Jul 2025 16:12:51 +0200 Subject: [PATCH] Add san balance discount only for sanbase plans --- .../billing/subscription/subscription.ex | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/sanbase/billing/subscription/subscription.ex b/lib/sanbase/billing/subscription/subscription.ex index e136ceadfc..72546ca6e3 100644 --- a/lib/sanbase/billing/subscription/subscription.ex +++ b/lib/sanbase/billing/subscription/subscription.ex @@ -20,6 +20,7 @@ defmodule Sanbase.Billing.Subscription do require Logger + # SAN balance discount only applies to Sanbase plans @percent_discount_1000_san 20 @generic_error_message """ @@ -596,12 +597,18 @@ defmodule Sanbase.Billing.Subscription do end end - # When user doesn't provide coupon - check if he has SAN staked - defp create_stripe_subscription(user, plan, nil) do + # When user doesn't provide coupon - check if he has SAN staked (only for Sanbase plans) + defp create_stripe_subscription(user, %Plan{product_id: product_id} = plan, nil) do percent_off = - user - |> User.san_balance_or_zero() - |> percent_discount() + case product_id == @product_sanbase do + true -> + user + |> User.san_balance_or_zero() + |> percent_discount() + + false -> + nil + end # recalc percent off if customer buys annual subscription and is within 30 days from trial start date # comment temporarily until we decide to bring the annual discounts back