Skip to content

Commit

Permalink
feat: allow trial on default plan of billing account
Browse files Browse the repository at this point in the history
When the org is created, if a default billing account of customer
is registered to billing provider, if the plan is configured with
trial days, subscription will start with trial days.

Signed-off-by: Kush Sharma <[email protected]>
  • Loading branch information
kushsharma committed Aug 24, 2024
1 parent 8d0bca6 commit b3939ba
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions core/event/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,19 @@ func (p *Service) EnsureDefaultPlan(ctx context.Context, orgID string) error {
return fmt.Errorf("failed to get default plan: %w", err)
}

var totalPrice int64
for _, prod := range defaultPlan.Products {
for _, price := range prod.Prices {
if price.Amount > 0 {
return fmt.Errorf("default plan is not free")
}
totalPrice += price.Amount
}
}
if totalPrice > 0 && defaultPlan.TrialDays == 0 {
return fmt.Errorf("default plan is not free to start")
}

_, _, err = p.checkoutService.Apply(ctx, checkout.Checkout{
CustomerID: customr.ID,
PlanID: defaultPlan.ID,
SkipTrial: true,
})
if err != nil {
return fmt.Errorf("failed to apply default plan: %w", err)
Expand Down

0 comments on commit b3939ba

Please sign in to comment.