-
Notifications
You must be signed in to change notification settings - Fork 32
/
subscription.go
79 lines (63 loc) · 1.82 KB
/
subscription.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package subscription
import (
"fmt"
"time"
"github.com/raystack/frontier/pkg/metadata"
)
var (
ErrNotFound = fmt.Errorf("subscription not found")
ErrInvalidUUID = fmt.Errorf("invalid syntax of uuid")
ErrInvalidID = fmt.Errorf("invalid subscription id")
ErrInvalidDetail = fmt.Errorf("invalid subscription detail")
ErrAlreadyOnSamePlan = fmt.Errorf("already on the same plan")
ErrNoPhaseActive = fmt.Errorf("no phase active")
ErrPhaseIsUpdating = fmt.Errorf("phase is in the middle of a change, please try again later")
ErrSubscriptionOnProviderNotFound = fmt.Errorf("failed to get subscription from billing provider")
)
type State string
func (s State) String() string {
return string(s)
}
const (
StateActive State = "active"
StateTrialing State = "trialing"
StatePastDue State = "past_due"
)
type Phase struct {
EffectiveAt time.Time
EndsAt time.Time
PlanID string
}
type ChangeRequest struct {
PlanID string
Immediate bool
CancelUpcoming bool
}
type Subscription struct {
ID string
ProviderID string // identifier set by the billing engine provider
CustomerID string
PlanID string
State string
Metadata metadata.Metadata
Phase Phase
PlanHistory []Phase
CreatedAt time.Time
UpdatedAt time.Time
CanceledAt time.Time
DeletedAt time.Time
EndedAt time.Time
TrialEndsAt time.Time
CurrentPeriodStartAt time.Time
CurrentPeriodEndAt time.Time
BillingCycleAnchorAt time.Time
}
func (s Subscription) IsActive() bool {
return State(s.State) == StateActive || State(s.State) == StateTrialing
}
type Filter struct {
CustomerID string
ProviderID string
PlanID string
State string
}