Skip to content

Commit 634fc34

Browse files
committed
feat(api): add ExtendSubscriptionRenewalDateForAll and GetStatusOfSubscriptionRenewalDate
1 parent 7aa21f8 commit 634fc34

File tree

1 file changed

+58
-10
lines changed

1 file changed

+58
-10
lines changed

store.go

+58-10
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@ const (
2121
HostSandBox = "https://api.storekit-sandbox.itunes.apple.com"
2222
HostProduction = "https://api.storekit.itunes.apple.com"
2323

24-
PathTransactionInfo = "/inApps/v1/transactions/{transactionId}"
25-
PathLookUp = "/inApps/v1/lookup/{orderId}"
26-
PathTransactionHistory = "/inApps/v1/history/{originalTransactionId}"
27-
PathRefundHistory = "/inApps/v2/refund/lookup/{originalTransactionId}"
28-
PathGetALLSubscriptionStatus = "/inApps/v1/subscriptions/{originalTransactionId}"
29-
PathConsumptionInfo = "/inApps/v1/transactions/consumption/{originalTransactionId}"
30-
PathExtendSubscriptionRenewalDate = "/inApps/v1/subscriptions/extend/{originalTransactionId}"
31-
PathGetNotificationHistory = "/inApps/v1/notifications/history"
32-
PathRequestTestNotification = "/inApps/v1/notifications/test"
33-
PathGetTestNotificationStatus = "/inApps/v1/notifications/test/{testNotificationToken}"
24+
PathTransactionInfo = "/inApps/v1/transactions/{transactionId}"
25+
PathLookUp = "/inApps/v1/lookup/{orderId}"
26+
PathTransactionHistory = "/inApps/v1/history/{originalTransactionId}"
27+
PathRefundHistory = "/inApps/v2/refund/lookup/{originalTransactionId}"
28+
PathGetALLSubscriptionStatus = "/inApps/v1/subscriptions/{originalTransactionId}"
29+
PathConsumptionInfo = "/inApps/v1/transactions/consumption/{originalTransactionId}"
30+
PathExtendSubscriptionRenewalDate = "/inApps/v1/subscriptions/extend/{originalTransactionId}"
31+
PathExtendSubscriptionRenewalDateForAll = "/inApps/v1/subscriptions/extend/mass/"
32+
PathGetStatusOfSubscriptionRenewalDate = "/inApps/v1/subscriptions/extend/mass/{productId}/{requestIdentifier}"
33+
PathGetNotificationHistory = "/inApps/v1/notifications/history"
34+
PathRequestTestNotification = "/inApps/v1/notifications/test"
35+
PathGetTestNotificationStatus = "/inApps/v1/notifications/test/{testNotificationToken}"
3436
)
3537

3638
type StoreConfig struct {
@@ -265,6 +267,52 @@ func (c *StoreClient) ExtendSubscriptionRenewalDate(ctx context.Context, origina
265267
return statusCode, nil
266268
}
267269

270+
// ExtendSubscriptionRenewalDateForAll https://developer.apple.com/documentation/appstoreserverapi/extend_subscription_renewal_dates_for_all_active_subscribers
271+
func (c *StoreClient) ExtendSubscriptionRenewalDateForAll(ctx context.Context, body MassExtendRenewalDateRequest) (statusCode int, err error) {
272+
URL := HostProduction + PathExtendSubscriptionRenewalDateForAll
273+
if c.Token.Sandbox {
274+
URL = HostSandBox + PathExtendSubscriptionRenewalDateForAll
275+
}
276+
277+
bodyBuf := new(bytes.Buffer)
278+
err = json.NewEncoder(bodyBuf).Encode(body)
279+
if err != nil {
280+
return 0, err
281+
}
282+
283+
statusCode, _, err = c.Do(ctx, http.MethodPost, URL, bodyBuf)
284+
if err != nil {
285+
return statusCode, err
286+
}
287+
return statusCode, nil
288+
}
289+
290+
// GetSubscriptionRenewalDataStatus https://developer.apple.com/documentation/appstoreserverapi/get_status_of_subscription_renewal_date_extensions
291+
func (c *StoreClient) GetSubscriptionRenewalDataStatus(ctx context.Context, productId, requestIdentifier string) (statusCode int, rsp *MassExtendRenewalDateStatusResponse, err error) {
292+
URL := HostProduction + PathGetStatusOfSubscriptionRenewalDate
293+
if c.Token.Sandbox {
294+
URL = HostSandBox + PathGetStatusOfSubscriptionRenewalDate
295+
}
296+
URL = strings.Replace(URL, "{productId}", productId, -1)
297+
URL = strings.Replace(URL, "{requestIdentifier}", requestIdentifier, -1)
298+
299+
statusCode, body, err := c.Do(ctx, http.MethodGet, URL, nil)
300+
if err != nil {
301+
return statusCode, nil, err
302+
}
303+
304+
if statusCode != http.StatusOK {
305+
return statusCode, nil, fmt.Errorf("appstore api: %v return status code %v", URL, statusCode)
306+
}
307+
308+
err = json.Unmarshal(body, &rsp)
309+
if err != nil {
310+
return statusCode, nil, err
311+
}
312+
313+
return statusCode, rsp, nil
314+
}
315+
268316
// GetNotificationHistory https://developer.apple.com/documentation/appstoreserverapi/get_notification_history
269317
func (c *StoreClient) GetNotificationHistory(ctx context.Context, body NotificationHistoryRequest) (responses []NotificationHistoryResponseItem, err error) {
270318
baseURL := c.hostUrl + PathGetNotificationHistory

0 commit comments

Comments
 (0)