Skip to content

Commit

Permalink
Expose BillingCadence for all RateCards (#1956)
Browse files Browse the repository at this point in the history
  • Loading branch information
GAlexIHU authored Dec 10, 2024
1 parent ceef8d3 commit d0e1991
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
9 changes: 9 additions & 0 deletions openmeter/productcatalog/ratecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type RateCard interface {
Feature() *feature.Feature
Key() string
Merge(RateCard) error
GetBillingCadence() *datex.Period
}

type RateCardSerde struct {
Expand Down Expand Up @@ -157,6 +158,10 @@ type FlatFeeRateCard struct {
BillingCadence *datex.Period `json:"billingCadence"`
}

func (r *FlatFeeRateCard) GetBillingCadence() *datex.Period {
return r.BillingCadence
}

func (r *FlatFeeRateCard) Merge(v RateCard) error {
if r.Type() != v.Type() {
return errors.New("type mismatch")
Expand Down Expand Up @@ -240,6 +245,10 @@ type UsageBasedRateCard struct {
BillingCadence datex.Period `json:"billingCadence"`
}

func (r *UsageBasedRateCard) GetBillingCadence() *datex.Period {
return &r.BillingCadence
}

func (r *UsageBasedRateCard) Merge(v RateCard) error {
if r.Type() != v.Type() {
return errors.New("type mismatch")
Expand Down
17 changes: 1 addition & 16 deletions openmeter/productcatalog/subscription/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/openmeterio/openmeter/openmeter/productcatalog"
"github.com/openmeterio/openmeter/openmeter/subscription"
"github.com/openmeterio/openmeter/pkg/currencyx"
"github.com/openmeterio/openmeter/pkg/datex"
"github.com/openmeterio/openmeter/pkg/models"
)

Expand Down Expand Up @@ -98,20 +97,6 @@ func (r *RateCard) ToCreateSubscriptionItemPlanInput() subscription.CreateSubscr
fk = &m.Feature.Key
}

var cadence *datex.Period

// FIXME: BillingCadence could be a method on RateCard
switch r.RateCard.Type() {
case productcatalog.FlatFeeRateCardType:
if rc, ok := r.RateCard.(*productcatalog.FlatFeeRateCard); ok {
cadence = rc.BillingCadence
}
case productcatalog.UsageBasedRateCardType:
if rc, ok := r.RateCard.(*productcatalog.UsageBasedRateCard); ok {
cadence = &rc.BillingCadence
}
}

return subscription.CreateSubscriptionItemPlanInput{
PhaseKey: r.PhaseKey,
ItemKey: r.Key(),
Expand All @@ -122,7 +107,7 @@ func (r *RateCard) ToCreateSubscriptionItemPlanInput() subscription.CreateSubscr
EntitlementTemplate: m.EntitlementTemplate,
TaxConfig: m.TaxConfig,
Price: m.Price,
BillingCadence: cadence,
BillingCadence: r.GetBillingCadence(),
},
}
}
Expand Down

0 comments on commit d0e1991

Please sign in to comment.