Skip to content

Commit e43690a

Browse files
Merge pull request #172 from riyazpanjwani/main
Updating App Store Server Library to support Consumption API and new …
2 parents 335f2d5 + 918eee8 commit e43690a

20 files changed

Lines changed: 565 additions & 143 deletions

appstoreserverlibrary/api_client.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import calendar
44
import datetime
5+
import warnings
56
from enum import IntEnum, Enum
67
from typing import Any, Dict, List, MutableMapping, Optional, Type, TypeVar, Union
78
from attr import define
@@ -14,6 +15,7 @@
1415
from appstoreserverlibrary.models.LibraryUtility import _get_cattrs_converter
1516
from .models.CheckTestNotificationResponse import CheckTestNotificationResponse
1617
from .models.ConsumptionRequest import ConsumptionRequest
18+
from .models.ConsumptionRequestV1 import ConsumptionRequestV1
1719
from .models.DefaultConfigurationRequest import DefaultConfigurationRequest
1820
from .models.Environment import Environment
1921
from .models.ExtendRenewalDateRequest import ExtendRenewalDateRequest
@@ -853,17 +855,32 @@ def request_test_notification(self) -> SendTestNotificationResponse:
853855
"""
854856
return self._make_request("/inApps/v1/notifications/test", "POST", {}, None, SendTestNotificationResponse, None)
855857

856-
def send_consumption_data(self, transaction_id: str, consumption_request: ConsumptionRequest):
858+
def send_consumption_data(self, transaction_id: str, consumption_request: ConsumptionRequestV1):
857859
"""
858860
Send consumption information about a consumable in-app purchase to the App Store after your server receives a consumption request notification.
859-
https://developer.apple.com/documentation/appstoreserverapi/send_consumption_information
861+
https://developer.apple.com/documentation/appstoreserverapi/send-consumption-information-v1
862+
863+
.. deprecated::
864+
Use :func:`send_consumption_information` instead.
860865
861866
:param transaction_id: The transaction identifier for which you're providing consumption information. You receive this identifier in the CONSUMPTION_REQUEST notification the App Store sends to your server.
862867
:param consumption_request: The request body containing consumption information.
863868
:raises APIException: If a response was returned indicating the request could not be processed
864869
"""
870+
warnings.warn("send_consumption_data is deprecated, use send_consumption_information instead", DeprecationWarning, stacklevel=2)
865871
self._make_request(f"/inApps/v1/transactions/consumption/{transaction_id}", "PUT", {}, consumption_request, None, None)
866872

873+
def send_consumption_information(self, transaction_id: str, consumption_request: ConsumptionRequest):
874+
"""
875+
Send consumption information about an In-App Purchase to the App Store after your server receives a consumption request notification.
876+
https://developer.apple.com/documentation/appstoreserverapi/send-consumption-information
877+
878+
:param transaction_id: The transaction identifier for which you're providing consumption information. You receive this identifier in the CONSUMPTION_REQUEST notification the App Store sends to your server's App Store Server Notifications V2 endpoint.
879+
:param consumption_request: The request body containing consumption information.
880+
:raises APIException: If a response was returned indicating the request could not be processed
881+
"""
882+
self._make_request(f"/inApps/v2/transactions/consumption/{transaction_id}", "PUT", {}, consumption_request, None, None)
883+
867884
def set_app_account_token(self, original_transaction_id: str, update_app_account_token_request: UpdateAppAccountTokenRequest):
868885
"""
869886
Sets the app account token value for a purchase the customer makes outside your app, or updates its value in an existing transaction.
@@ -1170,17 +1187,32 @@ async def request_test_notification(self) -> SendTestNotificationResponse:
11701187
"""
11711188
return await self._make_request("/inApps/v1/notifications/test", "POST", {}, None, SendTestNotificationResponse, None)
11721189

1173-
async def send_consumption_data(self, transaction_id: str, consumption_request: ConsumptionRequest):
1190+
async def send_consumption_data(self, transaction_id: str, consumption_request: ConsumptionRequestV1):
11741191
"""
11751192
Send consumption information about a consumable in-app purchase to the App Store after your server receives a consumption request notification.
1176-
https://developer.apple.com/documentation/appstoreserverapi/send_consumption_information
1193+
https://developer.apple.com/documentation/appstoreserverapi/send-consumption-information-v1
1194+
1195+
.. deprecated::
1196+
Use :func:`send_consumption_information` instead.
11771197
11781198
:param transaction_id: The transaction identifier for which you're providing consumption information. You receive this identifier in the CONSUMPTION_REQUEST notification the App Store sends to your server.
11791199
:param consumption_request: The request body containing consumption information.
11801200
:raises APIException: If a response was returned indicating the request could not be processed
11811201
"""
1202+
warnings.warn("send_consumption_data is deprecated, use send_consumption_information instead", DeprecationWarning, stacklevel=2)
11821203
await self._make_request(f"/inApps/v1/transactions/consumption/{transaction_id}", "PUT", {}, consumption_request, None, None)
11831204

1205+
async def send_consumption_information(self, transaction_id: str, consumption_request: ConsumptionRequest):
1206+
"""
1207+
Send consumption information about an In-App Purchase to the App Store after your server receives a consumption request notification.
1208+
https://developer.apple.com/documentation/appstoreserverapi/send-consumption-information
1209+
1210+
:param transaction_id: The transaction identifier for which you're providing consumption information. You receive this identifier in the CONSUMPTION_REQUEST notification the App Store sends to your server's App Store Server Notifications V2 endpoint.
1211+
:param consumption_request: The request body containing consumption information.
1212+
:raises APIException: If a response was returned indicating the request could not be processed
1213+
"""
1214+
await self._make_request(f"/inApps/v2/transactions/consumption/{transaction_id}", "PUT", {}, consumption_request, None, None)
1215+
11841216
async def set_app_account_token(self, original_transaction_id: str, update_app_account_token_request: UpdateAppAccountTokenRequest):
11851217
"""
11861218
Sets the app account token value for a purchase the customer makes outside your app, or updates its value in an existing transaction.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright (c) 2025 Apple Inc. Licensed under MIT License.
2+
from typing import Optional
3+
4+
from attr import define
5+
import attr
6+
7+
from .Environment import Environment
8+
from .LibraryUtility import AttrsRawValueAware
9+
10+
@define
11+
class AppData(AttrsRawValueAware):
12+
"""
13+
The object that contains the app metadata and signed app transaction information.
14+
15+
https://developer.apple.com/documentation/appstoreservernotifications/appdata
16+
"""
17+
18+
appAppleId: Optional[int] = attr.ib(default=None)
19+
"""
20+
The unique identifier of the app that the notification applies to.
21+
22+
https://developer.apple.com/documentation/appstoreservernotifications/appappleid
23+
"""
24+
25+
bundleId: Optional[str] = attr.ib(default=None)
26+
"""
27+
The bundle identifier of the app.
28+
29+
https://developer.apple.com/documentation/appstoreservernotifications/bundleid
30+
"""
31+
32+
environment: Optional[Environment] = Environment.create_main_attr('rawEnvironment')
33+
"""
34+
The server environment that the notification applies to, either sandbox or production.
35+
36+
https://developer.apple.com/documentation/appstoreservernotifications/environment
37+
"""
38+
39+
rawEnvironment: Optional[str] = Environment.create_raw_attr('environment')
40+
"""
41+
See environment
42+
"""
43+
44+
signedAppTransactionInfo: Optional[str] = attr.ib(default=None)
45+
"""
46+
App transaction information signed by the App Store, in JSON Web Signature (JWS) format.
47+
48+
https://developer.apple.com/documentation/appstoreservernotifications/jwsapptransaction
49+
"""
Lines changed: 18 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,153 +1,62 @@
1-
# Copyright (c) 2023 Apple Inc. Licensed under MIT License.
1+
# Copyright (c) 2025 Apple Inc. Licensed under MIT License.
22
from typing import Optional
33

44
from attr import define
55
import attr
66

7-
from .AccountTenure import AccountTenure
8-
from .ConsumptionStatus import ConsumptionStatus
97
from .DeliveryStatus import DeliveryStatus
108
from .LibraryUtility import AttrsRawValueAware
11-
from .LifetimeDollarsPurchased import LifetimeDollarsPurchased
12-
from .LifetimeDollarsRefunded import LifetimeDollarsRefunded
13-
from .Platform import Platform
14-
from .PlayTime import PlayTime
159
from .RefundPreference import RefundPreference
16-
from .UserStatus import UserStatus
1710

1811
@define
1912
class ConsumptionRequest(AttrsRawValueAware):
2013
"""
21-
The request body containing consumption information.
22-
14+
The request body that contains consumption information for an In-App Purchase.
15+
2316
https://developer.apple.com/documentation/appstoreserverapi/consumptionrequest
2417
"""
2518

26-
customerConsented: Optional[bool] = attr.ib(default=None)
19+
customerConsented: bool = attr.ib()
2720
"""
2821
A Boolean value that indicates whether the customer consented to provide consumption data to the App Store.
29-
30-
https://developer.apple.com/documentation/appstoreserverapi/customerconsented
31-
"""
32-
33-
consumptionStatus: Optional[ConsumptionStatus] = ConsumptionStatus.create_main_attr('rawConsumptionStatus')
34-
"""
35-
A value that indicates the extent to which the customer consumed the in-app purchase.
36-
37-
https://developer.apple.com/documentation/appstoreserverapi/consumptionstatus
38-
"""
39-
40-
rawConsumptionStatus: Optional[int] = ConsumptionStatus.create_raw_attr('consumptionStatus')
41-
"""
42-
See consumptionStatus
43-
"""
44-
45-
platform: Optional[Platform] = Platform.create_main_attr('rawPlatform')
46-
"""
47-
A value that indicates the platform on which the customer consumed the in-app purchase.
48-
49-
https://developer.apple.com/documentation/appstoreserverapi/platform
50-
"""
5122
52-
rawPlatform: Optional[int] = Platform.create_raw_attr('platform')
53-
"""
54-
See platform
23+
https://developer.apple.com/documentation/appstoreserverapi/customerconsented
5524
"""
5625

57-
sampleContentProvided: Optional[bool] = attr.ib(default=None)
26+
sampleContentProvided: bool = attr.ib()
5827
"""
5928
A Boolean value that indicates whether you provided, prior to its purchase, a free sample or trial of the content, or information about its functionality.
60-
29+
6130
https://developer.apple.com/documentation/appstoreserverapi/samplecontentprovided
6231
"""
6332

64-
deliveryStatus: Optional[DeliveryStatus] = DeliveryStatus.create_main_attr('rawDeliveryStatus')
33+
deliveryStatus: Optional[DeliveryStatus] = DeliveryStatus.create_main_attr('rawDeliveryStatus', raw_required=True)
6534
"""
6635
A value that indicates whether the app successfully delivered an in-app purchase that works properly.
67-
68-
https://developer.apple.com/documentation/appstoreserverapi/deliverystatus
69-
"""
70-
71-
rawDeliveryStatus: Optional[int] = DeliveryStatus.create_raw_attr('deliveryStatus')
72-
"""
73-
See deliveryStatus
74-
"""
75-
76-
appAccountToken: Optional[str] = attr.ib(default=None)
77-
"""
78-
The UUID that an app optionally generates to map a customer's in-app purchase with its resulting App Store transaction.
79-
80-
https://developer.apple.com/documentation/appstoreserverapi/appaccounttoken
81-
"""
8236
83-
accountTenure: Optional[AccountTenure] = AccountTenure.create_main_attr('rawAccountTenure')
84-
"""
85-
The age of the customer's account.
86-
87-
https://developer.apple.com/documentation/appstoreserverapi/accounttenure
88-
"""
89-
90-
rawAccountTenure: Optional[int] = AccountTenure.create_raw_attr('accountTenure')
91-
"""
92-
See accountTenure
93-
"""
94-
95-
playTime: Optional[PlayTime] = PlayTime.create_main_attr('rawPlayTime')
96-
"""
97-
A value that indicates the amount of time that the customer used the app.
98-
99-
https://developer.apple.com/documentation/appstoreserverapi/consumptionrequest
100-
"""
101-
102-
rawPlayTime: Optional[int] = PlayTime.create_raw_attr('playTime')
103-
"""
104-
See playTime
105-
"""
106-
107-
lifetimeDollarsRefunded: Optional[LifetimeDollarsRefunded] = LifetimeDollarsRefunded.create_main_attr('rawLifetimeDollarsRefunded')
37+
https://developer.apple.com/documentation/appstoreserverapi/deliverystatus
10838
"""
109-
A value that indicates the total amount, in USD, of refunds the customer has received, in your app, across all platforms.
11039

111-
https://developer.apple.com/documentation/appstoreserverapi/lifetimedollarsrefunded
112-
"""
113-
114-
rawLifetimeDollarsRefunded: Optional[int] = LifetimeDollarsRefunded.create_raw_attr('lifetimeDollarsRefunded')
115-
"""
116-
See lifetimeDollarsRefunded
40+
consumptionPercentage: Optional[int] = attr.ib(default=None)
11741
"""
42+
An integer that indicates the percentage, in milliunits, of the In-App Purchase the customer consumed.
11843
119-
lifetimeDollarsPurchased: Optional[LifetimeDollarsPurchased] = LifetimeDollarsPurchased.create_main_attr('rawLifetimeDollarsPurchased')
120-
"""
121-
A value that indicates the total amount, in USD, of in-app purchases the customer has made in your app, across all platforms.
122-
123-
https://developer.apple.com/documentation/appstoreserverapi/lifetimedollarspurchased
44+
https://developer.apple.com/documentation/appstoreserverapi/consumptionpercentage
12445
"""
12546

126-
rawLifetimeDollarsPurchased: Optional[int] = LifetimeDollarsPurchased.create_raw_attr('lifetimeDollarsPurchased')
47+
rawDeliveryStatus: str = DeliveryStatus.create_raw_attr('deliveryStatus', required=True)
12748
"""
128-
See lifetimeDollarsPurchased
129-
"""
130-
131-
userStatus: Optional[UserStatus] = UserStatus.create_main_attr('rawUserStatus')
132-
"""
133-
The status of the customer's account.
134-
135-
https://developer.apple.com/documentation/appstoreserverapi/userstatus
49+
See deliveryStatus
13650
"""
13751

138-
rawUserStatus: Optional[int] = UserStatus.create_raw_attr('userStatus')
139-
"""
140-
See userStatus
52+
refundPreference: Optional[RefundPreference] = RefundPreference.create_main_attr('rawRefundPreference')
14153
"""
54+
A value that indicates your preferred outcome for the refund request.
14255
143-
refundPreference: Optional[RefundPreference] = RefundPreference.create_main_attr('rawRefundPreference')
144-
"""
145-
A value that indicates your preference, based on your operational logic, as to whether Apple should grant the refund.
146-
14756
https://developer.apple.com/documentation/appstoreserverapi/refundpreference
14857
"""
14958

150-
rawRefundPreference: Optional[int] = RefundPreference.create_raw_attr('refundPreference')
59+
rawRefundPreference: Optional[str] = RefundPreference.create_raw_attr('refundPreference')
15160
"""
15261
See refundPreference
153-
"""
62+
"""

0 commit comments

Comments
 (0)