-
Notifications
You must be signed in to change notification settings - Fork 31
/
credit.go
72 lines (56 loc) · 1.59 KB
/
credit.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
package credit
import (
"errors"
"time"
"github.com/google/uuid"
"github.com/raystack/frontier/pkg/metadata"
)
var (
ErrNotFound = errors.New("transaction not found")
ErrInvalidUUID = errors.New("invalid syntax of uuid")
ErrInvalidID = errors.New("invalid transaction id")
ErrInvalidDetail = errors.New("invalid transaction detail")
ErrInsufficientCredits = errors.New("insufficient credits")
ErrAlreadyApplied = errors.New("credits already applied")
// TxNamespaceUUID is the namespace for generating transaction UUIDs deterministically
TxNamespaceUUID = uuid.MustParse("967416d0-716e-4308-b58f-2468ac14f20a")
SourceSystemBuyEvent = "system.buy"
SourceSystemAwardedEvent = "system.awarded"
SourceSystemOnboardEvent = "system.starter"
SourceSystemRevertEvent = "system.revert"
)
type TransactionType string
func (t TransactionType) String() string {
return string(t)
}
const (
DebitType TransactionType = "debit"
CreditType TransactionType = "credit"
)
type Transaction struct {
ID string
CustomerID string
Amount int64
Type TransactionType
// Source is the source app or event that caused the transaction
Source string
Description string
// UserID is the user who initiated the transaction
UserID string
Metadata metadata.Metadata
CreatedAt time.Time
UpdatedAt time.Time
}
type Credit struct {
ID string
CustomerID string
Amount int64
UserID string
Source string
Description string
Metadata metadata.Metadata
}
type Filter struct {
CustomerID string
Since time.Time
}