-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathadjustments.go
50 lines (45 loc) · 1.68 KB
/
adjustments.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
package gorecurly
import (
"encoding/xml"
"errors"
"time"
)
//Adjustment struct
type Adjustment struct {
XMLName xml.Name `xml:"adjustment"`
endpoint string
r *Recurly
Type string `xml:"type,attr"`
AccountCode string `xml:"-"`
Account *AccountStub `xml:"account,omitempty"`
UUID string `xml:"uuid,omitempty"`
Description string `xml:"description,omitempty"`
AccountingCode string `xml:"accounting_code,omitempty"`
Origin string `xml:"origin,omitempty"`
UnitAmountInCents int `xml:"unit_amount_in_cents,omitempty"`
Quantity int `xml:"quantity,omitempty"`
DiscountInCents int `xml:"discount_in_cents,omitempty"`
TaxInCents int `xml:"tax_in_cents,omitempty"`
Currency string `xml:"currency,omitempty"`
Taxable bool `xml:"taxable,omitempty"`
StartDate *time.Time `xml:"start_date,omitempty"`
EndDate RecurlyDate `xml:"end_date,omitempty"`
CreatedAt *time.Time `xml:"created_at,omitempty"`
}
//Create a new adjustment and load updated fields
func (a *Adjustment) Create() error {
if a.UUID != "" {
return RecurlyError{statusCode: 400, Description: "Adjustment Already created"}
}
return a.r.doCreate(&a, ACCOUNTS+"/"+a.AccountCode+"/"+a.endpoint)
}
//Delete an adjustment
func (a *Adjustment) Delete() error {
return a.r.doDelete(a.endpoint + "/" + a.UUID)
}
func (a *Adjustment) GetAccount() (Account, error) {
if a.Account == nil {
return Account{}, errors.New("Account Stub is nil")
}
return a.r.GetAccount(a.Account.GetCode())
}