-
Notifications
You must be signed in to change notification settings - Fork 0
/
product.go
59 lines (49 loc) · 1.29 KB
/
product.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
package sendowl
import (
"encoding/json"
"fmt"
"strconv"
)
type ProductType string
const (
Digital ProductType = "digital"
)
type ProductID int
// UnmarshalJSON implements the json.Unmarshaler interface.
func (id *ProductID) UnmarshalJSON(data []byte) error {
var i int64
if err := json.Unmarshal(data, &i); err != nil {
return fmt.Errorf("sendowl: ProductID should be an int64, got %T: %v", data, data)
}
*id = ProductIDFromInt(i)
return nil
}
func (id ProductID) String() string {
return strconv.Itoa(int(id))
}
func (id ProductID) Int() int64 {
return int64(id)
}
func ProductIDFromString(s string) ProductID {
i, _ := strconv.Atoi(s)
return ProductID(i)
}
func ProductIDFromInt(i int64) ProductID {
return ProductID(i)
}
type Product struct {
// ID of the product.
ID ProductID `json:"id"`
// Name of the product.
Name string `json:"name"`
// Type of the product.
Type ProductType `json:"product_type"`
// Price of the product (in dollars and cents).
Price Price `json:"price"`
// InstantBuyURL for purchasing the product.
InstantBuyURL string `json:"instant_buy_url"`
PDFStamping bool `json:"pdf_stamping"`
// SelfHostedURL is the url of the file to be issued at download (only
// useable when the product is self hosted).
SelfHostedURL string `json:"self_hosted_url"`
}