This repository was archived by the owner on Nov 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathevent.go
More file actions
79 lines (75 loc) · 1.91 KB
/
event.go
File metadata and controls
79 lines (75 loc) · 1.91 KB
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
package stripe
import (
"encoding/json"
"net/url"
"strconv"
)
type Event struct {
Type string `json:"type"`
Data struct {
Object interface{} `json:"object"`
}
PendingWebhooks int `json:"pending_webhooks"`
LiveMode bool `json:"livemode"`
Created int64 `json:"created"`
ID string `json:"id"`
Object string `json:"object"`
Error *RawError `json:"error"`
}
func (stripe *Stripe) GetEvent(id string) (resp *Event, err error) {
r, err := stripe.request("GET", "events/"+id, "")
if err != nil {
return nil, err
}
err = json.Unmarshal(r, &resp)
if err != nil {
return nil, err
}
if resp.Error != nil {
//TODO: Throw an error
}
return
}
func (stripe *Stripe) ListEvents(event *Event, count, offset int, comparison string ) (resp []*Event, err error) {
values := make(url.Values)
if count >= 0 {
values.Set("count", strconv.Itoa(count))
}
if offset >= 0 {
values.Set("offset", strconv.Itoa(offset))
}
if event != nil {
if event.Type != "" {
values.Set("type", event.Type)
}
if event.Created > 0 && comparison != "" {
if comparison != "e" {
values.Set("created["+comparison+"]", strconv.FormatInt(event.Created, 10))
} else {
values.Set("created", strconv.FormatInt(event.Created, 10))
}
}
}
params := values.Encode()
if params != "" {
params = "?" + params
}
r, err := stripe.request("GET", "events"+params, "")
if err != nil {
return nil, err
}
var raw struct {
Count int "count"
Data []*Event "data"
Error *RawError "error"
}
err = json.Unmarshal(r, &raw)
if err != nil {
return nil, err
}
if raw.Error != nil {
// TODO: throw an error
}
resp = raw.Data
return
}