Skip to content

Commit

Permalink
Revert "[usage] handle reset usage for chargebee"
Browse files Browse the repository at this point in the history
  • Loading branch information
svenefftinge authored and roboquat committed Dec 2, 2022
1 parent 81f23e9 commit a5d6744
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 148 deletions.
17 changes: 4 additions & 13 deletions components/gitpod-db/go/cost_center.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ var CostCenterNotFound = errors.New("CostCenter not found")
type BillingStrategy string

const (
CostCenter_Stripe BillingStrategy = "stripe"
CostCenter_Other BillingStrategy = "other"
CostCenter_ChargebeeCancelled BillingStrategy = "chargebee-cancelled"
CostCenter_Stripe BillingStrategy = "stripe"
CostCenter_Other BillingStrategy = "other"
)

type CostCenter struct {
Expand Down Expand Up @@ -291,19 +290,11 @@ func (c *CostCenterManager) ResetUsage(ctx context.Context, id AttributionID) (C
nextBillingTime = cc.NextBillingTime.Time().AddDate(0, 1, 0)
}

futureSpendingLimit := cc.SpendingLimit
futurebillingStrategy := cc.BillingStrategy
// chargebee cancellations will be switched to free plan (strategy: other)
if cc.BillingStrategy == CostCenter_ChargebeeCancelled {
futureSpendingLimit = c.cfg.ForTeams
futurebillingStrategy = CostCenter_Other
}

// All fields on the new cost center remain the same, except for BillingCycleStart, NextBillingTime, and CreationTime
newCostCenter := CostCenter{
ID: cc.ID,
SpendingLimit: futureSpendingLimit,
BillingStrategy: futurebillingStrategy,
SpendingLimit: cc.SpendingLimit,
BillingStrategy: cc.BillingStrategy,
BillingCycleStart: NewVarCharTime(billingCycleStart),
NextBillingTime: NewVarCharTime(nextBillingTime),
CreationTime: NewVarCharTime(now),
Expand Down
1 change: 0 additions & 1 deletion components/gitpod-protocol/src/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,5 @@ export interface CostCenterJSON {
export enum CostCenter_BillingStrategy {
BILLING_STRATEGY_STRIPE = "BILLING_STRATEGY_STRIPE",
BILLING_STRATEGY_OTHER = "BILLING_STRATEGY_OTHER",
BILLING_STRATEGY_CHARGEBEE_CANCELLATION = "BILLING_STRATEGY_CHARGEBEE_CANCELLATION",
UNRECOGNIZED = "UNRECOGNIZED",
}
128 changes: 61 additions & 67 deletions components/usage-api/go/v1/usage.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions components/usage-api/typescript/src/usage/v1/usage.pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ export interface CostCenter {
export enum CostCenter_BillingStrategy {
BILLING_STRATEGY_STRIPE = "BILLING_STRATEGY_STRIPE",
BILLING_STRATEGY_OTHER = "BILLING_STRATEGY_OTHER",
BILLING_STRATEGY_CHARGEBEE_CANCELLATION = "BILLING_STRATEGY_CHARGEBEE_CANCELLATION",
UNRECOGNIZED = "UNRECOGNIZED",
}

Expand All @@ -213,9 +212,6 @@ export function costCenter_BillingStrategyFromJSON(object: any): CostCenter_Bill
case 1:
case "BILLING_STRATEGY_OTHER":
return CostCenter_BillingStrategy.BILLING_STRATEGY_OTHER;
case 2:
case "BILLING_STRATEGY_CHARGEBEE_CANCELLATION":
return CostCenter_BillingStrategy.BILLING_STRATEGY_CHARGEBEE_CANCELLATION;
case -1:
case "UNRECOGNIZED":
default:
Expand All @@ -229,8 +225,6 @@ export function costCenter_BillingStrategyToJSON(object: CostCenter_BillingStrat
return "BILLING_STRATEGY_STRIPE";
case CostCenter_BillingStrategy.BILLING_STRATEGY_OTHER:
return "BILLING_STRATEGY_OTHER";
case CostCenter_BillingStrategy.BILLING_STRATEGY_CHARGEBEE_CANCELLATION:
return "BILLING_STRATEGY_CHARGEBEE_CANCELLATION";
case CostCenter_BillingStrategy.UNRECOGNIZED:
default:
return "UNRECOGNIZED";
Expand All @@ -243,8 +237,6 @@ export function costCenter_BillingStrategyToNumber(object: CostCenter_BillingStr
return 0;
case CostCenter_BillingStrategy.BILLING_STRATEGY_OTHER:
return 1;
case CostCenter_BillingStrategy.BILLING_STRATEGY_CHARGEBEE_CANCELLATION:
return 2;
case CostCenter_BillingStrategy.UNRECOGNIZED:
default:
return -1;
Expand Down
1 change: 0 additions & 1 deletion components/usage-api/usage/v1/usage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ message CostCenter {
enum BillingStrategy {
BILLING_STRATEGY_STRIPE = 0;
BILLING_STRATEGY_OTHER = 1;
BILLING_STRATEGY_CHARGEBEE_CANCELLATION = 2;
}
BillingStrategy billing_strategy = 3;

Expand Down
6 changes: 0 additions & 6 deletions components/usage/pkg/apiv1/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,13 @@ func convertBillingStrategyToDB(in v1.CostCenter_BillingStrategy) db.BillingStra
if in == v1.CostCenter_BILLING_STRATEGY_STRIPE {
return db.CostCenter_Stripe
}
if in == v1.CostCenter_BILLING_STRATEGY_CHARGEBEE_CANCELLATION {
return db.CostCenter_ChargebeeCancelled
}
return db.CostCenter_Other
}

func convertBillingStrategyToAPI(in db.BillingStrategy) v1.CostCenter_BillingStrategy {
if in == db.CostCenter_Stripe {
return v1.CostCenter_BILLING_STRATEGY_STRIPE
}
if in == db.CostCenter_ChargebeeCancelled {
return v1.CostCenter_BILLING_STRATEGY_CHARGEBEE_CANCELLATION
}
return v1.CostCenter_BILLING_STRATEGY_OTHER
}

Expand Down
Loading

0 comments on commit a5d6744

Please sign in to comment.