-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinvoice.go
59 lines (51 loc) · 1.63 KB
/
invoice.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
package gorecurly
import (
"encoding/xml"
"errors"
"time"
)
//Invoice object
type Invoice struct {
XMLName xml.Name `xml:"invoice"`
endpoint string
r *Recurly
Account *AccountStub `xml:"account,omitempty"`
UUID string `xml:"uuid,omitempty"`
State string `xml:"state,omitempty"`
InvoiceNumber string `xml:"invoice_number,omitempty"`
PONumber string `xml:"po_number,omitempty"`
VATNumber string `xml:"vat_number,omitempty"`
SubtotalInCents int `xml:"subtotal_in_cents,omitempty"`
TaxInCents int `xml:"tax_in_cents,omitempty"`
TotalInCents int `xml:"total_in_cents,omitempty"`
Currency string `xml:"currency,omitempty"`
CreatedAt *time.Time `xml:"created_at,omitempty"`
LineItems []LineItems `xml:"line_items,omitempty"`
//Transactions []Transaction `xml:"transactions,omitempty"`
}
//Invoice any pending charges given an acount code
func (i *Invoice) InvoicePendingCharges(account_code string) error {
_, err := i.r.createRequest(ACCOUNTS + "/" + account_code + "/invoices", "POST", nil, nil)
return err
}
//Mark an invoice as successfully paid
func (i *Invoice) MarkSuccessful() error {
if i.UUID == "" {
return errors.New("Not a valid invoice")
}
_, err := i.r.createRequest(INVOICES + "/" + i.InvoiceNumber + "/mark_successful", "PUT", nil, nil)
return err
}
//Mark an invoice as failed
func (i *Invoice) MarkFailed() error {
if i.UUID == "" {
return errors.New("Not a valid invoice")
}
_, err := i.r.createRequest(INVOICES + "/" + i.InvoiceNumber + "/mark_failed", "PUT", nil, nil)
return err
}
//Listing of line items in a transaction
type LineItems struct {
XMLName xml.Name `xml:"line_items"`
Adjustment []Adjustment
}