Skip to content

Commit 057cf9a

Browse files
authored
Merge pull request #215 from richzw/master
feat(appstore): add more fields to request/response structs of app store server api
2 parents c1296f3 + 0827129 commit 057cf9a

File tree

2 files changed

+72
-31
lines changed

2 files changed

+72
-31
lines changed

appstore/api/model.go

+61-28
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,30 @@ type OrderLookupResponse struct {
88
SignedTransactions []string `json:"signedTransactions"`
99
}
1010

11+
type Environment string
12+
13+
// Environment https://developer.apple.com/documentation/appstoreserverapi/environment
14+
const (
15+
Sandbox Environment = "Sandbox"
16+
Production Environment = "Production"
17+
)
18+
1119
// HistoryResponse https://developer.apple.com/documentation/appstoreserverapi/historyresponse
1220
type HistoryResponse struct {
13-
AppAppleId int `json:"appAppleId"`
14-
BundleId string `json:"bundleId"`
15-
Environment string `json:"environment"`
16-
HasMore bool `json:"hasMore"`
17-
Revision string `json:"revision"`
18-
SignedTransactions []string `json:"signedTransactions"`
21+
AppAppleId int64 `json:"appAppleId"`
22+
BundleId string `json:"bundleId"`
23+
Environment Environment `json:"environment"`
24+
HasMore bool `json:"hasMore"`
25+
Revision string `json:"revision"`
26+
SignedTransactions []string `json:"signedTransactions"`
1927
}
2028

2129
// TransactionInfoResponse https://developer.apple.com/documentation/appstoreserverapi/transactioninforesponse
2230
type TransactionInfoResponse struct {
2331
SignedTransactionInfo string `json:"signedTransactionInfo"`
2432
}
2533

26-
// RefundLookupResponse https://developer.apple.com/documentation/appstoreserverapi/refundlookupresponse
34+
// RefundLookupResponse same as the RefundHistoryResponse https://developer.apple.com/documentation/appstoreserverapi/refundhistoryresponse
2735
type RefundLookupResponse struct {
2836
HasMore bool `json:"hasMore"`
2937
Revision string `json:"revision"`
@@ -32,8 +40,8 @@ type RefundLookupResponse struct {
3240

3341
// StatusResponse https://developer.apple.com/documentation/appstoreserverapi/get_all_subscription_statuses
3442
type StatusResponse struct {
35-
Environment string `json:"environment"`
36-
AppAppleId int `json:"appAppleId"`
43+
Environment Environment `json:"environment"`
44+
AppAppleId int64 `json:"appAppleId"`
3745
BundleId string `json:"bundleId"`
3846
Data []SubscriptionGroupIdentifierItem `json:"data"`
3947
}
@@ -45,36 +53,51 @@ type SubscriptionGroupIdentifierItem struct {
4553

4654
type LastTransactionsItem struct {
4755
OriginalTransactionId string `json:"originalTransactionId"`
48-
Status int `json:"status"`
56+
Status int32 `json:"status"`
4957
SignedRenewalInfo string `json:"signedRenewalInfo"`
5058
SignedTransactionInfo string `json:"signedTransactionInfo"`
5159
}
5260

5361
// MassExtendRenewalDateRequest https://developer.apple.com/documentation/appstoreserverapi/massextendrenewaldaterequest
5462
type MassExtendRenewalDateRequest struct {
5563
RequestIdentifier string `json:"requestIdentifier"`
56-
ExtendByDays int `json:"extendByDays"`
57-
ExtendReasonCode int `json:"extendReasonCode"`
64+
ExtendByDays int32 `json:"extendByDays"`
65+
ExtendReasonCode int32 `json:"extendReasonCode"`
5866
ProductId string `json:"productId"`
5967
StorefrontCountryCodes []string `json:"storefrontCountryCodes"`
6068
}
6169

6270
// ConsumptionRequestBody https://developer.apple.com/documentation/appstoreserverapi/consumptionrequest
6371
type ConsumptionRequestBody struct {
64-
AccountTenure int `json:"accountTenure"`
72+
AccountTenure int32 `json:"accountTenure"`
6573
AppAccountToken string `json:"appAccountToken"`
66-
ConsumptionStatus int `json:"consumptionStatus"`
74+
ConsumptionStatus int32 `json:"consumptionStatus"`
6775
CustomerConsented bool `json:"customerConsented"`
68-
DeliveryStatus int `json:"deliveryStatus"`
69-
LifetimeDollarsPurchased int `json:"lifetimeDollarsPurchased"`
70-
LifetimeDollarsRefunded int `json:"lifetimeDollarsRefunded"`
71-
Platform int `json:"platform"`
72-
PlayTime int `json:"playTime"`
76+
DeliveryStatus int32 `json:"deliveryStatus"`
77+
LifetimeDollarsPurchased int32 `json:"lifetimeDollarsPurchased"`
78+
LifetimeDollarsRefunded int32 `json:"lifetimeDollarsRefunded"`
79+
Platform int32 `json:"platform"`
80+
PlayTime int32 `json:"playTime"`
7381
SampleContentProvided bool `json:"sampleContentProvided"`
74-
UserStatus int `json:"userStatus"`
82+
UserStatus int32 `json:"userStatus"`
7583
}
7684

85+
// JWSRenewalInfoDecodedPayload https://developer.apple.com/documentation/appstoreserverapi/jwsrenewalinfodecodedpayload
7786
type JWSRenewalInfoDecodedPayload struct {
87+
AutoRenewProductId string `json:"autoRenewProductId"`
88+
AutoRenewStatus int32 `json:"autoRenewStatus"`
89+
Environment Environment `json:"environment"`
90+
ExpirationIntent int32 `json:"expirationIntent"`
91+
GracePeriodExpiresDate int64 `json:"gracePeriodExpiresDate"`
92+
IsInBillingRetryPeriod bool `json:"isInBillingRetryPeriod"`
93+
OfferIdentifier string `json:"offerIdentifier"`
94+
OfferType string `json:"offerType"`
95+
OriginalTransactionId string `json:"originalTransactionId"`
96+
PriceIncreaseStatus int32 `json:"priceIncreaseStatus"`
97+
ProductId string `json:"productId"`
98+
RecentSubscriptionStartDate int64 `json:"recentSubscriptionStartDate"`
99+
RenewalDate int64 `json:"renewalDate"`
100+
SignedDate int64 `json:"signedDate"`
78101
}
79102

80103
// JWSDecodedHeader https://developer.apple.com/documentation/appstoreserverapi/jwsdecodedheader
@@ -114,27 +137,28 @@ type JWSTransaction struct {
114137
PurchaseDate int64 `json:"purchaseDate,omitempty"`
115138
OriginalPurchaseDate int64 `json:"originalPurchaseDate,omitempty"`
116139
ExpiresDate int64 `json:"expiresDate,omitempty"`
117-
Quantity int64 `json:"quantity,omitempty"`
140+
Quantity int32 `json:"quantity,omitempty"`
118141
Type IAPType `json:"type,omitempty"`
119142
AppAccountToken string `json:"appAccountToken,omitempty"`
120143
InAppOwnershipType string `json:"inAppOwnershipType,omitempty"`
121144
SignedDate int64 `json:"signedDate,omitempty"`
122-
OfferType int64 `json:"offerType,omitempty"`
145+
OfferType int32 `json:"offerType,omitempty"`
123146
OfferIdentifier string `json:"offerIdentifier,omitempty"`
124147
RevocationDate int64 `json:"revocationDate,omitempty"`
125-
RevocationReason int `json:"revocationReason,omitempty"`
148+
RevocationReason int32 `json:"revocationReason,omitempty"`
126149
IsUpgraded bool `json:"isUpgraded,omitempty"`
127-
Storefront string `json:"storefront"`
128-
StorefrontId string `json:"storefrontId"`
129-
TransactionReason TransactionReason `json:"transactionReason"`
150+
Storefront string `json:"storefront,omitempty"`
151+
StorefrontId string `json:"storefrontId,omitempty"`
152+
TransactionReason TransactionReason `json:"transactionReason,omitempty"`
153+
Environment Environment `json:"environment,omitempty"`
130154
}
131155

132156
func (J JWSTransaction) Valid() error {
133157
return nil
134158
}
135159

136160
// https://developer.apple.com/documentation/appstoreserverapi/extendreasoncode
137-
type ExtendReasonCode int
161+
type ExtendReasonCode int32
138162

139163
const (
140164
UndeclaredExtendReasonCode = iota
@@ -145,11 +169,20 @@ const (
145169

146170
// ExtendRenewalDateRequest https://developer.apple.com/documentation/appstoreserverapi/extendrenewaldaterequest
147171
type ExtendRenewalDateRequest struct {
148-
ExtendByDays int `json:"extendByDays"`
172+
ExtendByDays int32 `json:"extendByDays"`
149173
ExtendReasonCode ExtendReasonCode `json:"extendReasonCode"`
150174
RequestIdentifier string `json:"requestIdentifier"`
151175
}
152176

177+
// MassExtendRenewalDateStatusResponse https://developer.apple.com/documentation/appstoreserverapi/massextendrenewaldatestatusresponse
178+
type MassExtendRenewalDateStatusResponse struct {
179+
RequestIdentifier string `json:"requestIdentifier"`
180+
Complete bool `json:"complete"`
181+
CompleteDate int64 `json:"completeDate,omitempty"`
182+
FailedCount int64 `json:"failedCount,omitempty"`
183+
SucceededCount int64 `json:"succeededCount,omitempty"`
184+
}
185+
153186
// NotificationHistoryRequest https://developer.apple.com/documentation/appstoreserverapi/notificationhistoryrequest
154187
type NotificationHistoryRequest struct {
155188
StartDate int64 `json:"startDate"`

appstore/api/store.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -301,17 +301,25 @@ func (a *StoreClient) ExtendSubscriptionRenewalDateForAll(ctx context.Context, b
301301
}
302302

303303
// GetSubscriptionRenewalDataStatus https://developer.apple.com/documentation/appstoreserverapi/get_status_of_subscription_renewal_date_extensions
304-
func (a *StoreClient) GetSubscriptionRenewalDataStatus(ctx context.Context, productId, requestIdentifier string) (statusCode int, err error) {
304+
func (a *StoreClient) GetSubscriptionRenewalDataStatus(ctx context.Context, productId, requestIdentifier string) (statusCode int, rsp *MassExtendRenewalDateStatusResponse, err error) {
305305
URL := HostProduction + PathGetStatusOfSubscriptionRenewalDate
306306
if a.Token.Sandbox {
307307
URL = HostSandBox + PathGetStatusOfSubscriptionRenewalDate
308308
}
309309
URL = strings.Replace(URL, "{productId}", productId, -1)
310310
URL = strings.Replace(URL, "{requestIdentifier}", requestIdentifier, -1)
311311

312-
statusCode, _, err = a.Do(ctx, http.MethodGet, URL, nil)
312+
statusCode, body, err := a.Do(ctx, http.MethodGet, URL, nil)
313+
if statusCode != http.StatusOK {
314+
return statusCode, nil, fmt.Errorf("appstore api: %v return status code %v", URL, statusCode)
315+
}
313316

314-
return statusCode, nil
317+
err = json.Unmarshal(body, &rsp)
318+
if err != nil {
319+
return statusCode, nil, err
320+
}
321+
322+
return statusCode, rsp, nil
315323
}
316324

317325
// GetNotificationHistory https://developer.apple.com/documentation/appstoreserverapi/get_notification_history

0 commit comments

Comments
 (0)