-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproduct.go
64 lines (51 loc) · 1.13 KB
/
product.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
package paymentwall
import "strconv"
type ProductType string
const (
ProductTypeSubscription ProductType = "subscription"
ProductTypeFixed ProductType = "fixed"
)
type PeriodType string
const (
PeriodTypeDay PeriodType = "day"
PeriodTypeWeek PeriodType = "week"
PeriodTypeMonth PeriodType = "month"
PeriodTypeYear PeriodType = "year"
)
func NewProduct(
name, id string,
amount float64, currency string,
pType ProductType) *Product {
p := &Product{
Name: name,
Identity: id,
Amount: amount,
Currency: currency,
Type: pType,
}
return p
}
type Product struct {
Name string
Identity string
Amount float64
Currency string
Type ProductType
Recurring bool
PeriodLength uint
PeriodType PeriodType
}
func (p *Product) SetSubscription(
periodLength uint,
periodType PeriodType,
isRecurring bool) {
p.Recurring = isRecurring
p.PeriodLength = periodLength
p.PeriodType = periodType
}
func (p *Product) DisplayAmount() string {
return strconv.FormatFloat(p.Amount, 'f', -1, 64)
}
func (p *Product) DisplayPeriodLength() string {
return strconv.FormatUint(uint64(p.PeriodLength), 10)
}