-
Notifications
You must be signed in to change notification settings - Fork 244
/
notification_v2.go
250 lines (217 loc) · 10.9 KB
/
notification_v2.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
package appstore
import "github.com/golang-jwt/jwt/v4"
// NotificationTypeV2 is type
type NotificationTypeV2 string
// list of notificationType
// https://developer.apple.com/documentation/appstoreservernotifications/notificationtype
const (
NotificationTypeV2ConsumptionRequest NotificationTypeV2 = "CONSUMPTION_REQUEST"
NotificationTypeV2DidChangeRenewalPref NotificationTypeV2 = "DID_CHANGE_RENEWAL_PREF"
NotificationTypeV2DidChangeRenewalStatus NotificationTypeV2 = "DID_CHANGE_RENEWAL_STATUS"
NotificationTypeV2DidFailToRenew NotificationTypeV2 = "DID_FAIL_TO_RENEW"
NotificationTypeV2DidRenew NotificationTypeV2 = "DID_RENEW"
NotificationTypeV2Expired NotificationTypeV2 = "EXPIRED"
NotificationTypeV2ExternalPurchaseToken NotificationTypeV2 = "EXTERNAL_PURCHASE_TOKEN"
NotificationTypeV2GracePeriodExpired NotificationTypeV2 = "GRACE_PERIOD_EXPIRED"
NotificationTypeV2OfferRedeemed NotificationTypeV2 = "OFFER_REDEEMED"
NotificationTypeV2PriceIncrease NotificationTypeV2 = "PRICE_INCREASE"
NotificationTypeV2Refund NotificationTypeV2 = "REFUND"
NotificationTypeV2RefundDeclined NotificationTypeV2 = "REFUND_DECLINED"
NotificationTypeV2RefundReversed NotificationTypeV2 = "REFUND_REVERSED"
NotificationTypeV2RenewalExtended NotificationTypeV2 = "RENEWAL_EXTENDED"
NotificationTypeV2RenewalExtension NotificationTypeV2 = "RENEWAL_EXTENSION"
NotificationTypeV2Revoke NotificationTypeV2 = "REVOKE"
NotificationTypeV2Subscribed NotificationTypeV2 = "SUBSCRIBED"
NotificationTypeV2Test NotificationTypeV2 = "TEST"
)
// SubtypeV2 is type
type SubtypeV2 string
// list of subtypes
// https://developer.apple.com/documentation/appstoreservernotifications/subtype
const (
SubTypeV2Accepted = "ACCEPTED"
SubTypeV2AutoRenewDisabled = "AUTO_RENEW_DISABLED"
SubTypeV2AutoRenewEnabled = "AUTO_RENEW_ENABLED"
SubTypeV2BillingRecovery = "BILLING_RECOVERY"
SubTypeV2BillingRetry = "BILLING_RETRY"
SubTypeV2Downgrade = "DOWNGRADE"
SubTypeV2Failure = "FAILURE"
SubTypeV2GracePeriod = "GRACE_PERIOD"
SubTypeV2InitialBuy = "INITIAL_BUY"
SubTypeV2Pending = "PENDING"
SubTypeV2PriceIncrease = "PRICE_INCREASE"
SubTypeV2ProductNotForSale = "PRODUCT_NOT_FOR_SALE"
SubTypeV2Resubscribe = "RESUBSCRIBE"
SubTypeV2Summary = "SUMMARY"
SubTypeV2Upgrade = "UPGRADE"
SubTypeV2Unreported = "UNREPORTED"
SubTypeV2Voluntary = "VOLUNTARY"
)
type AutoRenewStatus int
const (
Off AutoRenewStatus = iota
On
)
type ExpirationIntent int
const (
CustomerCancelled ExpirationIntent = iota + 1
BillingError
NoPriceChangeConsent
ProductUnavailable
)
type OfferType int
const (
IntroductoryOffer OfferType = iota + 1
PromotionalOffer
SubscriptionOfferCode
)
type PriceIncreaseStatus int
const (
CustomerNotYetConsented PriceIncreaseStatus = iota
CustomerConsented
)
type RevocationReason int
const (
OtherReason RevocationReason = iota
AppIssue
)
type IAPType string
const (
AutoRenewable IAPType = "Auto-Renewable Subscription"
NonConsumable IAPType = "Non-Consumable"
Consumable IAPType = "Consumable"
NonRenewable IAPType = "Non-Renewing Subscription"
)
// AutoRenewableSubscriptionStatus status value is current as of the signedDate in the decoded payload, SubscriptionNotificationV2DecodedPayload.
// https://developer.apple.com/documentation/appstoreservernotifications/status
type AutoRenewableSubscriptionStatus int32
const (
AutoRenewableSubscriptionStatusActive = iota + 1
AutoRenewableSubscriptionStatusExpired
AutoRenewableSubscriptionStatusBillingRetryPeriod
AutoRenewableSubscriptionStatusBillingGracePeriod
AutoRenewableSubscriptionStatusRevoked
)
// TransactionReason indicates the cause of a purchase transaction,
// which indicates whether it’s a customer’s purchase or a renewal for an auto-renewable subscription that the system initiates.
// https://developer.apple.com/documentation/appstoreservernotifications/transactionreason
type TransactionReason string
const (
TransactionReasonPurchase = "PURCHASE"
TransactionReasonRenewal = "RENEWAL"
)
type OfferDiscountType string
const (
OfferDiscountTypeFreeTrial OfferDiscountType = "FREE_TRIAL"
OfferDiscountTypePayAsYouGo OfferDiscountType = "PAY_AS_YOU_GO"
OfferDiscountTypePayUpFront OfferDiscountType = "PAY_UP_FRONT"
)
type (
// SubscriptionNotificationV2 is struct for
// https://developer.apple.com/documentation/appstoreservernotifications/responsebodyv2
SubscriptionNotificationV2 struct {
SignedPayload SubscriptionNotificationV2SignedPayload `json:"signedPayload"`
}
// SubscriptionNotificationV2SignedPayload is struct
// https://developer.apple.com/documentation/appstoreservernotifications/signedpayload
SubscriptionNotificationV2SignedPayload struct {
SignedPayload string `json:"signedPayload"`
}
// SubscriptionNotificationV2DecodedPayload is struct
// https://developer.apple.com/documentation/appstoreservernotifications/responsebodyv2decodedpayload
SubscriptionNotificationV2DecodedPayload struct {
NotificationType NotificationTypeV2 `json:"notificationType"`
Subtype SubtypeV2 `json:"subtype"`
NotificationUUID string `json:"notificationUUID"`
NotificationVersion string `json:"version"`
SignedDate int64 `json:"signedDate"`
Data SubscriptionNotificationV2Data `json:"data,omitempty"`
Summary SubscriptionNotificationV2Summary `json:"summary,omitempty"`
jwt.RegisteredClaims
}
// SubscriptionNotificationV2Summary is struct
// https://developer.apple.com/documentation/appstoreservernotifications/summary
SubscriptionNotificationV2Summary struct {
RequestIdentifier string `json:"requestIdentifier"`
Environment string `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"`
}
// SubscriptionNotificationV2Data is struct
// https://developer.apple.com/documentation/appstoreservernotifications/data
SubscriptionNotificationV2Data struct {
AppAppleID int `json:"appAppleId"`
BundleID string `json:"bundleId"`
BundleVersion string `json:"bundleVersion"`
Environment string `json:"environment"`
SignedRenewalInfo JWSRenewalInfo `json:"signedRenewalInfo"`
SignedTransactionInfo JWSTransaction `json:"signedTransactionInfo"`
Status AutoRenewableSubscriptionStatus `json:"status"`
}
// SubscriptionNotificationV2JWSDecodedHeader is struct
SubscriptionNotificationV2JWSDecodedHeader struct {
Alg string `json:"alg"`
Kid string `json:"kid"`
X5c []string `json:"x5c"`
}
// JWSRenewalInfo contains the Base64 encoded signed JWS payload of the renewal information
// https://developer.apple.com/documentation/appstoreservernotifications/jwsrenewalinfo
JWSRenewalInfo string
// JWSTransaction contains the Base64 encoded signed JWS payload of the transaction
// https://developer.apple.com/documentation/appstoreservernotifications/jwstransaction
JWSTransaction string
// JWSRenewalInfoDecodedPayload contains the decoded renewal information
// https://developer.apple.com/documentation/appstoreservernotifications/jwsrenewalinfodecodedpayload
JWSRenewalInfoDecodedPayload struct {
AutoRenewProductId string `json:"autoRenewProductId"`
AutoRenewStatus AutoRenewStatus `json:"autoRenewStatus"`
Environment Environment `json:"environment"`
ExpirationIntent ExpirationIntent `json:"expirationIntent"`
GracePeriodExpiresDate int64 `json:"gracePeriodExpiresDate"`
IsInBillingRetryPeriod bool `json:"isInBillingRetryPeriod"`
OfferIdentifier string `json:"offerIdentifier"`
OfferType OfferType `json:"offerType"`
OriginalTransactionId string `json:"originalTransactionId"`
PriceIncreaseStatus PriceIncreaseStatus `json:"priceIncreaseStatus"`
ProductId string `json:"productId"`
RecentSubscriptionStartDate int64 `json:"recentSubscriptionStartDate"`
RenewalDate int64 `json:"renewalDate"`
SignedDate int64 `json:"signedDate"`
jwt.RegisteredClaims
}
// JWSTransactionDecodedPayload contains the decoded transaction information
// https://developer.apple.com/documentation/appstoreservernotifications/jwstransactiondecodedpayload
JWSTransactionDecodedPayload struct {
AppAccountToken string `json:"appAccountToken"`
BundleId string `json:"bundleId"`
Currency string `json:"currency,omitempty"`
Environment Environment `json:"environment"`
ExpiresDate int64 `json:"expiresDate"`
InAppOwnershipType string `json:"inAppOwnershipType"`
IsUpgraded bool `json:"isUpgraded"`
OfferDiscountType OfferDiscountType `json:"offerDiscountType"`
OfferIdentifier string `json:"offerIdentifier"`
OfferType OfferType `json:"offerType"`
OriginalPurchaseDate int64 `json:"originalPurchaseDate"`
OriginalTransactionId string `json:"originalTransactionId"`
Price int64 `json:"price,omitempty"`
ProductId string `json:"productId"`
PurchaseDate int64 `json:"purchaseDate"`
Quantity int64 `json:"quantity"`
RevocationDate int64 `json:"revocationDate"`
RevocationReason RevocationReason `json:"revocationReason"`
SignedDate int64 `json:"signedDate"`
Storefront string `json:"storefront"`
StorefrontId string `json:"storefrontId"`
SubscriptionGroupIdentifier string `json:"subscriptionGroupIdentifier"`
TransactionId string `json:"transactionId"`
TransactionReason TransactionReason `json:"transactionReason"`
IAPtype IAPType `json:"type"`
WebOrderLineItemId string `json:"webOrderLineItemId"`
jwt.RegisteredClaims
}
)