-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbeneficial_owner.go
203 lines (160 loc) · 6.29 KB
/
beneficial_owner.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package dwolla
import (
"context"
"errors"
"fmt"
)
const (
// BeneficialOwnerStatusDocument is when the beneficial owner needs verification document
BeneficialOwnerStatusDocument BeneficialOwnerStatus = "document"
// BeneficialOwnerStatusIncomplete is when the beneficial owner is incomplete
BeneficialOwnerStatusIncomplete BeneficialOwnerStatus = "incomplete"
// BeneficialOwnerStatusVerified is when the beneficial owner is verified
BeneficialOwnerStatusVerified BeneficialOwnerStatus = "verified"
)
const (
// CertificationStatusCertified is when the ownership status is certified
CertificationStatusCertified CertificationStatus = "certified"
// CertificationStatusRecertify is when the ownership status needs
// to be recertified
CertificationStatusRecertify CertificationStatus = "recertify"
// CertificationStatusUncertified is when the ownership status is uncertified
CertificationStatusUncertified CertificationStatus = "uncertified"
)
// BeneficialOwnerService is the beneficial owner service interface
//
// see: https://docsv2.dwolla.com/#beneficial-owners
type BeneficialOwnerService interface {
Remove(context.Context, string) error
Retrieve(context.Context, string) (*BeneficialOwner, error)
Update(context.Context, string, *BeneficialOwnerRequest) (*BeneficialOwner, error)
}
// BeneficialOwnerServiceOp is an implementation of the beneficial owner
// service
type BeneficialOwnerServiceOp struct {
client *Client
}
// BeneficialOwnerStatus is the status of the beneficial owner
type BeneficialOwnerStatus string
// BeneficialOwner is a beneficial owner
type BeneficialOwner struct {
Resource
ID string `json:"id"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Address Address `json:"address"`
Passport Passport `json:"passport"`
VerificationStatus BeneficialOwnerStatus `json:"verificationStatus"`
}
// BeneficialOwners is a collection of beneficial owners
type BeneficialOwners struct {
Collection
Embedded map[string][]BeneficialOwner `json:"_embedded"`
}
// BeneficialOwnerRequest is a beneficial owner request
type BeneficialOwnerRequest struct {
FirstName string `json:"firstName,omitempty"`
LastName string `json:"lastName,omitempty"`
DateOfBirth string `json:"dateOfBirth,omitempty"`
SSN string `json:"ssn,omitempty"`
Address Address `json:"address,omitempty"`
Passport *Passport `json:"passport,omitempty"`
}
// CertificationStatus is the beneficial ownership certification status
type CertificationStatus string
// BeneficialOwnership is the beneficial ownership status
type BeneficialOwnership struct {
Resource
Status CertificationStatus `json:"status"`
}
// BeneficialOwnershipRequest is a beneficial ownership request
type BeneficialOwnershipRequest struct {
Status CertificationStatus `json:"status,omitempty"`
}
// Remove removes a beneficial owner matching the id
//
// see: https://docsv2.dwolla.com/#remove-a-beneficial-owner
func (b *BeneficialOwnerServiceOp) Remove(ctx context.Context, id string) error {
return b.client.Delete(ctx, fmt.Sprintf("beneficial-owners/%s", id), nil, nil)
}
// Retrieve retrieves a beneficial owner matching the id
//
// see: https://docsv2.dwolla.com/#retrieve-a-beneficial-owner
func (b *BeneficialOwnerServiceOp) Retrieve(ctx context.Context, id string) (*BeneficialOwner, error) {
var owner BeneficialOwner
if err := b.client.Get(ctx, fmt.Sprintf("beneficial-owners/%s", id), nil, nil, &owner); err != nil {
return nil, err
}
owner.client = b.client
return &owner, nil
}
// Update updates a beneficial owner matching the id
//
// see: https://docsv2.dwolla.com/#update-a-beneficial-owner
func (b *BeneficialOwnerServiceOp) Update(ctx context.Context, id string, body *BeneficialOwnerRequest) (*BeneficialOwner, error) {
var owner BeneficialOwner
if err := b.client.Post(ctx, fmt.Sprintf("beneficial-owners/%s", id), body, nil, &owner); err != nil {
return nil, err
}
owner.client = b.client
return &owner, nil
}
// CreateDocument uploads a document for the beneficial owner
//
// see: https://docsv2.dwolla.com/#create-a-document-for-a-beneficial-owner
func (b *BeneficialOwner) CreateDocument(ctx context.Context, body *DocumentRequest) (*Document, error) {
var document Document
if _, ok := b.Links["self"]; !ok {
return nil, errors.New("No self resource link")
}
if err := b.client.Upload(ctx, fmt.Sprintf("%s/documents", b.Links["self"].Href), body.Type, body.FileName, body.File, &document); err != nil {
return nil, err
}
document.client = b.client
return &document, nil
}
// ListDocuments returns documents for beneficial owner
//
// see: https://docsv2.dwolla.com/#list-documents-for-beneficial-owners
func (b *BeneficialOwner) ListDocuments(ctx context.Context) (*Documents, error) {
var documents Documents
if _, ok := b.Links["self"]; !ok {
return nil, errors.New("No self resource link")
}
if err := b.client.Get(ctx, fmt.Sprintf("%s/documents", b.Links["self"].Href), nil, nil, &documents); err != nil {
return nil, err
}
documents.client = b.client
for i := range documents.Embedded["documents"] {
documents.Embedded["documents"][i].client = b.client
}
return &documents, nil
}
// Remove removes the beneficial owner
//
// see: https://docsv2.dwolla.com/#remove-a-beneficial-owner
func (b *BeneficialOwner) Remove(ctx context.Context) error {
if _, ok := b.Links["self"]; !ok {
return errors.New("No self resource link")
}
return b.client.Delete(ctx, b.Links["self"].Href, nil, nil)
}
// Update updates the dwolla beneficial owner
//
// see: https://docsv2.dwolla.com/#update-a-beneficial-owner
func (b *BeneficialOwner) Update(ctx context.Context, body *BeneficialOwnerRequest) error {
if _, ok := b.Links["self"]; !ok {
return errors.New("No self resource link")
}
return b.client.Post(ctx, b.Links["self"].Href, body, nil, b)
}
// Certify certifies beneficial ownership
//
// see: https://docsv2.dwolla.com/#certify-beneficial-ownership
func (b *BeneficialOwnership) Certify(ctx context.Context) error {
if _, ok := b.Links["self"]; !ok {
return errors.New("No self resource link")
}
request := &BeneficialOwnershipRequest{Status: CertificationStatusCertified}
return b.client.Post(ctx, b.Links["self"].Href, request, nil, b)
}