-
Notifications
You must be signed in to change notification settings - Fork 1
/
ent.go
100 lines (83 loc) · 1.9 KB
/
ent.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package pay
import (
"time"
)
type PricingSchedule = string
const (
PricingAnnual PricingSchedule = "annual"
PricingMonthly PricingSchedule = "monthly"
PricingOnce PricingSchedule = "once"
)
type Price struct {
ID int64
PlanID int64
Provider string
ProviderID string
Amount int64
Currency string
Schedule PricingSchedule
TrialDays int
}
func (p *Price) TableName() string {
return "pay.price"
}
func (p *Price) HasTrial() bool {
return p.TrialDays > 0
}
// TrialEnd returns the time at which the trial would end if it started now
func (p *Price) TrialEnd() time.Time {
return time.Now().Add(time.Hour * 24 * time.Duration(p.TrialDays))
}
// Plan that customers will subscribe to
type Plan struct {
ID int64
Name string
Description string
Provider string
ProviderID string
Active bool
}
func (p *Plan) TableName() string {
return "pay.plan"
}
// Customer from a provider like stripe or paypal
type Customer struct {
ID int64 // internal (to this service)
ProviderID string // external providers id
Provider string // the provider for this customer
Name string // customers name
Email string // customers email
}
func (c *Customer) TableName() string {
return "pay.customer"
}
// Subscription represents a customers subscription to a Plan
type Subscription struct {
ID int64
Provider string
ProviderID string
CustomerID int64
PriceID int64
Active bool
CreatedAt time.Time
}
func (s *Subscription) TableName() string {
return "pay.subscription"
}
type WebhookEvent struct {
ID int64
Provider string
ProviderID string
EventType string
Payload []byte
}
func (e *WebhookEvent) TableName() string {
return "pay.webhook_event"
}
type SubscriptionUser struct {
SubscriptionID int64
Username string
}
func (SubscriptionUser) TableName() string {
return "pay.subscription_user"
}