Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions appstoreserverlibrary/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import calendar
import datetime
import warnings
from enum import IntEnum, Enum
from typing import Any, Dict, List, MutableMapping, Optional, Type, TypeVar, Union
from attr import define
Expand All @@ -14,6 +15,7 @@
from appstoreserverlibrary.models.LibraryUtility import _get_cattrs_converter
from .models.CheckTestNotificationResponse import CheckTestNotificationResponse
from .models.ConsumptionRequest import ConsumptionRequest
from .models.ConsumptionRequestV1 import ConsumptionRequestV1
from .models.DefaultConfigurationRequest import DefaultConfigurationRequest
from .models.Environment import Environment
from .models.ExtendRenewalDateRequest import ExtendRenewalDateRequest
Expand Down Expand Up @@ -853,17 +855,32 @@ def request_test_notification(self) -> SendTestNotificationResponse:
"""
return self._make_request("/inApps/v1/notifications/test", "POST", {}, None, SendTestNotificationResponse, None)

def send_consumption_data(self, transaction_id: str, consumption_request: ConsumptionRequest):
def send_consumption_data(self, transaction_id: str, consumption_request: ConsumptionRequestV1):
"""
Send consumption information about a consumable in-app purchase to the App Store after your server receives a consumption request notification.
https://developer.apple.com/documentation/appstoreserverapi/send_consumption_information
https://developer.apple.com/documentation/appstoreserverapi/send-consumption-information-v1

.. deprecated::
Use :func:`send_consumption_information` instead.

: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.
:param consumption_request: The request body containing consumption information.
:raises APIException: If a response was returned indicating the request could not be processed
"""
warnings.warn("send_consumption_data is deprecated, use send_consumption_information instead", DeprecationWarning, stacklevel=2)
self._make_request(f"/inApps/v1/transactions/consumption/{transaction_id}", "PUT", {}, consumption_request, None, None)

def send_consumption_information(self, transaction_id: str, consumption_request: ConsumptionRequest):
"""
Send consumption information about an In-App Purchase to the App Store after your server receives a consumption request notification.
https://developer.apple.com/documentation/appstoreserverapi/send-consumption-information

: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.
:param consumption_request: The request body containing consumption information.
:raises APIException: If a response was returned indicating the request could not be processed
"""
self._make_request(f"/inApps/v2/transactions/consumption/{transaction_id}", "PUT", {}, consumption_request, None, None)

def set_app_account_token(self, original_transaction_id: str, update_app_account_token_request: UpdateAppAccountTokenRequest):
"""
Sets the app account token value for a purchase the customer makes outside your app, or updates its value in an existing transaction.
Expand Down Expand Up @@ -1170,17 +1187,32 @@ async def request_test_notification(self) -> SendTestNotificationResponse:
"""
return await self._make_request("/inApps/v1/notifications/test", "POST", {}, None, SendTestNotificationResponse, None)

async def send_consumption_data(self, transaction_id: str, consumption_request: ConsumptionRequest):
async def send_consumption_data(self, transaction_id: str, consumption_request: ConsumptionRequestV1):
"""
Send consumption information about a consumable in-app purchase to the App Store after your server receives a consumption request notification.
https://developer.apple.com/documentation/appstoreserverapi/send_consumption_information
https://developer.apple.com/documentation/appstoreserverapi/send-consumption-information-v1

.. deprecated::
Use :func:`send_consumption_information` instead.

: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.
:param consumption_request: The request body containing consumption information.
:raises APIException: If a response was returned indicating the request could not be processed
"""
warnings.warn("send_consumption_data is deprecated, use send_consumption_information instead", DeprecationWarning, stacklevel=2)
await self._make_request(f"/inApps/v1/transactions/consumption/{transaction_id}", "PUT", {}, consumption_request, None, None)

async def send_consumption_information(self, transaction_id: str, consumption_request: ConsumptionRequest):
"""
Send consumption information about an In-App Purchase to the App Store after your server receives a consumption request notification.
https://developer.apple.com/documentation/appstoreserverapi/send-consumption-information

: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.
:param consumption_request: The request body containing consumption information.
:raises APIException: If a response was returned indicating the request could not be processed
"""
await self._make_request(f"/inApps/v2/transactions/consumption/{transaction_id}", "PUT", {}, consumption_request, None, None)

async def set_app_account_token(self, original_transaction_id: str, update_app_account_token_request: UpdateAppAccountTokenRequest):
"""
Sets the app account token value for a purchase the customer makes outside your app, or updates its value in an existing transaction.
Expand Down
49 changes: 49 additions & 0 deletions appstoreserverlibrary/models/AppData.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright (c) 2025 Apple Inc. Licensed under MIT License.
from typing import Optional

from attr import define
import attr

from .Environment import Environment
from .LibraryUtility import AttrsRawValueAware

@define
class AppData(AttrsRawValueAware):
"""
The object that contains the app metadata and signed app transaction information.

https://developer.apple.com/documentation/appstoreservernotifications/appdata
"""

appAppleId: Optional[int] = attr.ib(default=None)
"""
The unique identifier of the app that the notification applies to.

https://developer.apple.com/documentation/appstoreservernotifications/appappleid
"""

bundleId: Optional[str] = attr.ib(default=None)
"""
The bundle identifier of the app.

https://developer.apple.com/documentation/appstoreservernotifications/bundleid
"""

environment: Optional[Environment] = Environment.create_main_attr('rawEnvironment')
"""
The server environment that the notification applies to, either sandbox or production.

https://developer.apple.com/documentation/appstoreservernotifications/environment
"""

rawEnvironment: Optional[str] = Environment.create_raw_attr('environment')
"""
See environment
"""

signedAppTransactionInfo: Optional[str] = attr.ib(default=None)
"""
App transaction information signed by the App Store, in JSON Web Signature (JWS) format.

https://developer.apple.com/documentation/appstoreservernotifications/jwsapptransaction
"""
127 changes: 18 additions & 109 deletions appstoreserverlibrary/models/ConsumptionRequest.py
Original file line number Diff line number Diff line change
@@ -1,153 +1,62 @@
# Copyright (c) 2023 Apple Inc. Licensed under MIT License.
# Copyright (c) 2025 Apple Inc. Licensed under MIT License.
from typing import Optional

from attr import define
import attr

from .AccountTenure import AccountTenure
from .ConsumptionStatus import ConsumptionStatus
from .DeliveryStatus import DeliveryStatus
from .LibraryUtility import AttrsRawValueAware
from .LifetimeDollarsPurchased import LifetimeDollarsPurchased
from .LifetimeDollarsRefunded import LifetimeDollarsRefunded
from .Platform import Platform
from .PlayTime import PlayTime
from .RefundPreference import RefundPreference
from .UserStatus import UserStatus

@define
class ConsumptionRequest(AttrsRawValueAware):
"""
The request body containing consumption information.
The request body that contains consumption information for an In-App Purchase.

https://developer.apple.com/documentation/appstoreserverapi/consumptionrequest
"""

customerConsented: Optional[bool] = attr.ib(default=None)
customerConsented: bool = attr.ib()
"""
A Boolean value that indicates whether the customer consented to provide consumption data to the App Store.

https://developer.apple.com/documentation/appstoreserverapi/customerconsented
"""

consumptionStatus: Optional[ConsumptionStatus] = ConsumptionStatus.create_main_attr('rawConsumptionStatus')
"""
A value that indicates the extent to which the customer consumed the in-app purchase.

https://developer.apple.com/documentation/appstoreserverapi/consumptionstatus
"""

rawConsumptionStatus: Optional[int] = ConsumptionStatus.create_raw_attr('consumptionStatus')
"""
See consumptionStatus
"""

platform: Optional[Platform] = Platform.create_main_attr('rawPlatform')
"""
A value that indicates the platform on which the customer consumed the in-app purchase.

https://developer.apple.com/documentation/appstoreserverapi/platform
"""

rawPlatform: Optional[int] = Platform.create_raw_attr('platform')
"""
See platform
https://developer.apple.com/documentation/appstoreserverapi/customerconsented
"""

sampleContentProvided: Optional[bool] = attr.ib(default=None)
sampleContentProvided: bool = attr.ib()
"""
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.

https://developer.apple.com/documentation/appstoreserverapi/samplecontentprovided
"""

deliveryStatus: Optional[DeliveryStatus] = DeliveryStatus.create_main_attr('rawDeliveryStatus')
deliveryStatus: Optional[DeliveryStatus] = DeliveryStatus.create_main_attr('rawDeliveryStatus', raw_required=True)
"""
A value that indicates whether the app successfully delivered an in-app purchase that works properly.

https://developer.apple.com/documentation/appstoreserverapi/deliverystatus
"""

rawDeliveryStatus: Optional[int] = DeliveryStatus.create_raw_attr('deliveryStatus')
"""
See deliveryStatus
"""

appAccountToken: Optional[str] = attr.ib(default=None)
"""
The UUID that an app optionally generates to map a customer's in-app purchase with its resulting App Store transaction.

https://developer.apple.com/documentation/appstoreserverapi/appaccounttoken
"""

accountTenure: Optional[AccountTenure] = AccountTenure.create_main_attr('rawAccountTenure')
"""
The age of the customer's account.

https://developer.apple.com/documentation/appstoreserverapi/accounttenure
"""

rawAccountTenure: Optional[int] = AccountTenure.create_raw_attr('accountTenure')
"""
See accountTenure
"""

playTime: Optional[PlayTime] = PlayTime.create_main_attr('rawPlayTime')
"""
A value that indicates the amount of time that the customer used the app.

https://developer.apple.com/documentation/appstoreserverapi/consumptionrequest
"""

rawPlayTime: Optional[int] = PlayTime.create_raw_attr('playTime')
"""
See playTime
"""

lifetimeDollarsRefunded: Optional[LifetimeDollarsRefunded] = LifetimeDollarsRefunded.create_main_attr('rawLifetimeDollarsRefunded')
https://developer.apple.com/documentation/appstoreserverapi/deliverystatus
"""
A value that indicates the total amount, in USD, of refunds the customer has received, in your app, across all platforms.

https://developer.apple.com/documentation/appstoreserverapi/lifetimedollarsrefunded
"""

rawLifetimeDollarsRefunded: Optional[int] = LifetimeDollarsRefunded.create_raw_attr('lifetimeDollarsRefunded')
"""
See lifetimeDollarsRefunded
consumptionPercentage: Optional[int] = attr.ib(default=None)
"""
An integer that indicates the percentage, in milliunits, of the In-App Purchase the customer consumed.

lifetimeDollarsPurchased: Optional[LifetimeDollarsPurchased] = LifetimeDollarsPurchased.create_main_attr('rawLifetimeDollarsPurchased')
"""
A value that indicates the total amount, in USD, of in-app purchases the customer has made in your app, across all platforms.

https://developer.apple.com/documentation/appstoreserverapi/lifetimedollarspurchased
https://developer.apple.com/documentation/appstoreserverapi/consumptionpercentage
"""

rawLifetimeDollarsPurchased: Optional[int] = LifetimeDollarsPurchased.create_raw_attr('lifetimeDollarsPurchased')
rawDeliveryStatus: str = DeliveryStatus.create_raw_attr('deliveryStatus', required=True)
"""
See lifetimeDollarsPurchased
"""

userStatus: Optional[UserStatus] = UserStatus.create_main_attr('rawUserStatus')
"""
The status of the customer's account.

https://developer.apple.com/documentation/appstoreserverapi/userstatus
See deliveryStatus
"""

rawUserStatus: Optional[int] = UserStatus.create_raw_attr('userStatus')
"""
See userStatus
refundPreference: Optional[RefundPreference] = RefundPreference.create_main_attr('rawRefundPreference')
"""
A value that indicates your preferred outcome for the refund request.

refundPreference: Optional[RefundPreference] = RefundPreference.create_main_attr('rawRefundPreference')
"""
A value that indicates your preference, based on your operational logic, as to whether Apple should grant the refund.

https://developer.apple.com/documentation/appstoreserverapi/refundpreference
"""

rawRefundPreference: Optional[int] = RefundPreference.create_raw_attr('refundPreference')
rawRefundPreference: Optional[str] = RefundPreference.create_raw_attr('refundPreference')
"""
See refundPreference
"""
"""
Loading