Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions billing/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package billing
import "time"

type Config struct {
StripeKey string `yaml:"stripe_key" mapstructure:"stripe_key"`
StripeAutoTax bool `yaml:"stripe_auto_tax" mapstructure:"stripe_auto_tax"`
StripeWebhookSecrets []string `yaml:"stripe_webhook_secrets" mapstructure:"stripe_webhook_secrets"`
// PlansPath is a directory path where plans are defined
PlansPath string `yaml:"plans_path" mapstructure:"plans_path"`
DefaultCurrency string `yaml:"default_currency" mapstructure:"default_currency"`
PaymentMethodConfig []PaymentMethodConfig `yaml:"payment_method_config" mapstructure:"payment_method_config"`
StripeKey string `yaml:"stripe_key" mapstructure:"stripe_key"`
StripeAutoTax bool `yaml:"stripe_auto_tax" mapstructure:"stripe_auto_tax"`
StripeWebhookSecrets []string `yaml:"stripe_webhook_secrets" mapstructure:"stripe_webhook_secrets"`
DefaultCurrency string `yaml:"default_currency" mapstructure:"default_currency"`
Comment thread
rohilsurana marked this conversation as resolved.
PaymentMethodConfig []PaymentMethodConfig `yaml:"payment_method_config" mapstructure:"payment_method_config"`

AccountConfig AccountConfig `yaml:"customer" mapstructure:"customer"`
PlanChangeConfig PlanChangeConfig `yaml:"plan_change" mapstructure:"plan_change"`
Expand Down
20 changes: 1 addition & 19 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,6 @@ func StartServer(logger *slog.Logger, cfg *config.Frontier) error {
}
}()

// load billing plans
billingBlobFS, err := blob.NewStore(ctx, cfg.Billing.PlansPath, "")
if err != nil {
return err
}
billingPlanRepository := blob.NewPlanRepository(billingBlobFS)

promRegistry := prometheus.NewRegistry()
promMetrics := prometheusmiddleware.NewClientMetrics(
prometheusmiddleware.WithClientHandlingTimeHistogram(),
Expand All @@ -182,7 +175,7 @@ func StartServer(logger *slog.Logger, cfg *config.Frontier) error {
return err
}

deps, err := buildAPIDependencies(logger, cfg, dbClient, spiceDBClient, resourceBlobFS, billingPlanRepository)
deps, err := buildAPIDependencies(logger, cfg, dbClient, spiceDBClient, resourceBlobFS)
if err != nil {
return err
}
Expand All @@ -200,14 +193,6 @@ func StartServer(logger *slog.Logger, cfg *config.Frontier) error {
}
logger.Info("migrated authz schema")

// apply billing plans
if cfg.Billing.PlansPath != "" {
if err = deps.BootstrapService.MigrateBillingPlans(ctx); err != nil {
return err
}
logger.Info("migrated billing plans")
}

// apply roles over nil org id
Comment thread
rohilsurana marked this conversation as resolved.
// nil org is the default org of platform
if err = deps.BootstrapService.MigrateRoles(ctx); err != nil {
Expand Down Expand Up @@ -362,7 +347,6 @@ func buildAPIDependencies(
dbc *db.Client,
sdb *spicedb.SpiceDB,
resourceBlobBucket blob.Bucket,
planBlobRepository *blob.PlanRepository,
) (api.Deps, error) {
// Load additional traits from config file if specified
traits, err := preference.LoadTraitsFromFile(cfg.App.AdditionalTraitsPath)
Expand Down Expand Up @@ -609,8 +593,6 @@ func buildAPIDependencies(
policyService,
svUserRepo,
cfg.App.PAT.DeniedPermissionsSet(),
planService,
planBlobRepository,
svUserRepo,
scUserCredRepo,
serviceUserService,
Expand Down
3 changes: 0 additions & 3 deletions config/sample.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,6 @@ billing:
# webhook secret to be used for validating stripe webhooks events
# all the secrets are used to validate the events useful in case of key rotation
stripe_webhook_secrets: []
# path to plans spec file that will be used to create plans in billing engine
# e.g. file:///tmp/plans
plans_path: ""
# default currency to be used for billing if not provided by the user
# e.g. usd, inr, eur
default_currency: ""
Expand Down
1 change: 0 additions & 1 deletion core/event/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func mockService(t *testing.T) (*billing.Config, *mocks.CheckoutService, *mocks.
StripeKey: "test_key",
StripeAutoTax: false,
StripeWebhookSecrets: nil,
PlansPath: "",
DefaultCurrency: "USD",
AccountConfig: billing.AccountConfig{AutoCreateWithOrg: true, DefaultPlan: "default_plan", DefaultOffline: false},
PlanChangeConfig: billing.PlanChangeConfig{},
Expand Down
1 change: 0 additions & 1 deletion docs/content/docs/reference/billing-configurations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ This document provides instructions on how to configure the billing settings for
| **billing.stripe_key** | Developer key generated on Stripe | sk_test_abcdefghijklmnopqrstuvwxyz | Yes |
| **billing.stripe_auto_tax** | Set to true if you want Stripe to automatically apply tax on the invoices as per the customer's location | false | No (default: false) |
| **billing.stripe_webhook_secrets** | Webhook secrets to be used for validating stripe webhooks events | [] | No |
| **billing.plans_path** | Path to a folder which has yaml files describing the products and plans that need to be created on the billing engine (Stripe). The plans and products in these files will be automatically created on Stripe as part of migration during application startup | "file:///tmp/plans" | No (but recommended) |
| **billing.default_plan** | Name of the plan that should be used subscribed automatically when the org is created. It also automatically creates an empty billing account under the org.<br/>**Note: The plan name provided here should exist in the billing engine.** | "standard_plan" | No |
| **billing.default_currency** | Default currency to be used for billing if not provided by the user | "USD" | No (but recommended) |
| **billing.plan_change.proration_behavior** | Proration behaviour to be used when a subscription is changed, or its quantity is updated. Can be one of "create_prorations", "always_invoice" or "none" | "create_prorations" | No (default: create_prorations) |
Expand Down
3 changes: 0 additions & 3 deletions docs/content/docs/reference/configurations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ billing:
# webhook secret to be used for validating stripe webhooks events
# all the secrets are used to validate the events useful in case of key rotation
stripe_webhook_secrets: []
# path to plans spec file that will be used to create plans in billing engine
# e.g. file:///tmp/plans
plans_path: ""
# default currency to be used for billing if not provided by the user
# e.g. usd, inr, eur
default_currency: ""
Expand Down
26 changes: 0 additions & 26 deletions internal/bootstrap/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"fmt"
"log/slog"

"github.com/raystack/frontier/billing/plan"

azcore "github.com/authzed/spicedb/pkg/proto/core/v1"

"github.com/raystack/frontier/core/namespace"
Expand Down Expand Up @@ -50,14 +48,6 @@ type AuthzEngine interface {
WriteSchema(ctx context.Context, schema string) error
}

type BillingPlanRepository interface {
Get(ctx context.Context) (plan.File, error)
}

type PlanService interface {
UpsertPlans(ctx context.Context, planFile plan.File) error
}

// PolicyService is policy.Service narrowed to what backfill needs. Goes through
// Create so the SpiceDB rolebinding tuples land alongside the row.
type PolicyService interface {
Expand Down Expand Up @@ -100,9 +90,6 @@ type Service struct {
suCreator ServiceUserCreator
suCredStore ServiceUserCredentialStore
suPromoter SuperUserPromoter

planService PlanService
planLocalRepo BillingPlanRepository
}

func NewBootstrapService(
Expand All @@ -117,8 +104,6 @@ func NewBootstrapService(
policyService PolicyService,
serviceuserRepo ServiceUserBackfiller,
patDeniedPerms map[string]struct{},
planService PlanService,
planLocalRepo BillingPlanRepository,
suCreator ServiceUserCreator,
suCredStore ServiceUserCredentialStore,
suPromoter SuperUserPromoter,
Expand All @@ -131,8 +116,6 @@ func NewBootstrapService(
roleService: roleService,
permissionService: actionService,
authzEngine: authzEngine,
planService: planService,
planLocalRepo: planLocalRepo,
relationService: relationService,
policyService: policyService,
serviceuserRepo: serviceuserRepo,
Expand Down Expand Up @@ -436,12 +419,3 @@ func (s Service) migrateAZDefinitionsToDB(ctx context.Context, azDefinitions []*
}
return nil
}

func (s Service) MigrateBillingPlans(ctx context.Context) error {
localPlans, err := s.planLocalRepo.Get(ctx)
if err != nil {
return err
}

return s.planService.UpsertPlans(ctx, localPlans)
}
70 changes: 0 additions & 70 deletions internal/store/blob/plan_repository.go

This file was deleted.

58 changes: 56 additions & 2 deletions test/e2e/regression/billing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ import (
"google.golang.org/protobuf/types/known/structpb"

"github.com/raystack/frontier/billing"
"github.com/raystack/frontier/billing/product"
"github.com/raystack/frontier/core/authenticate"
testusers "github.com/raystack/frontier/core/authenticate/test_users"
"github.com/raystack/frontier/internal/store/postgres"
"github.com/raystack/frontier/pkg/db"
"github.com/raystack/frontier/pkg/server"
frontierv1beta1 "github.com/raystack/frontier/proto/v1beta1"

Expand Down Expand Up @@ -70,7 +73,6 @@ func (s *BillingRegressionTestSuite) SetupSuite() {
},
Billing: billing.Config{
StripeKey: "sk_test_mock",
PlansPath: path.Join(testDataPath, "plans"),
DefaultCurrency: "usd",
AccountConfig: billing.AccountConfig{
AutoCreateWithOrg: true,
Expand All @@ -82,7 +84,33 @@ func (s *BillingRegressionTestSuite) SetupSuite() {
},
}

s.testBench, err = testbench.Init(appConfig)
// support_credits is the credit_overdraft_product the billing service
// resolves during boot (invoice.Init). The boot loader used to seed it from
// cfg.Billing.PlansPath; that loader is gone, so seed it straight into the
// database before the server starts, so the boot sequence can find it.
seedOverdraftProduct := func(ctx context.Context, dbc *db.Client) error {
prod, err := postgres.NewBillingProductRepository(dbc).Create(ctx, product.Product{
ID: uuid.New().String(),
Name: "support_credits",
Title: "Support Credits",
Description: "Support for enterprise help",
Behavior: product.CreditBehavior,
Config: product.BehaviorConfig{CreditAmount: 100},
State: "active",
})
if err != nil {
return err
}
_, err = postgres.NewBillingPriceRepository(dbc).Create(ctx, product.Price{
Name: "default",
ProductID: prod.ID,
Amount: 20000,
Currency: "usd",
})
return err
}

s.testBench, err = testbench.Init(appConfig, seedOverdraftProduct)
s.Require().NoError(err)

ctx := context.Background()
Expand All @@ -95,6 +123,32 @@ func (s *BillingRegressionTestSuite) SetupSuite() {
s.Require().NoError(testbench.BootstrapOrganizations(ctx, s.testBench.Client, adminCookie))
s.Require().NoError(testbench.BootstrapProject(ctx, s.testBench.Client, adminCookie))
s.Require().NoError(testbench.BootstrapGroup(ctx, s.testBench.Client, adminCookie))

// The enterprise_yearly plan used to be seeded at boot from
// cfg.Billing.PlansPath. That loader is gone, so create it through the admin
// API once the server is up (a checkout test uses it). The overdraft product
// was already seeded before boot above.
ctxAdmin := testbench.ContextWithAuth(ctx, adminCookie)
_, err = s.testBench.AdminClient.CreatePlan(ctxAdmin, connect.NewRequest(&frontierv1beta1.CreatePlanRequest{
Body: &frontierv1beta1.PlanRequestBody{
Name: "enterprise_yearly",
Title: "Enterprise Plan",
Description: "Enterprise Plan",
Interval: "year",
State: "active",
Products: []*frontierv1beta1.Product{
{
Name: "enterprise_access",
Title: "Enterprise base access for year",
Description: "Base access to the platform",
Prices: []*frontierv1beta1.Price{
{Name: "default", Interval: "year", Amount: 8000, Currency: "usd"},
},
},
},
},
}))
s.Require().NoError(err)
}

func (s *BillingRegressionTestSuite) TearDownSuite() {
Expand Down
Loading
Loading