-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaccounts.go
352 lines (316 loc) · 13.1 KB
/
accounts.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
package whmcsgo
import (
"encoding/json"
"fmt"
"strings"
)
// AccountsService handles communication with the Client related
// methods of the WHMCS API.
//
// WHMCS API docs: https://developers.whmcs.com/api/api-index/
type AccountsService struct {
client *Client
}
// Account represents an WHMCS user.
type Account struct {
Address1 string `json:"address1"`
Address2 string `json:"address2"`
AllowSingleSignOn int `json:"allowSingleSignOn"`
Billingcid int `json:"billingcid"`
Cclastfour interface{} `json:"cclastfour"`
Cctype interface{} `json:"cctype"`
City string `json:"city"`
// Client struct {
// Address1 string `json:"address1"`
// Address2 string `json:"address2"`
// AllowSingleSignOn int `json:"allowSingleSignOn"`
// Billingcid int `json:"billingcid"`
// City string `json:"city"`
// Companyname string `json:"companyname"`
// Country string `json:"country"`
// Countrycode string `json:"countrycode"`
// Countryname string `json:"countryname"`
// Credit string `json:"credit"`
// Currency int `json:"currency"`
// CurrencyCode string `json:"currency_code"`
// Customfields []struct {
// ID int `json:"id"`
// Value string `json:"value"`
// } `json:"customfields"`
// Customfields1 string `json:"customfields1"`
// Customfields10 string `json:"customfields10"`
// Customfields11 string `json:"customfields11"`
// Customfields12 string `json:"customfields12"`
// Customfields13 string `json:"customfields13"`
// Customfields14 string `json:"customfields14"`
// Customfields15 string `json:"customfields15"`
// Customfields16 string `json:"customfields16"`
// Customfields17 string `json:"customfields17"`
// Customfields2 string `json:"customfields2"`
// Customfields3 string `json:"customfields3"`
// Customfields4 string `json:"customfields4"`
// Customfields5 string `json:"customfields5"`
// Customfields6 string `json:"customfields6"`
// Customfields7 string `json:"customfields7"`
// Customfields8 string `json:"customfields8"`
// Customfields9 string `json:"customfields9"`
// Defaultgateway string `json:"defaultgateway"`
// Disableautocc bool `json:"disableautocc"`
// Email string `json:"email"`
// Emailoptout bool `json:"emailoptout"`
// Firstname string `json:"firstname"`
// Fullname string `json:"fullname"`
// Fullstate string `json:"fullstate"`
// Groupid int `json:"groupid"`
// ID int `json:"id"`
// IsOptedInToMarketingEmails bool `json:"isOptedInToMarketingEmails"`
// Language string `json:"language"`
// Lastlogin string `json:"lastlogin"`
// Lastname string `json:"lastname"`
// Latefeeoveride bool `json:"latefeeoveride"`
// MarketingEmailsOptIn bool `json:"marketing_emails_opt_in"`
// Notes string `json:"notes"`
// Overideduenotices bool `json:"overideduenotices"`
// Overrideautoclose bool `json:"overrideautoclose"`
// Password string `json:"password"`
// Phonecc int `json:"phonecc"`
// Phonenumber string `json:"phonenumber"`
// Phonenumberformatted string `json:"phonenumberformatted"`
// Postcode string `json:"postcode"`
// Securityqans string `json:"securityqans"`
// Securityqid int `json:"securityqid"`
// Separateinvoices bool `json:"separateinvoices"`
// State string `json:"state"`
// Statecode string `json:"statecode"`
// Status string `json:"status"`
// TaxID string `json:"tax_id"`
// Taxexempt bool `json:"taxexempt"`
// TelephoneNumber string `json:"telephoneNumber"`
// Twofaenabled bool `json:"twofaenabled"`
// Userid int `json:"userid"`
// UUID string `json:"uuid"`
// } `json:"client"`
Companyname string `json:"companyname"`
Country string `json:"country"`
Countrycode string `json:"countrycode"`
Countryname string `json:"countryname"`
Credit string `json:"credit"`
Currency int `json:"currency"`
CurrencyCode string `json:"currency_code"`
// Customfields []struct {
// ID int `json:"id"`
// Value string `json:"value"`
// } `json:"customfields"`
// Customfields1 string `json:"customfields1"`
// Customfields10 string `json:"customfields10"`
// Customfields11 string `json:"customfields11"`
// Customfields12 string `json:"customfields12"`
// Customfields13 string `json:"customfields13"`
// Customfields14 string `json:"customfields14"`
// Customfields15 string `json:"customfields15"`
// Customfields16 string `json:"customfields16"`
// Customfields17 string `json:"customfields17"`
// Customfields2 string `json:"customfields2"`
// Customfields3 string `json:"customfields3"`
// Customfields4 string `json:"customfields4"`
// Customfields5 string `json:"customfields5"`
// Customfields6 string `json:"customfields6"`
// Customfields7 string `json:"customfields7"`
// Customfields8 string `json:"customfields8"`
// Customfields9 string `json:"customfields9"`
Defaultgateway string `json:"defaultgateway"`
Disableautocc bool `json:"disableautocc"`
Email string `json:"email"`
Emailoptout bool `json:"emailoptout"`
Firstname string `json:"firstname"`
Fullname string `json:"fullname"`
Fullstate string `json:"fullstate"`
Gatewayid interface{} `json:"gatewayid"`
Groupid int `json:"groupid"`
ID int `json:"id"`
IsOptedInToMarketingEmails bool `json:"isOptedInToMarketingEmails"`
Language string `json:"language"`
Lastlogin string `json:"lastlogin"`
Lastname string `json:"lastname"`
Latefeeoveride bool `json:"latefeeoveride"`
MarketingEmailsOptIn bool `json:"marketing_emails_opt_in"`
Notes string `json:"notes"`
Overideduenotices bool `json:"overideduenotices"`
Overrideautoclose bool `json:"overrideautoclose"`
Password string `json:"password"`
Phonecc int `json:"phonecc"`
Phonenumber string `json:"phonenumber"`
Phonenumberformatted string `json:"phonenumberformatted"`
Postcode string `json:"postcode"`
Result string `json:"result"`
Securityqans string `json:"securityqans"`
Securityqid int `json:"securityqid"`
Separateinvoices bool `json:"separateinvoices"`
State string `json:"state"`
Statecode string `json:"statecode"`
Status string `json:"status"`
TaxID string `json:"tax_id"`
Taxexempt bool `json:"taxexempt"`
TelephoneNumber string `json:"telephoneNumber"`
Twofaenabled bool `json:"twofaenabled"`
Userid int `json:"userid"`
UUID string `json:"uuid"`
}
func (u Account) String() string {
return Stringify(u)
}
/*
GetContacts Obtain the Client Contacts that match passed criteria
WHMCS API docs
https://developers.whmcs.com/api-reference/getcontacts/
Request Parameters
limitstart
The offset for the returned log data (default: 0) Optional
limitnum
The number of records to return (default: 25) Optional
userid
Find contacts for a specific client id Optional
firstname
Find contacts with a specific first name Optional
lastname
Find contacts with a specific last name Optional
companyname
Find contacts with a specific company name Optional
email
Find contacts with a specific email address Optional
address1
Find contacts with a specific address line 1 Optional
address2
Find contacts with a specific address line 2 Optional
city
Find contacts with a specific city Optional
state
Find contacts with a specific state Optional
postcode
Find contacts with a specific post/zip code Optional
country
Find contacts with a specific country Optional
phonenumber
Find contacts with a specific phone number Optional
subaccount
Search for sub-accounts Optional
*/
func (s *AccountsService) GetContacts(parms map[string]string) (*Account, *Response, error) {
a := new(Account)
resp, err := do(s.client, Params{parms: parms, u: "GetContacts"}, a)
if err != nil {
return nil, resp, err
}
err = json.Unmarshal([]byte(resp.Body), &a)
return a, resp, err
}
// WHMCSclient opbect
type WHMCSclient struct {
Companyname string `json:"companyname"`
Datecreated WHCMSdate `json:"datecreated"`
Email string `json:"email"`
Firstname string `json:"firstname"`
Groupid int `json:"groupid"`
ID int `json:"id"`
Lastname string `json:"lastname"`
Status string `json:"status"`
}
// WHMCSclients object
type WHMCSclients struct {
Clients struct {
Client []WHMCSclient `json:"client"`
} `json:"clients"`
Numreturned int `json:"numreturned"`
Result string `json:"result"`
Startnumber int `json:"startnumber"`
Totalresults int `json:"totalresults"`
}
// ContactList quick contact list
type ContactList struct {
CompanyName string `json:"companyname"`
FullName string `json:"fullname"`
Phone string `json:"phonenumberformatted"`
VendorSoftware string `json:"customfields3"`
VMRef string `json:"customfields1"`
AlertPrimary string `json:"customfields5"`
Status string `json:"status"`
UserID int `json:"userid"`
State string `json:"state"`
Email string `json:"email"`
GroupID int `json:"groupid"`
}
/*
ClientContactList list of contact for a given status
*/
func (s *AccountsService) ClientContactList(status string) ([]ContactList, error) {
params := map[string]string{"sorting": "ASC", "limitstart": "0", "limitnum": "2500"}
var contactList []ContactList
// obj := new(WHMCSclients)
obj, _, err := s.GetClients(params)
if err != nil {
return nil, err
}
for _, c := range obj.Clients.Client {
if c.Status == status {
cl := ContactList{}
clientid := fmt.Sprintf("%d", c.ID)
clParams := map[string]string{"clientid": clientid}
resp, err := do(s.client, Params{parms: clParams, u: "GetClientsDetails"}, cl)
if err != nil {
fmt.Println(err)
}
err = json.Unmarshal([]byte(resp.Body), &cl)
if err != nil {
fmt.Println(err)
}
cl.VendorSoftware = strings.TrimSpace(cl.VendorSoftware)
cl.Phone = strings.Replace(cl.Phone, "+61.", "0", -1)
cl.Phone = strings.Replace(cl.Phone, " ", "", -1)
if len(cl.Phone) == 10 {
cl.Phone = fmt.Sprintf("%s %s %s", cl.Phone[0:4], cl.Phone[4:7], cl.Phone[7:10])
}
cl.AlertPrimary = strings.Replace(cl.AlertPrimary, " ", "", -1)
if len(cl.AlertPrimary) == 10 {
cl.AlertPrimary = fmt.Sprintf("%s %s %s", cl.AlertPrimary[0:4], cl.AlertPrimary[4:7], cl.AlertPrimary[7:10])
}
contactList = append(contactList, cl)
}
}
return contactList, nil
}
// ClientLastBilledList quick contact list
type ClientLastBilledList struct {
CompanyName string `json:"companyname"`
Date string `json:"date"`
Total string `json:"total"`
Status string `json:"status"`
}
/*
ClientLastBilled list of the last invoice date
*/
func (s *AccountsService) ClientLastBilled(status string) ([]ClientLastBilledList, error) {
params := map[string]string{"sorting": "ASC", "limitstart": "0", "limitnum": "2500"}
var contactList []ClientLastBilledList
// obj := new(WHMCSclients)
obj, _, err := s.GetClients(params)
if err != nil {
return nil, err
}
for _, c := range obj.Clients.Client {
if c.Status == status {
cl := ClientLastBilledList{}
clientid := fmt.Sprintf("%d", c.ID)
clParams := map[string]string{"clientid": clientid}
resp, err := do(s.client, Params{parms: clParams, u: "GetClientsDetails"}, cl)
if err != nil {
fmt.Println(err)
}
err = json.Unmarshal([]byte(resp.Body), &cl)
if err != nil {
fmt.Println(err)
}
contactList = append(contactList, cl)
}
}
return contactList, nil
}