From a5d67448b29a82c07e3dcc6e92e83f550fa2fd37 Mon Sep 17 00:00:00 2001 From: Sven Efftinge Date: Fri, 2 Dec 2022 14:34:51 +0000 Subject: [PATCH] Revert "[usage] handle reset usage for chargebee" --- components/gitpod-db/go/cost_center.go | 17 +-- components/gitpod-protocol/src/usage.ts | 1 - components/usage-api/go/v1/usage.pb.go | 128 +++++++++--------- .../typescript/src/usage/v1/usage.pb.ts | 8 -- components/usage-api/usage/v1/usage.proto | 1 - components/usage/pkg/apiv1/usage.go | 6 - components/usage/pkg/apiv1/usage_test.go | 53 +------- 7 files changed, 66 insertions(+), 148 deletions(-) diff --git a/components/gitpod-db/go/cost_center.go b/components/gitpod-db/go/cost_center.go index cfb50de79e7c0a..c4a3be3b544390 100644 --- a/components/gitpod-db/go/cost_center.go +++ b/components/gitpod-db/go/cost_center.go @@ -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 { @@ -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), diff --git a/components/gitpod-protocol/src/usage.ts b/components/gitpod-protocol/src/usage.ts index 79050559922e5d..a2b3c2edee1b03 100644 --- a/components/gitpod-protocol/src/usage.ts +++ b/components/gitpod-protocol/src/usage.ts @@ -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", } diff --git a/components/usage-api/go/v1/usage.pb.go b/components/usage-api/go/v1/usage.pb.go index 215d2a122259cc..abbd83686b28f1 100644 --- a/components/usage-api/go/v1/usage.pb.go +++ b/components/usage-api/go/v1/usage.pb.go @@ -120,9 +120,8 @@ func (Usage_Kind) EnumDescriptor() ([]byte, []int) { type CostCenter_BillingStrategy int32 const ( - CostCenter_BILLING_STRATEGY_STRIPE CostCenter_BillingStrategy = 0 - CostCenter_BILLING_STRATEGY_OTHER CostCenter_BillingStrategy = 1 - CostCenter_BILLING_STRATEGY_CHARGEBEE_CANCELLATION CostCenter_BillingStrategy = 2 + CostCenter_BILLING_STRATEGY_STRIPE CostCenter_BillingStrategy = 0 + CostCenter_BILLING_STRATEGY_OTHER CostCenter_BillingStrategy = 1 ) // Enum value maps for CostCenter_BillingStrategy. @@ -130,12 +129,10 @@ var ( CostCenter_BillingStrategy_name = map[int32]string{ 0: "BILLING_STRATEGY_STRIPE", 1: "BILLING_STRATEGY_OTHER", - 2: "BILLING_STRATEGY_CHARGEBEE_CANCELLATION", } CostCenter_BillingStrategy_value = map[string]int32{ - "BILLING_STRATEGY_STRIPE": 0, - "BILLING_STRATEGY_OTHER": 1, - "BILLING_STRATEGY_CHARGEBEE_CANCELLATION": 2, + "BILLING_STRATEGY_STRIPE": 0, + "BILLING_STRATEGY_OTHER": 1, } ) @@ -1304,7 +1301,7 @@ var file_usage_v1_usage_proto_rawDesc = []byte{ 0x12, 0x35, 0x0a, 0x0b, 0x63, 0x6f, 0x73, 0x74, 0x5f, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x73, 0x74, 0x43, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x52, 0x0a, 0x63, 0x6f, 0x73, - 0x74, 0x43, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x22, 0xb8, 0x03, 0x0a, 0x0a, 0x43, 0x6f, 0x73, 0x74, + 0x74, 0x43, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x22, 0x8b, 0x03, 0x0a, 0x0a, 0x43, 0x6f, 0x73, 0x74, 0x43, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x12, 0x25, 0x0a, 0x0e, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x25, 0x0a, @@ -1324,69 +1321,66 @@ var file_usage_v1_usage_proto_rawDesc = []byte{ 0x74, 0x61, 0x72, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x11, 0x62, 0x69, 0x6c, 0x6c, 0x69, 0x6e, 0x67, 0x43, - 0x79, 0x63, 0x6c, 0x65, 0x53, 0x74, 0x61, 0x72, 0x74, 0x22, 0x77, 0x0a, 0x0f, 0x42, 0x69, 0x6c, + 0x79, 0x63, 0x6c, 0x65, 0x53, 0x74, 0x61, 0x72, 0x74, 0x22, 0x4a, 0x0a, 0x0f, 0x42, 0x69, 0x6c, 0x6c, 0x69, 0x6e, 0x67, 0x53, 0x74, 0x72, 0x61, 0x74, 0x65, 0x67, 0x79, 0x12, 0x1b, 0x0a, 0x17, 0x42, 0x49, 0x4c, 0x4c, 0x49, 0x4e, 0x47, 0x5f, 0x53, 0x54, 0x52, 0x41, 0x54, 0x45, 0x47, 0x59, 0x5f, 0x53, 0x54, 0x52, 0x49, 0x50, 0x45, 0x10, 0x00, 0x12, 0x1a, 0x0a, 0x16, 0x42, 0x49, 0x4c, 0x4c, 0x49, 0x4e, 0x47, 0x5f, 0x53, 0x54, 0x52, 0x41, 0x54, 0x45, 0x47, 0x59, 0x5f, 0x4f, 0x54, - 0x48, 0x45, 0x52, 0x10, 0x01, 0x12, 0x2b, 0x0a, 0x27, 0x42, 0x49, 0x4c, 0x4c, 0x49, 0x4e, 0x47, - 0x5f, 0x53, 0x54, 0x52, 0x41, 0x54, 0x45, 0x47, 0x59, 0x5f, 0x43, 0x48, 0x41, 0x52, 0x47, 0x45, - 0x42, 0x45, 0x45, 0x5f, 0x43, 0x41, 0x4e, 0x43, 0x45, 0x4c, 0x4c, 0x41, 0x54, 0x49, 0x4f, 0x4e, - 0x10, 0x02, 0x22, 0x13, 0x0a, 0x11, 0x52, 0x65, 0x73, 0x65, 0x74, 0x55, 0x73, 0x61, 0x67, 0x65, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x14, 0x0a, 0x12, 0x52, 0x65, 0x73, 0x65, 0x74, - 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x97, 0x01, - 0x0a, 0x19, 0x41, 0x64, 0x64, 0x55, 0x73, 0x61, 0x67, 0x65, 0x43, 0x72, 0x65, 0x64, 0x69, 0x74, - 0x4e, 0x6f, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x25, 0x0a, 0x0e, 0x61, - 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x0d, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, - 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x72, 0x65, 0x64, 0x69, 0x74, 0x73, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x05, 0x52, 0x07, 0x63, 0x72, 0x65, 0x64, 0x69, 0x74, 0x73, 0x12, 0x20, 0x0a, 0x0b, - 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x17, - 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x1c, 0x0a, 0x1a, 0x41, 0x64, 0x64, 0x55, 0x73, - 0x61, 0x67, 0x65, 0x43, 0x72, 0x65, 0x64, 0x69, 0x74, 0x4e, 0x6f, 0x74, 0x65, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xce, 0x04, 0x0a, 0x0c, 0x55, 0x73, 0x61, 0x67, 0x65, 0x53, - 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x52, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x73, - 0x74, 0x43, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x12, 0x1e, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, - 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x73, 0x74, 0x43, 0x65, 0x6e, 0x74, 0x65, 0x72, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, - 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x73, 0x74, 0x43, 0x65, 0x6e, 0x74, 0x65, 0x72, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x52, 0x0a, 0x0d, 0x53, 0x65, - 0x74, 0x43, 0x6f, 0x73, 0x74, 0x43, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x12, 0x1e, 0x2e, 0x75, 0x73, - 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x43, 0x6f, 0x73, 0x74, 0x43, 0x65, - 0x6e, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x75, 0x73, - 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x43, 0x6f, 0x73, 0x74, 0x43, 0x65, - 0x6e, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x55, - 0x0a, 0x0e, 0x52, 0x65, 0x63, 0x6f, 0x6e, 0x63, 0x69, 0x6c, 0x65, 0x55, 0x73, 0x61, 0x67, 0x65, - 0x12, 0x1f, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x63, 0x6f, - 0x6e, 0x63, 0x69, 0x6c, 0x65, 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x20, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x63, - 0x6f, 0x6e, 0x63, 0x69, 0x6c, 0x65, 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x49, 0x0a, 0x0a, 0x52, 0x65, 0x73, 0x65, 0x74, 0x55, 0x73, - 0x61, 0x67, 0x65, 0x12, 0x1b, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x52, - 0x65, 0x73, 0x65, 0x74, 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x1c, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x73, 0x65, - 0x74, 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, - 0x12, 0x46, 0x0a, 0x09, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1a, 0x2e, - 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, 0x61, - 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x75, 0x73, 0x61, 0x67, - 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x49, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x42, - 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x1b, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, - 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x47, - 0x65, 0x74, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x22, 0x00, 0x12, 0x61, 0x0a, 0x12, 0x41, 0x64, 0x64, 0x55, 0x73, 0x61, 0x67, 0x65, 0x43, - 0x72, 0x65, 0x64, 0x69, 0x74, 0x4e, 0x6f, 0x74, 0x65, 0x12, 0x23, 0x2e, 0x75, 0x73, 0x61, 0x67, - 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x64, 0x64, 0x55, 0x73, 0x61, 0x67, 0x65, 0x43, 0x72, 0x65, - 0x64, 0x69, 0x74, 0x4e, 0x6f, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x24, - 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x64, 0x64, 0x55, 0x73, 0x61, - 0x67, 0x65, 0x43, 0x72, 0x65, 0x64, 0x69, 0x74, 0x4e, 0x6f, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x2a, 0x5a, 0x28, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, - 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2d, 0x69, 0x6f, 0x2f, 0x67, - 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2f, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2d, 0x61, 0x70, 0x69, 0x2f, - 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x48, 0x45, 0x52, 0x10, 0x01, 0x22, 0x13, 0x0a, 0x11, 0x52, 0x65, 0x73, 0x65, 0x74, 0x55, 0x73, + 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x14, 0x0a, 0x12, 0x52, 0x65, + 0x73, 0x65, 0x74, 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x97, 0x01, 0x0a, 0x19, 0x41, 0x64, 0x64, 0x55, 0x73, 0x61, 0x67, 0x65, 0x43, 0x72, 0x65, + 0x64, 0x69, 0x74, 0x4e, 0x6f, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x25, + 0x0a, 0x0e, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, + 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x72, 0x65, 0x64, 0x69, 0x74, 0x73, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x63, 0x72, 0x65, 0x64, 0x69, 0x74, 0x73, 0x12, + 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, + 0x6e, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x1c, 0x0a, 0x1a, 0x41, 0x64, + 0x64, 0x55, 0x73, 0x61, 0x67, 0x65, 0x43, 0x72, 0x65, 0x64, 0x69, 0x74, 0x4e, 0x6f, 0x74, 0x65, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xce, 0x04, 0x0a, 0x0c, 0x55, 0x73, 0x61, + 0x67, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x52, 0x0a, 0x0d, 0x47, 0x65, 0x74, + 0x43, 0x6f, 0x73, 0x74, 0x43, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x12, 0x1e, 0x2e, 0x75, 0x73, 0x61, + 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x73, 0x74, 0x43, 0x65, 0x6e, + 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x75, 0x73, 0x61, + 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x73, 0x74, 0x43, 0x65, 0x6e, + 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x52, 0x0a, + 0x0d, 0x53, 0x65, 0x74, 0x43, 0x6f, 0x73, 0x74, 0x43, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x12, 0x1e, + 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x43, 0x6f, 0x73, + 0x74, 0x43, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, + 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x43, 0x6f, 0x73, + 0x74, 0x43, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x12, 0x55, 0x0a, 0x0e, 0x52, 0x65, 0x63, 0x6f, 0x6e, 0x63, 0x69, 0x6c, 0x65, 0x55, 0x73, + 0x61, 0x67, 0x65, 0x12, 0x1f, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x52, + 0x65, 0x63, 0x6f, 0x6e, 0x63, 0x69, 0x6c, 0x65, 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, + 0x52, 0x65, 0x63, 0x6f, 0x6e, 0x63, 0x69, 0x6c, 0x65, 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x49, 0x0a, 0x0a, 0x52, 0x65, 0x73, 0x65, + 0x74, 0x55, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1b, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, + 0x31, 0x2e, 0x52, 0x65, 0x73, 0x65, 0x74, 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x52, + 0x65, 0x73, 0x65, 0x74, 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x22, 0x00, 0x12, 0x46, 0x0a, 0x09, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, 0x61, 0x67, 0x65, + 0x12, 0x1a, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, + 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x75, + 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, 0x61, 0x67, + 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x49, 0x0a, 0x0a, 0x47, + 0x65, 0x74, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x1b, 0x2e, 0x75, 0x73, 0x61, 0x67, + 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, + 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x61, 0x0a, 0x12, 0x41, 0x64, 0x64, 0x55, 0x73, 0x61, + 0x67, 0x65, 0x43, 0x72, 0x65, 0x64, 0x69, 0x74, 0x4e, 0x6f, 0x74, 0x65, 0x12, 0x23, 0x2e, 0x75, + 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x64, 0x64, 0x55, 0x73, 0x61, 0x67, 0x65, + 0x43, 0x72, 0x65, 0x64, 0x69, 0x74, 0x4e, 0x6f, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x24, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x64, 0x64, + 0x55, 0x73, 0x61, 0x67, 0x65, 0x43, 0x72, 0x65, 0x64, 0x69, 0x74, 0x4e, 0x6f, 0x74, 0x65, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x2a, 0x5a, 0x28, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2d, 0x69, + 0x6f, 0x2f, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2f, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2d, 0x61, + 0x70, 0x69, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/components/usage-api/typescript/src/usage/v1/usage.pb.ts b/components/usage-api/typescript/src/usage/v1/usage.pb.ts index b523021558fc3d..62a1f5d494d52b 100644 --- a/components/usage-api/typescript/src/usage/v1/usage.pb.ts +++ b/components/usage-api/typescript/src/usage/v1/usage.pb.ts @@ -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", } @@ -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: @@ -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"; @@ -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; diff --git a/components/usage-api/usage/v1/usage.proto b/components/usage-api/usage/v1/usage.proto index bfb869df3c8f8c..e82b9f366e1727 100644 --- a/components/usage-api/usage/v1/usage.proto +++ b/components/usage-api/usage/v1/usage.proto @@ -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; diff --git a/components/usage/pkg/apiv1/usage.go b/components/usage/pkg/apiv1/usage.go index a05c5da693650a..57013032d2cf3c 100644 --- a/components/usage/pkg/apiv1/usage.go +++ b/components/usage/pkg/apiv1/usage.go @@ -204,9 +204,6 @@ 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 } @@ -214,9 +211,6 @@ func convertBillingStrategyToAPI(in db.BillingStrategy) v1.CostCenter_BillingStr 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 } diff --git a/components/usage/pkg/apiv1/usage_test.go b/components/usage/pkg/apiv1/usage_test.go index 8eedf0aa3a9ad6..4b8b1f0c3a088b 100644 --- a/components/usage/pkg/apiv1/usage_test.go +++ b/components/usage/pkg/apiv1/usage_test.go @@ -341,7 +341,7 @@ func TestListUsage(t *testing.T) { } -func TestAddUsageCreditNote(t *testing.T) { +func TestAddUSageCreditNote(t *testing.T) { conn := dbtest.ConnectForTests(t) attributionID := db.NewTeamAttributionID(uuid.New().String()) @@ -382,54 +382,3 @@ func TestAddUsageCreditNote(t *testing.T) { } } - -func TestHandleChargebeeCancellations(t *testing.T) { - conn := dbtest.ConnectForTests(t) - - cancellationDate := time.Date(2022, 8, 1, 0, 0, 0, 0, time.UTC) - - attributionID := db.NewTeamAttributionID(uuid.New().String()) - - dbtest.CreateUsageRecords(t, conn, dbtest.NewUsage(t, db.Usage{ - AttributionID: attributionID, - EffectiveTime: db.NewVarCharTime(cancellationDate.Add(-6 * time.Hour)), - CreditCents: 100, - Draft: false, - }), dbtest.NewUsage(t, db.Usage{ - AttributionID: attributionID, - EffectiveTime: db.NewVarCharTime(cancellationDate.Add(-4 * time.Hour)), - CreditCents: 200, - Draft: false, - }), dbtest.NewUsage(t, db.Usage{ - AttributionID: attributionID, - EffectiveTime: db.NewVarCharTime(cancellationDate.Add(-2 * time.Hour)), - CreditCents: 300, - Draft: true, - })) - - cc := dbtest.CreateCostCenters(t, conn, db.CostCenter{ - ID: attributionID, - BillingStrategy: db.CostCenter_ChargebeeCancelled, - SpendingLimit: 1000, - BillingCycleStart: db.NewVarCharTime(cancellationDate.Add(-2 * time.Hour)), - NextBillingTime: db.NewVarCharTime(cancellationDate), - CreationTime: db.NewVarCharTime(cancellationDate.Add(-2 * time.Hour)), - })[0] - - usageService := newUsageService(t, conn) - - balanceBefore, err := usageService.GetBalance(context.Background(), &v1.GetBalanceRequest{AttributionId: string(cc.ID)}) - require.NoError(t, err) - require.Equal(t, float64(6), balanceBefore.Credits) - - _, err = usageService.ResetUsage(context.Background(), &v1.ResetUsageRequest{}) - require.NoError(t, err) - - costCenterAfter, err := usageService.GetCostCenter(context.Background(), &v1.GetCostCenterRequest{AttributionId: string(cc.ID)}) - require.NoError(t, err) - require.Equal(t, v1.CostCenter_BILLING_STRATEGY_OTHER, costCenterAfter.CostCenter.BillingStrategy) - - balanceAfter, err := usageService.GetBalance(context.Background(), &v1.GetBalanceRequest{AttributionId: string(cc.ID)}) - require.NoError(t, err) - require.Equal(t, float64(0), balanceAfter.Credits) -}