forked from getlago/lago-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.go
78 lines (62 loc) · 1.96 KB
/
event.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package lago
import "context"
type EventRequest struct {
client *Client
}
type EventParams struct {
Event *EventInput `json:"event"`
}
type EventInput struct {
TransactionID string `json:"transaction_id,omitempty"`
ExternalCustomerID string `json:"external_customer_id,omitempty"`
ExternalSubscriptionID string `json:"external_subscription_id,omitempty"`
Code string `json:"code,omitempty"`
Timestamp int64 `json:"timestamp,omitempty"`
Properties map[string]interface{} `json:"properties,omitempty"`
}
type EventEstimateFeesParams struct {
Event *EventEstimateFeesInput `json:"event"`
}
type EventEstimateFeesInput struct {
ExternalCustomerID string `json:"external_customer_id,omitempty"`
ExternalSubscriptionID string `json:"external_subscription_id,omitempty"`
Code string `json:"code,omitempty"`
Properties map[string]string `json:"properties,omitempty"`
}
func (c *Client) Event() *EventRequest {
return &EventRequest{
client: c,
}
}
func (er *EventRequest) Create(ctx context.Context, eventInput *EventInput) *Error {
eventParams := &EventParams{
Event: eventInput,
}
clientRequest := &ClientRequest{
Path: "events",
Body: eventParams,
}
err := er.client.PostWithoutResult(ctx, clientRequest)
if err != nil {
return err
}
return nil
}
func (er *EventRequest) EstimateFees(ctx context.Context, estimateInput EventEstimateFeesInput) (*FeeResult, *Error) {
eventEstimateParams := &EventEstimateFeesParams{
Event: &estimateInput,
}
clientRequest := &ClientRequest{
Path: "events/estimate_fees",
Body: eventEstimateParams,
}
result, clientErr := er.client.Post(ctx, clientRequest)
if clientErr != nil {
return nil, clientErr
}
feeResult, ok := result.(*FeeResult)
if !ok {
return nil, &ErrorTypeAssert
}
return feeResult, nil
}