forked from gotsunami/mangopay2-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.go
61 lines (52 loc) · 1.35 KB
/
user.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
// Copyright 2014 Mathias Monnerville. All rights reserved.
// Use of this source code is governed by a GPL
// license that can be found in the LICENSE file.
package mango
const (
KYCLevelLight = "LIGHT"
KYCLevelRegular = "REGULAR"
)
const (
PersonTypeNatural = "NATURAL"
PersonTypeLegal = "LEGAL"
)
// A Consumer is a legal or natural user with zero, one or
// more wallets and tranfers.
type Consumer interface {
// All user's wallets
Wallets() (WalletList, error)
// All user's transactions
Transfers() (TransferList, error)
}
type UserList []*User
// User is used by the user activity API and describe common fields to
// both natural and legal users.
type User struct {
ProcessIdent
PersonType string
Email string
}
func (u *User) String() string {
return struct2string(u)
}
// Users returns a list of all registered users, either natural
// or legal.
func (m *MangoPay) Users() (UserList, error) {
resp, err := m.request(actionAllUsers, nil)
if err != nil {
return nil, err
}
ul := UserList{}
if err := m.unMarshalJSONResponse(resp, &ul); err != nil {
return nil, err
}
return ul, nil
}
// User fetch a user (natural or legal) using the Id attribute.
func (m *MangoPay) User(id string) (*User, error) {
u, err := m.anyRequest(new(User), actionFetchUser, JsonObject{"Id": id})
if err != nil {
return nil, err
}
return u.(*User), nil
}