-
Notifications
You must be signed in to change notification settings - Fork 6
/
event_type_value.go
82 lines (72 loc) · 2.24 KB
/
event_type_value.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
79
80
81
82
package revcatgo
import (
"errors"
"fmt"
"strings"
"gopkg.in/guregu/null.v4"
)
const (
EventTypeTest = "TEST"
EventTypeInitialPurchase = "INITIAL_PURCHASE"
EventTypeNonRenewingPurchase = "NON_RENEWING_PURCHASE"
EventTypeRenewal = "RENEWAL"
EventTypeProductChange = "PRODUCT_CHANGE"
EventTypeCancellation = "CANCELLATION"
EventTypeUnCancellation = "UNCANCELLATION"
EventTypeBillingIssue = "BILLING_ISSUE"
EventTypeSubscriberAlias = "SUBSCRIBER_ALIAS"
EventTypeSubscriptionPaused = "SUBSCRIPTION_PAUSED"
EventTypeTransfer = "TRANSFER"
EventTypeExpiration = "EXPIRATION"
EventTypeSubscriptionExtended = "SUBSCRIPTION_EXTENDED"
EventTypeTemporaryEntitlementGrant = "TEMPORARY_ENTITLEMENT_GRANT"
)
var validEventTypeValues = []string{
EventTypeTest,
EventTypeInitialPurchase,
EventTypeNonRenewingPurchase,
EventTypeRenewal,
EventTypeProductChange,
EventTypeCancellation,
EventTypeUnCancellation,
EventTypeBillingIssue,
EventTypeSubscriberAlias,
EventTypeSubscriptionPaused,
EventTypeTransfer,
EventTypeExpiration,
EventTypeSubscriptionExtended,
EventTypeTemporaryEntitlementGrant,
}
type eventType struct {
value null.String
}
func newEventType(s string) (*eventType, error) {
if !contains(validEventTypeValues, s) {
return &eventType{}, fmt.Errorf("eventType value should be one of the following: %v, got %v", strings.Join(validEventTypeValues, ", "), s)
}
return &eventType{value: null.StringFrom(s)}, nil
}
func (e eventType) String() string {
return e.value.ValueOrZero()
}
// MarshalJSON serializes a store to JSON.
func (e eventType) MarshalJSON() ([]byte, error) {
return e.value.MarshalJSON()
}
// UnmarshalJSON deserialized a store from JSON
func (e *eventType) UnmarshalJSON(b []byte) error {
v := &eventType{}
err := v.value.UnmarshalJSON(b)
if err != nil {
return fmt.Errorf("failed to unmarshal the value of type: %w", err)
}
if !v.value.Valid {
return errors.New("type is a required field")
}
_e, err := newEventType(v.value.ValueOrZero())
if err != nil {
return fmt.Errorf("failed to unmarshal the value of type: %w", err)
}
e.value = _e.value
return nil
}