| package subscription |
|
|
| import ( |
| "time" |
|
|
| "github.com/openmeterio/openmeter/openmeter/customer" |
| "github.com/openmeterio/openmeter/openmeter/productcatalog" |
| "github.com/openmeterio/openmeter/pkg/currencyx" |
| "github.com/openmeterio/openmeter/pkg/datetime" |
| "github.com/openmeterio/openmeter/pkg/models" |
| ) |
|
|
| type Subscription struct { |
| models.NamespacedID |
| models.ManagedModel |
| models.CadencedModel |
| models.MetadataModel |
|
|
| Name string `json:"name,omitempty"` |
| Description *string `json:"description,omitempty"` |
|
|
| |
| PlanRef *PlanRef `json:"planRef"` |
|
|
| CustomerId string `json:"customerId,omitempty"` |
| Currency currencyx.Code `json:"currency,omitempty"` |
|
|
| BillingCadence datetime.ISODuration `json:"billing_cadence"` |
| BillingAnchor time.Time `json:"billingAnchor"` |
| ProRatingConfig productcatalog.ProRatingConfig `json:"pro_rating_config"` |
| SettlementMode productcatalog.SettlementMode `json:"settlement_mode"` |
|
|
| Annotations models.Annotations `json:"annotations"` |
| } |
|
|
| func (s Subscription) AsEntityInput() CreateSubscriptionEntityInput { |
| return CreateSubscriptionEntityInput{ |
| CadencedModel: s.CadencedModel, |
| NamespacedModel: models.NamespacedModel{ |
| Namespace: s.Namespace, |
| }, |
| MetadataModel: s.MetadataModel, |
| Annotations: s.Annotations, |
| Plan: s.PlanRef, |
| Name: s.Name, |
| Description: s.Description, |
| CustomerId: s.CustomerId, |
| Currency: s.Currency, |
| BillingCadence: s.BillingCadence, |
| BillingAnchor: s.BillingAnchor, |
| ProRatingConfig: s.ProRatingConfig, |
| SettlementMode: s.SettlementMode, |
| } |
| } |
|
|
| func (s Subscription) GetStatusAt(at time.Time) SubscriptionStatus { |
| |
| if s.CadencedModel.IsZero() { |
| return SubscriptionStatusInactive |
| } |
|
|
| if s.DeletedAt != nil && !s.DeletedAt.After(at) { |
| return SubscriptionStatusInactive |
| } |
|
|
| |
| if !s.ActiveFrom.After(at) { |
| |
| if s.ActiveTo == nil { |
| return SubscriptionStatusActive |
| } |
| |
| if s.ActiveTo.After(at) { |
| return SubscriptionStatusCanceled |
| } |
| } else { |
| |
| return SubscriptionStatusScheduled |
| } |
|
|
| |
| return SubscriptionStatusInactive |
| } |
|
|
| func (s Subscription) GetCustomerID() customer.CustomerID { |
| return customer.CustomerID{ |
| Namespace: s.Namespace, |
| ID: s.CustomerId, |
| } |
| } |
|
|