forked from getlago/lago-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
organization.go
105 lines (85 loc) · 4.03 KB
/
organization.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
package lago
import (
"context"
"time"
)
type OrganizationRequest struct {
client *Client
}
type OrganizationParams struct {
Organization *OrganizationInput `json:"organization"`
}
type OrganizationBillingConfigurationInput struct {
InvoiceGracePeriod int `json:"invoice_grace_period,omitempty"`
InvoiceFooter string `json:"invoice_footer,omitempty"`
VatRate float32 `json:"vat_rate,omitempty"`
DocumentLocale string `json:"document_locale,omitempty"`
}
type OrganizationBillingConfiguration struct {
InvoiceGracePeriod int `json:"invoice_grace_period,omitempty"`
InvoiceFooter string `json:"invoice_footer,omitempty"`
VatRate float32 `json:"vat_rate,omitempty"`
DocumentLocale string `json:"document_locale,omitempty"`
}
type OrganizationInput struct {
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
AddressLine1 string `json:"address_line1,omitempty"`
AddressLine2 string `json:"address_line2,omitempty"`
City string `json:"city,omitempty"`
Zipcode string `json:"zipcode,omitempty"`
State string `json:"state,omitempty"`
Country string `json:"country,omitempty"`
LegalName string `json:"legal_name,omitempty"`
LegalNumber string `json:"legal_number,omitempty"`
TaxIdentificationNumber string `json:"tax_identification_number,omitempty"`
WebhookURL string `json:"webhook_url,omitempty"`
Timezone string `json:"timezone,omitempty"`
EmailSettings []string `json:"email_settings,omitempty"`
BillingConfiguration OrganizationBillingConfigurationInput `json:"billing_configuration,omitempty"`
}
type OrganizationResult struct {
Organization *Organization `json:"organization,omitempty"`
}
type Organization struct {
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
AddressLine1 string `json:"address_line1,omitempty"`
AddressLine2 string `json:"address_line2,omitempty"`
City string `json:"city,omitempty"`
Zipcode string `json:"zipcode,omitempty"`
State string `json:"state,omitempty"`
Country string `json:"country,omitempty"`
LegalName string `json:"legal_name,omitempty"`
LegalNumber string `json:"legal_number,omitempty"`
TaxIdentificationNumber string `json:"tax_identification_number,omitempty"`
Timezone string `json:"timezone,omitempty"`
EmailSettings []string `json:"email_settings,omitempty"`
BillingConfiguration OrganizationBillingConfiguration `json:"billing_configuration,omitempty"`
Taxes []Tax `json:"taxes,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
}
func (c *Client) Organization() *OrganizationRequest {
return &OrganizationRequest{
client: c,
}
}
func (or *OrganizationRequest) Update(ctx context.Context, organizationInput *OrganizationInput) (*Organization, *Error) {
organizationParams := &OrganizationParams{
Organization: organizationInput,
}
clientRequest := &ClientRequest{
Path: "organizations",
Result: &OrganizationResult{},
Body: organizationParams,
}
result, err := or.client.Put(ctx, clientRequest)
if err != nil {
return nil, err
}
organizationResult, ok := result.(*OrganizationResult)
if !ok {
return nil, &ErrorTypeAssert
}
return organizationResult.Organization, nil
}