-
Notifications
You must be signed in to change notification settings - Fork 6
/
notification_type.go
113 lines (100 loc) · 5.08 KB
/
notification_type.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package apple
import (
"encoding/json"
"github.com/golang-jwt/jwt/v5"
)
// TestNotificationResponse https://developer.apple.com/documentation/appstoreserverapi/sendtestnotificationresponse
type TestNotificationResponse struct {
TestNotificationToken string `json:"testNotificationToken"`
}
// NotificationType https://developer.apple.com/documentation/appstoreservernotifications/notificationtype
type NotificationType string
const (
NotificationTypeConsumptionRequest NotificationType = "CONSUMPTION_REQUEST"
NotificationTypeDidChangeRenewalPref NotificationType = "DID_CHANGE_RENEWAL_PREF"
NotificationTypeDidChangeRenewalStatus NotificationType = "DID_CHANGE_RENEWAL_STATUS"
NotificationTypeDidFailToRenew NotificationType = "DID_FAIL_TO_RENEW"
NotificationTypeDidRenew NotificationType = "DID_RENEW"
NotificationTypeExpired NotificationType = "EXPIRED"
NotificationTypeGracePeriodExpired NotificationType = "GRACE_PERIOD_EXPIRED"
NotificationTypeOfferRedeemed NotificationType = "OFFER_REDEEMED"
NotificationTypePriceIncrease NotificationType = "PRICE_INCREASE"
NotificationTypeRefund NotificationType = "REFUND"
NotificationTypeRefundDeclined NotificationType = "REFUND_DECLINED"
NotificationTypeRefundReversed NotificationType = "REFUND_REVERSED"
NotificationTypeRenewalExtended NotificationType = "RENEWAL_EXTENDED"
NotificationTypeRenewalExtension NotificationType = "RENEWAL_EXTENSION"
NotificationTypeRevoke NotificationType = "REVOKE"
NotificationTypeSubscribed NotificationType = "SUBSCRIBED"
NotificationTypeTest NotificationType = "TEST"
)
// NotificationSubType https://developer.apple.com/documentation/appstoreservernotifications/subtype
type NotificationSubType string
const (
NotificationSubTypeAccept NotificationSubType = "ACCEPTED"
NotificationSubTypeAutoRenewDisabled NotificationSubType = "AUTO_RENEW_DISABLED"
NotificationSubTypeAutoRenewEnabled NotificationSubType = "AUTO_RENEW_ENABLED"
NotificationSubTypeBillingRecovery NotificationSubType = "BILLING_RECOVERY"
NotificationSubTypeBillingRetry NotificationSubType = "BILLING_RETRY"
NotificationSubTypeDowngrade NotificationSubType = "DOWNGRADE"
NotificationSubTypeFailure NotificationSubType = "FAILURE"
NotificationSubTypeGracePeriod NotificationSubType = "GRACE_PERIOD"
NotificationSubTypeInitialBuy NotificationSubType = "INITIAL_BUY"
NotificationSubTypePending NotificationSubType = "PENDING"
NotificationSubTypePriceIncrease NotificationSubType = "PRICE_INCREASE"
NotificationSubTypeProductNotForSale NotificationSubType = "PRODUCT_NOT_FOR_SALE"
NotificationSubTypeResubscribe NotificationSubType = "RESUBSCRIBE"
NotificationSubTypeSummary NotificationSubType = "SUMMARY"
NotificationSubTypeUpgrade NotificationSubType = "UPGRADE"
NotificationSubTypeVoluntary NotificationSubType = "VOLUNTARY"
)
// Notification https://developer.apple.com/documentation/appstoreservernotifications/responsebodyv2decodedpayload
type Notification struct {
jwt.RegisteredClaims
NotificationType NotificationType `json:"notificationType"`
Subtype NotificationSubType `json:"subtype"`
Data *NotificationData `json:"data"`
Summary *NotificationSummary `json:"summary"`
Version string `json:"version"`
SignedDate int64 `json:"signedDate"`
NotificationUUID string `json:"notificationUUID"`
}
type NotificationData struct {
AppAppleId int64 `json:"appAppleId"`
BundleId string `json:"bundleId"`
BundleVersion string `json:"bundleVersion"`
Environment Environment `json:"environment"`
Status int `json:"status"` // https://developer.apple.com/documentation/appstoreservernotifications/status
Renewal *Renewal `json:"renewal"`
Transaction *Transaction `json:"transaction"`
}
type NotificationDataAlias NotificationData
func (n *NotificationData) UnmarshalJSON(data []byte) (err error) {
var aux = struct {
*NotificationDataAlias
SignedRenewal SignedRenewal `json:"signedRenewalInfo"`
SignedTransaction SignedTransaction `json:"signedTransactionInfo"`
}{
NotificationDataAlias: (*NotificationDataAlias)(n),
}
if err = json.Unmarshal(data, &aux); err != nil {
return err
}
if n.Renewal, err = aux.SignedRenewal.Decode(); err != nil {
return err
}
if n.Transaction, err = aux.SignedTransaction.Decode(); err != nil {
return err
}
return nil
}
type NotificationSummary struct {
RequestIdentifier string `json:"requestIdentifier"`
Environment Environment `json:"environment"`
AppAppleId int64 `json:"appAppleId"`
BundleId string `json:"bundleId"`
ProductId string `json:"productId"`
StorefrontCountryCodes []string `json:"storefrontCountryCodes"`
FailedCount int64 `json:"failedCount"`
SucceededCount int64 `json:"succeededCount"`
}