From 8ddebeb06c605a0c840ffd69d7b2d0b0836563af Mon Sep 17 00:00:00 2001 From: RushikeshBhavsar3605 Date: Thu, 20 Aug 2026 16:21:33 +0530 Subject: [PATCH] fix(billing): omit empty product description for Stripe --- billing/product/service.go | 15 +++++++---- billing/product/service_test.go | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/billing/product/service.go b/billing/product/service.go index 2976e17e5..e37fc9186 100644 --- a/billing/product/service.go +++ b/billing/product/service.go @@ -81,13 +81,12 @@ func (s *Service) Create(ctx context.Context, product Product) (Product, error) } product.Name = strings.ToLower(product.Name) - _, err := s.stripeClient.Products.New(&stripe.ProductParams{ + providerParams := &stripe.ProductParams{ Params: stripe.Params{ Context: ctx, }, - ID: &product.ProviderID, - Name: &product.Title, - Description: &product.Description, + ID: &product.ProviderID, + Name: &product.Title, Metadata: map[string]string{ "name": product.Name, "credit_amount": fmt.Sprintf("%d", product.Config.CreditAmount), @@ -95,7 +94,13 @@ func (s *Service) Create(ctx context.Context, product Product) (Product, error) "product_id": product.ID, "managed_by": "frontier", }, - }) + } + + if product.Description != "" { + providerParams.Description = &product.Description + } + + _, err := s.stripeClient.Products.New(providerParams) if err != nil { return Product{}, fmt.Errorf("failed to create product at billing provider: %w", billingerrors.TranslateStripeError(err)) } diff --git a/billing/product/service_test.go b/billing/product/service_test.go index 3a34b454d..f6c9597e1 100644 --- a/billing/product/service_test.go +++ b/billing/product/service_test.go @@ -40,6 +40,51 @@ func TestService_Create(t *testing.T) { wantErr bool setup func() *product.Service }{ + { + name: "should create product with empty description", + args: args{ + product: product.Product{ + ID: "1", + Name: "product1", + Description: "", + }, + }, + want: product.Product{ + ID: "1", + Name: "product1", + Description: "", + }, + wantErr: false, + setup: func() *product.Service { + stripeClient, mockStripeBackend, mockProductRepo, mockPriceRepo, mockFeatureRepo := mockService(t) + mockProductRepo.EXPECT().Create(ctx, product.Product{ + ID: "1", + Name: "product1", + Description: "", + Behavior: product.BasicBehavior, + }).Return(product.Product{ + ID: "1", + Name: "product1", + Description: "", + }, nil) + mockStripeBackend.EXPECT().Call("POST", "/v1/products", "key_123", &stripe.ProductParams{ + Params: stripe.Params{ + Context: ctx, + }, + ID: new(""), + Name: new(""), + Description: nil, + Metadata: map[string]string{ + "behavior": "basic", + "credit_amount": "0", + "managed_by": "frontier", + "name": "product1", + "product_id": "1", + }, + }, &stripe.Product{}).Return(nil) + return product.NewService(stripeClient, mockProductRepo, mockPriceRepo, mockFeatureRepo) + }, + }, { name: "should create product in repo and billing provider with no price and features", args: args{