forked from jinmatt/go-quickbooks.v2
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcustomer.go
92 lines (81 loc) · 3.14 KB
/
customer.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
package quickbooks
import (
"encoding/json"
"fmt"
)
// CustomerObject the complete quickbooks customer object type
type CustomerObject struct {
Customer Customer `json:"Customer"`
Time string `json:"time"`
}
// Customer quickbooks customer type
type Customer struct {
ID string `json:"Id,omitempty"`
Taxable bool `json:"Taxable,omitempty"`
BillAddr *Address `json:"BillAddr,omitempty"`
ShipAddr *Address `json:"ShipAddr,omitempty"`
Job bool `json:"Job,omitempty"`
BillWithParent bool `json:"BillWithParent,omitempty"`
Balance float64 `json:"Balance,omitempty"`
BalanceWithJobs float64 `json:"BalanceWithJobs,omitempty"`
PreferredDeliveryMethod string `json:"PreferredDeliveryMethod,omitempty"`
Domain string `json:"domain,omitempty"`
Sparse bool `json:"sparse,omitempty"`
SyncToken string `json:"SyncToken,omitempty"`
GivenName string `json:"GivenName"`
MiddleName string `json:"MiddleName,omitempty"`
FamilyName string `json:"FamilyName"`
FullyQualifiedName string `json:"FullyQualifiedName,omitempty"`
CompanyName string `json:"CompanyName,omitempty"`
DisplayName string `json:"DisplayName"`
PrintOnCheckName string `json:"PrintOnCheckName,omitempty"`
Active bool `json:"Active,omitempty"`
PrimaryPhone *struct {
FreeFormNumber string `json:"FreeFormNumber"`
} `json:"PrimaryPhone,omitempty"`
AlternatePhone *struct {
FreeFormNumber string `json:"FreeFormNumber"`
} `json:"AlternatePhone,omitempty"`
PrimaryEmailAddr *struct {
Address string `json:"Address"`
} `json:"PrimaryEmailAddr,omitempty"`
ResaleNum string `json:"ResaleNum,omitempty"`
Notes string `json:"Notes,omitempty"`
MetaData *struct {
CreateTime string `json:"CreateTime"`
LastUpdatedTime string `json:"LastUpdatedTime"`
} `json:"MetaData,omitempty"`
}
// Address quickbooks address object
type Address struct {
ID string `json:"Id,omitempty"`
Line1 string `json:"Line1"`
Line2 string `json:"Line2,omitempty"`
City string `json:"City"`
CountrySubDivisionCode string `json:"CountrySubDivisionCode"`
PostalCode string `json:"PostalCode"`
Lat string `json:"Lat,omitempty"`
Long string `json:"Long,omitempty"`
}
// CustomerRef quickbooks customer reference object
type CustomerRef struct {
Value string `json:"value"`
Name string `json:"name,omitempty"`
}
// CreateCustomer creates a customer on quickbooks
func (q *Quickbooks) CreateCustomer(customer Customer) (*CustomerObject, error) {
endpoint := fmt.Sprintf("/company/%s/customer", q.RealmID)
res, err := q.makePostRequest(endpoint, customer)
if err != nil {
return nil, err
}
if res.Body != nil {
defer res.Body.Close()
}
newCustomer := CustomerObject{}
err = json.NewDecoder(res.Body).Decode(&newCustomer)
if err != nil {
return nil, err
}
return &newCustomer, nil
}