Skip to content

Commit f075104

Browse files
authored
Merge pull request #155 from takecy/noti_v2
Add struct for v2 response of app store notification
2 parents 8f8b4c2 + 39661f1 commit f075104

File tree

6 files changed

+100
-4
lines changed

6 files changed

+100
-4
lines changed

.github/workflows/unit_test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
go: [ '1.15', '1.16' ]
14+
go: [ '1.15', '1.16', '1.17' ]
1515
name: Go ${{ matrix.go }} test
1616
steps:
1717
- uses: actions/checkout@v2

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ generate:
2525
update: update_all tidy
2626

2727
tidy:
28-
GO111MODULE=on GOPRIVATE="github.com/awa/*" go mod tidy
28+
GO111MODULE=on go mod tidy
2929

3030
update_all:
31-
GO111MODULE=on GOPRIVATE="github.com/awa/*" go get -v all
31+
GO111MODULE=on go get -v -u ./...

appstore/model.go

+6
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ func (n *numericString) UnmarshalJSON(b []byte) error {
1313
return nil
1414
}
1515

16+
// Environment is alias
1617
type Environment string
1718

19+
// list of Environment
1820
const (
1921
Sandbox Environment = "Sandbox"
2022
Production Environment = "Production"
2123
)
2224

2325
type (
26+
// IAPRequest is struct
2427
// https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html
2528
// The IAPRequest type has the request parameter
2629
IAPRequest struct {
@@ -140,6 +143,7 @@ type (
140143
PreorderDate
141144
}
142145

146+
// PendingRenewalInfo is struct
143147
// A pending renewal may refer to a renewal that is scheduled in the future or a renewal that failed in the past for some reason.
144148
PendingRenewalInfo struct {
145149
SubscriptionExpirationIntent string `json:"expiration_intent"`
@@ -169,6 +173,7 @@ type (
169173
IsRetryable bool `json:"is-retryable,omitempty"`
170174
}
171175

176+
// StatusResponse is struct
172177
// The HttpStatusResponse struct contains the status code returned by the store
173178
// Used as a workaround to detect when to hit the production appstore or sandbox appstore regardless of receipt type
174179
StatusResponse struct {
@@ -189,6 +194,7 @@ type (
189194
Status int `json:"status"`
190195
}
191196

197+
// ReceiptForIOS6 is struct
192198
ReceiptForIOS6 struct {
193199
AppItemID numericString `json:"app_item_id"`
194200
BID string `json:"bid"`

appstore/notification.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ const (
4545
NotificationProduction NotificationEnvironment = "PROD"
4646
)
4747

48+
// NotificationExpiresDate is struct
4849
type NotificationExpiresDate struct {
4950
ExpiresDateMS string `json:"expires_date"`
5051
ExpiresDateUTC string `json:"expires_date_formatted"`
5152
ExpiresDatePST string `json:"expires_date_formatted_pst"`
5253
}
5354

55+
// NotificationReceipt is struct
5456
type NotificationReceipt struct {
5557
UniqueIdentifier string `json:"unique_identifier"`
5658
AppItemID string `json:"app_item_id"`
@@ -73,6 +75,7 @@ type NotificationReceipt struct {
7375
CancellationDate
7476
}
7577

78+
// NotificationUnifiedReceipt is struct
7679
type NotificationUnifiedReceipt struct {
7780
Status int `json:"status"`
7881
Environment Environment `json:"environment"`
@@ -82,7 +85,7 @@ type NotificationUnifiedReceipt struct {
8285
}
8386

8487
// SubscriptionNotification is struct for
85-
// https://developer.apple.com/documentation/appstoreservernotifications/responsebody
88+
// https://developer.apple.com/documentation/appstoreservernotifications/responsebodyv1
8689
type SubscriptionNotification struct {
8790
Environment NotificationEnvironment `json:"environment"`
8891
NotificationType NotificationType `json:"notification_type"`

appstore/notification_v2.go

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package appstore
2+
3+
// NotificationTypeV2 is type
4+
type NotificationTypeV2 string
5+
6+
// list of notificationType
7+
// https://developer.apple.com/documentation/appstoreservernotifications/notificationtype
8+
const (
9+
NotificationTypeV2ConsumptionRequest NotificationTypeV2 = "CONSUMPTION_REQUEST"
10+
NotificationTypeV2DidChangeRenewalPref NotificationTypeV2 = "DID_CHANGE_RENEWAL_PREF"
11+
NotificationTypeV2DidChangeRenewalStatus NotificationTypeV2 = "DID_CHANGE_RENEWAL_STATUS"
12+
NotificationTypeV2DidFailToRenew NotificationTypeV2 = "DID_FAIL_TO_RENEW"
13+
NotificationTypeV2DidRenew NotificationTypeV2 = "DID_RENEW"
14+
NotificationTypeV2Expired NotificationTypeV2 = "EXPIRED"
15+
NotificationTypeV2GracePeriodExpired NotificationTypeV2 = "GRACE_PERIOD_EXPIRED"
16+
NotificationTypeV2OfferRedeemed NotificationTypeV2 = "OFFER_REDEEMED"
17+
NotificationTypeV2PriceIncrease NotificationTypeV2 = "PRICE_INCREASE"
18+
NotificationTypeV2Refund NotificationTypeV2 = "REFUND"
19+
NotificationTypeV2RefundDeclined NotificationTypeV2 = "REFUND_DECLINED"
20+
NotificationTypeV2RenewalExtended NotificationTypeV2 = "RENEWAL_EXTENDED"
21+
NotificationTypeV2Revoke NotificationTypeV2 = "REVOKE"
22+
NotificationTypeV2Subscribed NotificationTypeV2 = "SUBSCRIBED"
23+
)
24+
25+
// SubtypeV2 is type
26+
type SubtypeV2 string
27+
28+
// list of subtypes
29+
// https://developer.apple.com/documentation/appstoreservernotifications/subtype
30+
const (
31+
SubTypeV2InitialBuy = "INITIAL_BUY"
32+
SubTypeV2Resubscribe = "RESUBSCRIBE"
33+
SubTypeV2Downgrade = "DOWNGRADE"
34+
SubTypeV2Upgrade = "UPGRADE"
35+
SubTypeV2AutoRenewEnabled = "AUTO_RENEW_ENABLED"
36+
SubTypeV2AutoRenewDisabled = "AUTO_RENEW_DISABLED"
37+
SubTypeV2Voluntary = "VOLUNTARY"
38+
SubTypeV2BillingRetry = "BILLING_RETRY"
39+
SubTypeV2PriceIncrease = "PRICE_INCREASE"
40+
SubTypeV2GracePeriod = "GRACE_PERIOD"
41+
SubTypeV2BillingRecovery = "BILLING_RECOVERY"
42+
SubTypeV2Pending = "PENDING"
43+
SubTypeV2Accepted = "ACCEPTED"
44+
)
45+
46+
type (
47+
// SubscriptionNotificationV2 is struct for
48+
// https://developer.apple.com/documentation/appstoreservernotifications/responsebodyv2
49+
SubscriptionNotificationV2 struct {
50+
SignedPayload SubscriptionNotificationV2SignedPayload `json:"signedPayload"`
51+
}
52+
53+
// SubscriptionNotificationV2SignedPayload is struct
54+
// https://developer.apple.com/documentation/appstoreservernotifications/signedpayload
55+
SubscriptionNotificationV2SignedPayload struct {
56+
SignedPayload string `json:"signedPayload"`
57+
}
58+
59+
// SubscriptionNotificationV2DecodedPayload is struct
60+
// https://developer.apple.com/documentation/appstoreservernotifications/responsebodyv2decodedpayload
61+
SubscriptionNotificationV2DecodedPayload struct {
62+
NotificationType NotificationTypeV2 `json:"notificationType"`
63+
Subtype SubtypeV2 `json:"subtype"`
64+
NotificationUUID string `json:"notificationUUID"`
65+
NotificationVersion string `json:"notificationVersion"`
66+
Data SubscriptionNotificationV2Data `json:"data"`
67+
}
68+
69+
// SubscriptionNotificationV2Data is struct
70+
// https://developer.apple.com/documentation/appstoreservernotifications/data
71+
SubscriptionNotificationV2Data struct {
72+
AppAppleID int `json:"appAppleId"`
73+
BundleID string `json:"bundleId"`
74+
BundleVersion string `json:"bundleVersion"`
75+
Environment string `json:"environment"`
76+
SignedRenewalInfo string `json:"signedRenewalInfo"`
77+
SignedTransactionInfo string `json:"signedTransactionInfo"`
78+
}
79+
80+
// SubscriptionNotificationV2JWSDecodedHeader is struct
81+
SubscriptionNotificationV2JWSDecodedHeader struct {
82+
Alg string `json:"alg"`
83+
Kid string `json:"kid"`
84+
X5c []string `json:"x5c"`
85+
}
86+
)

appstore/validator.go

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Client struct {
3434
httpCli *http.Client
3535
}
3636

37+
// list of errore
3738
var (
3839
ErrAppStoreServer = errors.New("AppStore server error")
3940

0 commit comments

Comments
 (0)