-
Notifications
You must be signed in to change notification settings - Fork 1
/
payments.go
115 lines (103 loc) · 2.39 KB
/
payments.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package domain
import (
"github.com/michaljemala/payments-sample/pkg/internal/errors"
"github.com/michaljemala/payments-sample/pkg/internal/resource"
)
type Payment struct {
BaseObject
Amount Monetary `json:"amount"`
Creditor PaymentParty `json:"creditor"`
Debtor PaymentParty `json:"debtor"`
Scheme string `json:"scheme"`
}
func (p Payment) Validate() error {
if p.ID.IsNil() {
return errors.Generic(
errors.ErrCodeGenericInvalidArgument,
"invalid payment",
"payment id must not be nil",
)
}
if p.Scheme == "" {
return errors.Generic(
errors.ErrCodeGenericInvalidArgument,
"invalid payment",
"invalid payment scheme",
)
}
if p.Amount.Currency == "" {
return errors.Generic(
errors.ErrCodeGenericInvalidArgument,
"invalid payment",
"invalid amount currency code",
)
}
if p.Creditor.AccountNumber == "" {
return errors.Generic(
errors.ErrCodeGenericInvalidArgument,
"invalid payment",
"invalid creditor account number",
)
}
if p.Debtor.AccountNumber == "" {
return errors.Generic(
errors.ErrCodeGenericInvalidArgument,
"invalid payment",
"invalid debtor account number",
)
}
return nil
}
type PaymentParty struct {
Name string `json:"name"`
Address Address `json:"address"`
AccountName string `json:"account_name"`
AccountNumber string `json:"account_number"`
AccountProvider AccountProvider `json:"account_provider"`
}
type AccountProvider struct {
Code string `json:"code"`
Name *string `json:"name,omitempty"`
}
type Monetary struct {
Value Decimal `json:"value"`
Currency string `json:"currency"`
}
type PaymentSearchRequest struct {
*resource.SearchPagination
resource.SearchFilter
}
func (r PaymentSearchRequest) IDs() []ID {
if r.SearchFilter == nil {
return nil
}
ids, ok := r.SearchFilter["id"].([]ID)
if !ok {
return nil
}
return ids
}
func (r PaymentSearchRequest) CreditorAccountNumbers() []string {
if r.SearchFilter == nil {
return nil
}
numbers, ok := r.SearchFilter["creditor.account_number"].([]string)
if !ok {
return nil
}
return numbers
}
func (r PaymentSearchRequest) DebtorAccountNumbers() []string {
if r.SearchFilter == nil {
return nil
}
numbers, ok := r.SearchFilter["debtor.account_number"].([]string)
if !ok {
return nil
}
return numbers
}
type PaymentSearchResponse struct {
Data []*Payment
Size uint
}