Skip to content

Commit b3939ba

Browse files
committed
feat: allow trial on default plan of billing account
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]>
1 parent 8d0bca6 commit b3939ba

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Diff for: core/event/service.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,19 @@ func (p *Service) EnsureDefaultPlan(ctx context.Context, orgID string) error {
135135
return fmt.Errorf("failed to get default plan: %w", err)
136136
}
137137

138+
var totalPrice int64
138139
for _, prod := range defaultPlan.Products {
139140
for _, price := range prod.Prices {
140-
if price.Amount > 0 {
141-
return fmt.Errorf("default plan is not free")
142-
}
141+
totalPrice += price.Amount
143142
}
144143
}
144+
if totalPrice > 0 && defaultPlan.TrialDays == 0 {
145+
return fmt.Errorf("default plan is not free to start")
146+
}
147+
145148
_, _, err = p.checkoutService.Apply(ctx, checkout.Checkout{
146149
CustomerID: customr.ID,
147150
PlanID: defaultPlan.ID,
148-
SkipTrial: true,
149151
})
150152
if err != nil {
151153
return fmt.Errorf("failed to apply default plan: %w", err)

0 commit comments

Comments
 (0)