-
Notifications
You must be signed in to change notification settings - Fork 0
/
invoice.go
48 lines (42 loc) · 1.53 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
package hc
import "fmt"
// Invoice object specifies the list of items to display
// on the invoice page. When the invoice is created, your
// application receives an invoice token and a checkout URL
// for a customer to make payment.
type Invoice struct {
Items map[string]*Item `json:"items,omitempty"`
Taxes map[string]*Tax `json:"taxes,omitempty"`
TotalAmount float64 `json:"total_amount,omitempty"`
Description string `json:"description,omitempty"`
}
// AddItem Is used for adding invoice items to the checkout invoice page.
func (i *Invoice) AddItem(name string, quantity int, unitPrice, totalPrice float64, description string) {
i.Items[fmt.Sprintf("item_%d", len(i.Items))] = &Item{
Name: name,
Quantity: quantity,
UnitPrice: unitPrice,
TotalPrice: totalPrice,
Description: description,
}
}
// Item specifies a single item on the checkout page.
type Item struct {
Name string `json:"name,omitempty"`
Quantity int `json:"quantity,omitempty"`
UnitPrice float64 `json:"unit_price,omitempty"`
TotalPrice float64 `json:"total_price,omitempty"`
Description string `json:"description,omitempty"`
}
// Tax specifies the tax items that apply to the invoice.
type Tax struct {
Name string `json:"name,omitempty"`
Amount float64 `json:"amount,omitempty"`
}
// AddTax is used for adding tax items to the checkout invoice page.
func (i *Invoice) AddTax(name string, amount float64) {
i.Taxes[fmt.Sprintf("tax_%d", len(i.Taxes))] = &Tax{
Name: name,
Amount: amount,
}
}