Skip to content

Commit 10be9f0

Browse files
authored
Merge pull request #210 from kaijietti/master
feat(appstore): add more server notification fields
2 parents 4e97308 + 7950571 commit 10be9f0

File tree

2 files changed

+70
-35
lines changed

2 files changed

+70
-35
lines changed

appstore/notification.go

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package appstore
33
// NotificationType is type
44
// https://developer.apple.com/documentation/appstoreservernotifications/notification_type
55
// https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Chapters/Subscriptions.html#//apple_ref/doc/uid/TP40008267-CH7-SW16
6+
// Deprecated
67
type NotificationType string
78

89
// list of NotificationType
@@ -86,6 +87,7 @@ type NotificationUnifiedReceipt struct {
8687

8788
// SubscriptionNotification is struct for
8889
// https://developer.apple.com/documentation/appstoreservernotifications/responsebodyv1
90+
// Deprecated
8991
type SubscriptionNotification struct {
9092
Environment NotificationEnvironment `json:"environment"`
9193
NotificationType NotificationType `json:"notification_type"`

appstore/notification_v2.go

+68-35
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ const (
1717
NotificationTypeV2PriceIncrease NotificationTypeV2 = "PRICE_INCREASE"
1818
NotificationTypeV2Refund NotificationTypeV2 = "REFUND"
1919
NotificationTypeV2RefundDeclined NotificationTypeV2 = "REFUND_DECLINED"
20+
NotificationTyp2V2RefundReversed NotificationTypeV2 = "REFUND_REVERSED"
2021
NotificationTypeV2RenewalExtended NotificationTypeV2 = "RENEWAL_EXTENDED"
22+
NotificationTypeV2RenewalExtension NotificationTypeV2 = "RENEWAL_EXTENSION"
2123
NotificationTypeV2Revoke NotificationTypeV2 = "REVOKE"
2224
NotificationTypeV2Subscribed NotificationTypeV2 = "SUBSCRIBED"
25+
NotificationTyp2V2Test NotificationTypeV2 = "TEST"
2326
)
2427

2528
// SubtypeV2 is type
@@ -28,19 +31,22 @@ type SubtypeV2 string
2831
// list of subtypes
2932
// https://developer.apple.com/documentation/appstoreservernotifications/subtype
3033
const (
31-
SubTypeV2InitialBuy = "INITIAL_BUY"
32-
SubTypeV2Resubscribe = "RESUBSCRIBE"
33-
SubTypeV2Downgrade = "DOWNGRADE"
34-
SubTypeV2Upgrade = "UPGRADE"
35-
SubTypeV2AutoRenewEnabled = "AUTO_RENEW_ENABLED"
34+
SubTypeV2Accepted = "ACCEPTED"
3635
SubTypeV2AutoRenewDisabled = "AUTO_RENEW_DISABLED"
37-
SubTypeV2Voluntary = "VOLUNTARY"
36+
SubTypeV2AutoRenewEnabled = "AUTO_RENEW_ENABLED"
37+
SubTypeV2BillingRecovery = "BILLING_RECOVERY"
3838
SubTypeV2BillingRetry = "BILLING_RETRY"
39-
SubTypeV2PriceIncrease = "PRICE_INCREASE"
39+
SubTypeV2Downgrade = "DOWNGRADE"
40+
SubTypeV2Failure = "FAILURE"
4041
SubTypeV2GracePeriod = "GRACE_PERIOD"
41-
SubTypeV2BillingRecovery = "BILLING_RECOVERY"
42+
SubTypeV2InitialBuy = "INITIAL_BUY"
4243
SubTypeV2Pending = "PENDING"
43-
SubTypeV2Accepted = "ACCEPTED"
44+
SubTypeV2PriceIncrease = "PRICE_INCREASE"
45+
SubTypeV2ProductNotForSale = "PRODUCT_NOT_FOR_SALE"
46+
SubTypeV2Resubscribe = "RESUBSCRIBE"
47+
SubTypeV2Summary = "SUMMARY"
48+
SubTypeV2Upgrade = "UPGRADE"
49+
SubTypeV2Voluntary = "VOLUNTARY"
4450
)
4551

4652
type AutoRenewStatus int
@@ -90,6 +96,28 @@ const (
9096
NonRenewable IAPType = "Non-Renewing Subscription"
9197
)
9298

99+
// AutoRenewableSubscriptionStatus status value is current as of the signedDate in the decoded payload, SubscriptionNotificationV2DecodedPayload.
100+
// https://developer.apple.com/documentation/appstoreservernotifications/status
101+
type AutoRenewableSubscriptionStatus int32
102+
103+
const (
104+
AutoRenewableSubscriptionStatusActive = iota + 1
105+
AutoRenewableSubscriptionStatusExpired
106+
AutoRenewableSubscriptionStatusBillingRetryPeriod
107+
AutoRenewableSubscriptionStatusBillingGracePeriod
108+
AutoRenewableSubscriptionStatusRevoked
109+
)
110+
111+
// TransactionReason indicates the cause of a purchase transaction,
112+
// which indicates whether it’s a customer’s purchase or a renewal for an auto-renewable subscription that the system initiates.
113+
// https://developer.apple.com/documentation/appstoreservernotifications/transactionreason
114+
type TransactionReason string
115+
116+
const (
117+
TransactionReasonPurchase = "PURCHASE"
118+
TransactionReasonRenewal = "RENEWAL"
119+
)
120+
93121
type (
94122
// SubscriptionNotificationV2 is struct for
95123
// https://developer.apple.com/documentation/appstoreservernotifications/responsebodyv2
@@ -131,12 +159,13 @@ type (
131159
// SubscriptionNotificationV2Data is struct
132160
// https://developer.apple.com/documentation/appstoreservernotifications/data
133161
SubscriptionNotificationV2Data struct {
134-
AppAppleID int `json:"appAppleId"`
135-
BundleID string `json:"bundleId"`
136-
BundleVersion string `json:"bundleVersion"`
137-
Environment string `json:"environment"`
138-
SignedRenewalInfo JWSRenewalInfo `json:"signedRenewalInfo"`
139-
SignedTransactionInfo JWSTransaction `json:"signedTransactionInfo"`
162+
AppAppleID int `json:"appAppleId"`
163+
BundleID string `json:"bundleId"`
164+
BundleVersion string `json:"bundleVersion"`
165+
Environment string `json:"environment"`
166+
SignedRenewalInfo JWSRenewalInfo `json:"signedRenewalInfo"`
167+
SignedTransactionInfo JWSTransaction `json:"signedTransactionInfo"`
168+
Status AutoRenewableSubscriptionStatus `json:"status"`
140169
}
141170

142171
// SubscriptionNotificationV2JWSDecodedHeader is struct
@@ -169,31 +198,35 @@ type (
169198
PriceIncreaseStatus PriceIncreaseStatus `json:"priceIncreaseStatus"`
170199
ProductId string `json:"productId"`
171200
RecentSubscriptionStartDate int64 `json:"recentSubscriptionStartDate"`
201+
RenewalDate int64 `json:"renewalDate"`
172202
SignedDate int64 `json:"signedDate"`
173203
}
174204

175205
// JWSTransactionDecodedPayload contains the decoded transaction information
176206
// https://developer.apple.com/documentation/appstoreservernotifications/jwstransactiondecodedpayload
177207
JWSTransactionDecodedPayload struct {
178-
AppAccountToken string `json:"appAccountToken"`
179-
BundleId string `json:"bundleId"`
180-
Environment Environment `json:"environment"`
181-
ExpiresDate int64 `json:"expiresDate"`
182-
InAppOwnershipType string `json:"inAppOwnershipType"`
183-
IsUpgraded bool `json:"isUpgraded"`
184-
OfferIdentifier string `json:"offerIdentifier"`
185-
OfferType OfferType `json:"offerType"`
186-
OriginalPurchaseDate int64 `json:"originalPurchaseDate"`
187-
OriginalTransactionId string `json:"originalTransactionId"`
188-
ProductId string `json:"productId"`
189-
PurchaseDate int64 `json:"purchaseDate"`
190-
Quantity int64 `json:"quantity"`
191-
RevocationDate int64 `json:"revocationDate"`
192-
RevocationReason RevocationReason `json:"revocationReason"`
193-
SignedDate int64 `json:"signedDate"`
194-
SubscriptionGroupIdentifier string `json:"subscriptionGroupIdentifier"`
195-
TransactionId string `json:"transactionId"`
196-
IAPtype IAPType `json:"type"`
197-
WebOrderLineItemId string `json:"webOrderLineItemId"`
208+
AppAccountToken string `json:"appAccountToken"`
209+
BundleId string `json:"bundleId"`
210+
Environment Environment `json:"environment"`
211+
ExpiresDate int64 `json:"expiresDate"`
212+
InAppOwnershipType string `json:"inAppOwnershipType"`
213+
IsUpgraded bool `json:"isUpgraded"`
214+
OfferIdentifier string `json:"offerIdentifier"`
215+
OfferType OfferType `json:"offerType"`
216+
OriginalPurchaseDate int64 `json:"originalPurchaseDate"`
217+
OriginalTransactionId string `json:"originalTransactionId"`
218+
ProductId string `json:"productId"`
219+
PurchaseDate int64 `json:"purchaseDate"`
220+
Quantity int64 `json:"quantity"`
221+
RevocationDate int64 `json:"revocationDate"`
222+
RevocationReason RevocationReason `json:"revocationReason"`
223+
SignedDate int64 `json:"signedDate"`
224+
Storefront string `json:"storefront"`
225+
StorefrontId string `json:"storefrontId"`
226+
SubscriptionGroupIdentifier string `json:"subscriptionGroupIdentifier"`
227+
TransactionId string `json:"transactionId"`
228+
TransactionReason TransactionReason `json:"transactionReason"`
229+
IAPtype IAPType `json:"type"`
230+
WebOrderLineItemId string `json:"webOrderLineItemId"`
198231
}
199232
)

0 commit comments

Comments
 (0)