-
Notifications
You must be signed in to change notification settings - Fork 37
/
company.go
71 lines (60 loc) · 1.59 KB
/
company.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
// Copyright (c) 2018, Randy Westlund. All rights reserved.
// This code is under the BSD-2-Clause license.
package quickbooks
// CompanyInfo describes a company account.
type CompanyInfo struct {
CompanyName string
LegalName string
// CompanyAddr
// CustomerCommunicationAddr
// LegalAddr
// PrimaryPhone
// CompanyStartDate Date
CompanyStartDate string
FiscalYearStartMonth string
Country string
// Email
// WebAddr
SupportedLanguages string
// NameValue
Domain string
Id string
SyncToken string
Metadata MetaData `json:",omitempty"`
}
// FindCompanyInfo returns the QuickBooks CompanyInfo object. This is a good
// test to check whether you're connected.
func (c *Client) FindCompanyInfo() (*CompanyInfo, error) {
var resp struct {
CompanyInfo CompanyInfo
Time Date
}
if err := c.get("companyinfo/"+c.realmId, &resp, nil); err != nil {
return nil, err
}
return &resp.CompanyInfo, nil
}
// UpdateCompanyInfo updates the company info
func (c *Client) UpdateCompanyInfo(companyInfo *CompanyInfo) (*CompanyInfo, error) {
existingCompanyInfo, err := c.FindCompanyInfo()
if err != nil {
return nil, err
}
companyInfo.Id = existingCompanyInfo.Id
companyInfo.SyncToken = existingCompanyInfo.SyncToken
payload := struct {
*CompanyInfo
Sparse bool `json:"sparse"`
}{
CompanyInfo: companyInfo,
Sparse: true,
}
var companyInfoData struct {
CompanyInfo CompanyInfo
Time Date
}
if err = c.post("companyInfo", payload, &companyInfoData, nil); err != nil {
return nil, err
}
return &companyInfoData.CompanyInfo, err
}