π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[server] Refactor /user/plans
Neeraj Guptac0a2347b80ac
diff --git a/server/ente/billing.go b/server/ente/billing.goindex 4d8d3401d0..5a0ff08a86 100644--- a/server/ente/billing.go+++ b/server/ente/billing.go@@ -176,11 +176,6 @@ type SubscriptionUpdateResponse struct {ClientSecret string `json:"clientSecret"`}-type StripeSubscriptionInfo struct {- PlanCountry string- AccountCountry StripeAccountCountry-}-type StripeEventLog struct {UserID int64StripeSubscription stripe.Subscriptiondiff --git a/server/pkg/controller/billing.go b/server/pkg/controller/billing.goindex 228a3344bc..0d01aeeb9a 100644--- a/server/pkg/controller/billing.go+++ b/server/pkg/controller/billing.go@@ -85,30 +85,27 @@ func (c *BillingController) GetPlansV2(countryCode string, stripeAccountCountry// GetStripeAccountCountry returns the stripe account country the user's existing plan is from// if he doesn't have a stripe subscription then ente.DefaultStripeAccountCountry is returnedfunc (c *BillingController) GetStripeAccountCountry(userID int64) (ente.StripeAccountCountry, error) {- stipeSubInfo, hasStripeSub, err := c.GetUserStripeSubscriptionInfo(userID)+ subscription, err := c.BillingRepo.GetUserSubscription(userID)if err != nil {return "", stacktrace.Propagate(err, "")}- if hasStripeSub {- return stipeSubInfo.AccountCountry, nil- } else {+ if subscription.PaymentProvider != ente.Stripe {//if user doesn't have a stripe subscription, return the default stripe account countryreturn ente.DefaultStripeAccountCountry, nil+ } else {+ return subscription.Attributes.StripeAccountCountry, nil}}// GetUserPlans returns the active plans for a userfunc (c *BillingController) GetUserPlans(ctx *gin.Context, userID int64) ([]ente.BillingPlan, error) {- stripeSubInfo, hasStripeSub, err := c.GetUserStripeSubscriptionInfo(userID)+ stripeAccountCountry, err := c.GetStripeAccountCountry(userID)if err != nil {- return []ente.BillingPlan{}, stacktrace.Propagate(err, "Failed to get user's subscription country and stripe account")- }- if hasStripeSub {- return c.GetPlansV2(stripeSubInfo.PlanCountry, stripeSubInfo.AccountCountry), nil- } else {- // user doesn't have a stipe subscription, so return the default account plans for the country the user is from- return c.GetPlansV2(network.GetClientCountry(ctx), ente.DefaultStripeAccountCountry), nil+ return []ente.BillingPlan{}, stacktrace.Propagate(err, "Failed to get user's country stripe account")}+ // always return the plans based on the user's country determined by the IP+ return c.GetPlansV2(network.GetClientCountry(ctx), stripeAccountCountry), nil+}// GetSubscription returns the current subscription for a user if any@@ -208,23 +205,6 @@ func (c *BillingController) HasActiveSelfOrFamilySubscription(userID int64) erroreturn nil}-func (c *BillingController) GetUserStripeSubscriptionInfo(userID int64) (ente.StripeSubscriptionInfo, bool, error) {- s, err := c.BillingRepo.GetUserSubscription(userID)- if err != nil {- return ente.StripeSubscriptionInfo{}, false, stacktrace.Propagate(err, "")- }- // skipping country code extraction for non-stripe subscriptions- // as they have same product id across countries and hence can't be distinquished- if s.PaymentProvider != ente.Stripe {- return ente.StripeSubscriptionInfo{}, false, nil- }- _, countryCode, err := c.getPlanWithCountry(s)- if err != nil {- return ente.StripeSubscriptionInfo{}, false, stacktrace.Propagate(err, "")- }- return ente.StripeSubscriptionInfo{PlanCountry: countryCode, AccountCountry: s.Attributes.StripeAccountCountry}, true, nil-}-// VerifySubscription verifies and returns the verified subscriptionfunc (c *BillingController) VerifySubscription(userID int64,