-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
186 lines (159 loc) · 9.2 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
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
package igcclient
import (
"fmt"
"net/http"
"net/url"
"strconv"
"github.com/moonwalker/igcclient/models"
"github.com/moonwalker/logger"
)
type UserService service
// Sends an email.
// Currently supports the following email template ids:
// 1 (Contact Form template),
// 2 (Manual Deposit Request template)
// Does not consider currently authenticated user.
// All information is to be included in the EmailBodyPlaceholderValues.
// Key "Email" and "FullName" is reserved and not to be used - will exit with error if used.
//
// Expected error codes: UNSUPPORTED_EMAIL_TEMPLATE_ID, REQUEST_DATA_INVALID, RESERVED_KEY_EMAIL_TEMPLATE_PLACEHOLDER_VALUES
func (s *UserService) SendEmail(body models.SendEmailModel, headers map[string]string, log logger.Logger) (response models.OperationResponseOfDictionaryOfStringAndString, err error) {
err = s.client.apiReq(http.MethodPost, "/user/sendemail", nil, &body, &response, &headers, log)
return
}
// Get the turnover of a user for the current session
func (s *UserService) SessionTurnover(headers map[string]string, log logger.Logger) (response models.OperationResponseOfDecimal, err error) {
err = s.client.apiReq(http.MethodPost, "/user/sessionturnover", nil, nil, &response, &headers, log)
return
}
// Adds a Note to the Logged In User
func (s *UserService) AddUserNote(note string, headers map[string]string, log logger.Logger) (response models.OperationResponseOfBoolean, err error) {
q := url.Values{}
q.Add("note", note)
err = s.client.apiReq(http.MethodPost, "/user/addusernote", &q, nil, &response, &headers, log)
return
}
// Returns a list of users with no activity since the fromDate specified as parameter
// fromDate - should be in following format: 2017-01-01
// limit - the maximum number if users to return
func (s *UserService) GetUsersWithNoActivity(fromDate string, limit int64, headers map[string]string, log logger.Logger) (response models.OperationResponseOfIEnumerableOfUserWithNoActivity, err error) {
q := url.Values{}
q.Add("fromdate", fromDate)
q.Add("limit", fmt.Sprintf("%d", limit))
err = s.client.apiReq(http.MethodPost, "/user/getuserswithnoactivity", &q, nil, &response, &headers, log)
return
}
// Gets the Count of Similar Users with the exact same First Name and Last Name
func (s *UserService) GetSimilarUserCount(body models.SimilarUser, headers map[string]string, log logger.Logger) (response models.OperationResponseOfInt32, err error) {
err = s.client.apiReq(http.MethodPost, "/user/getsimilarusercount", nil, &body, &response, &headers, log)
return
}
// Adds in a KYC requirement where needed for Photo ID, Proof of Address and Proof of Payment
func (s *UserService) AddKYCRequirements(headers map[string]string, log logger.Logger) (response models.OperationResponseOfBoolean, err error) {
err = s.client.apiReq(http.MethodPost, "/user/addkycrequirements", nil, nil, &response, &headers, log)
return
}
// Gets the KYC for the user with supplied user id ordered by status and then by KYC type
// X-Api-Key header is required
func (s *UserService) KYCByUserID(userID int64, headers map[string]string, log logger.Logger) (response models.OperationResponseOfListOfKYCLinkedObject, err error) {
q := url.Values{}
q.Add("userid", fmt.Sprintf("%d", userID))
err = s.client.apiReq(http.MethodPost, "/user/kyc", &q, nil, &response, &headers, log)
return
}
// Gets the KYC for the current user ordered by status and then by KYC type
// AuthenticationToken header is required
func (s *UserService) KYC(headers map[string]string, log logger.Logger) (response models.OperationResponseOfListOfKYCLinkedObject, err error) {
err = s.client.apiReq(http.MethodPost, "/user/kyc", nil, nil, &response, &headers, log)
return
}
// Uploads a KYC file for the specified KYC item.
func (s *UserService) KYCUpload(body models.KYCUpload, headers map[string]string, log logger.Logger) (response models.OperationResponseOfBoolean, err error) {
err = s.client.apiReq(http.MethodPost, "/user/kyc/upload", nil, &body, &response, &headers, log)
return
}
//Allows the requesting of the following documents: ID, Proof of address, Payment method
func (s *UserService) KYCDocumentRequest(documentToRequest int64, headers map[string]string, log logger.Logger) (response models.OperationResponseOfBoolean, err error) {
id := strconv.FormatInt(documentToRequest, 10)
err = s.client.apiReq(http.MethodPost, "/user/kycdocumentrequest/"+url.QueryEscape(id), nil, nil, &response, &headers, log)
return
}
// Get the logged in user using the Authentication Token
func (s *UserService) User(headers map[string]string, log logger.Logger) (response models.OperationResponseOfSafeUserDetails, err error) {
err = s.client.apiReq(http.MethodPost, "/user", nil, nil, &response, &headers, log)
return
}
// Get the logged in user using the Authentication Token
func (s *UserService) UserV2(headers map[string]string, log logger.Logger) (response models.OperationResponseOfUserResponseDTO, err error) {
err = s.client.apiReq(http.MethodGet, "/v2/user", nil, nil, &response, &headers, log)
return
}
// Get user using the userID
func (s *UserService) UserByID(userID int64, headers map[string]string, log logger.Logger) (response models.OperationResponseOfSafeUserDetails, err error) {
q := url.Values{}
q.Add("userid", fmt.Sprintf("%d", userID))
err = s.client.apiReq(http.MethodPost, "/user", &q, nil, &response, &headers, log)
return
}
// Get user last logins
func (s *UserService) GetLoginHistory(headers map[string]string, log logger.Logger) (response models.OperationResponseOfListOfDBTokenIP, err error) {
err = s.client.apiReq(http.MethodGet, "/user/getloginhistory", nil, nil, &response, &headers, log)
return
}
// Accept terms for the logged in user
func (s *UserService) AcceptTerms(headers map[string]string, log logger.Logger) (response models.OperationResponseOfBoolean, err error) {
err = s.client.apiReq(http.MethodPost, "/user/acceptterms", nil, nil, &response, &headers, log)
return
}
// Update user details
func (s *UserService) Update(body models.UpdateUserObject, headers map[string]string, log logger.Logger) (response models.OperationResponseOfBoolean, err error) {
err = s.client.apiReq(http.MethodPost, "/user/update", nil, &body, &response, &headers, log)
return
}
// Email validation
func (s *UserService) CheckEmail(body models.CheckUser, headers map[string]string, log logger.Logger) (response models.OperationResponseOfBoolean, err error) {
err = s.client.apiReq(http.MethodPost, "/user/check/email", nil, &body, &response, &headers, log)
return
}
// Username validation
func (s *UserService) CheckUsername(body models.CheckUser, headers map[string]string, log logger.Logger) (response models.OperationResponseOfBoolean, err error) {
err = s.client.apiReq(http.MethodPost, "/user/check/username", nil, &body, &response, &headers, log)
return
}
// Combination validation This check if the user firstname, lastname, address and phone match with an existing user
func (s *UserService) CheckCombination(body models.UserObject, headers map[string]string, log logger.Logger) (response models.OperationResponseOfBoolean, err error) {
err = s.client.apiReq(http.MethodPost, "/user/check/combination", nil, &body, &response, &headers, log)
return
}
// Associates a user with an affiliate reference.
// Errors:
// USER_NOT_FOUND if user does not exist.
// USER_ALREADY_AFFILIATED if user is already affiliated.
// INVALID_AFFILIATE_REFERENCE if affiliate reference is null or empty.
func (s *UserService) SetAffiliateReference(userID int64, affiliateReference string, headers map[string]string, log logger.Logger) (response models.OperationResponseOfBoolean, err error) {
q := url.Values{}
q.Add("userid", fmt.Sprintf("%d", userID))
q.Add("affiliatereference", affiliateReference)
err = s.client.apiReq(http.MethodPost, "/user/setaffiliatereference", &q, nil, &response, &headers, log)
return
}
// Close user's account at their request. Requires user's date of birth to proceed Errors: USER_NOT_FOUND if user does not exist. INVALID_DATE_RANGE if date of birth is Empty/Incorrect. INVALID_DOB if date of birth is incorrect.
func (s *UserService) CloseAccount(body models.CloseAccountDOBRequestDto, headers map[string]string, log logger.Logger) (response models.OperationResponseOfBoolean, err error) {
err = s.client.apiReq(http.MethodPost, "/v2/user/closeaccount", nil, &body, &response, &headers, log)
return
}
func (s *UserService) PasswordSetOnce(body models.PasswordRequestDto, headers map[string]string, log logger.Logger) (response models.OperationResponse, err error) {
err = s.client.apiReq(http.MethodPost, "/user/password/setonce", nil, &body, &response, &headers, log)
return
}
func (s *UserService) GetUserActiveBlocks(userID int64, headers map[string]string, log logger.Logger) (response models.OperationResponseOfIListOfUserActiveBlock, err error) {
id := strconv.FormatInt(userID, 10)
err = s.client.apiReq(http.MethodGet, "/user/getuseractiveblocks/"+url.QueryEscape(id), nil, nil, &response, &headers, log)
return
}
func (s *UserService) GracePeriod(userID int64, headers map[string]string, log logger.Logger) (response models.OperationResponseOfListOfUserGracePeriodDTO, err error) {
q := url.Values{}
q.Add("userid", fmt.Sprintf("%d", userID))
err = s.client.apiReq(http.MethodPost, "/user/graceperiod", &q, nil, &response, &headers, log)
return
}