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
20 changes: 20 additions & 0 deletions appstoreserverlibrary/models/ExternalPurchaseToken.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import attr

from .LibraryUtility import AttrsRawValueAware
from .TokenType import TokenType

@define
class ExternalPurchaseToken(AttrsRawValueAware):
Expand Down Expand Up @@ -40,4 +41,23 @@ class ExternalPurchaseToken(AttrsRawValueAware):
The bundle identifier of an app.

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

tokenType: Optional[TokenType] = TokenType.create_main_attr('rawTokenType')
"""
The type of an external purchase custom link token.

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

rawTokenType: Optional[str] = TokenType.create_raw_attr('tokenType')
"""
See tokenType
"""

tokenExpirationDate: Optional[int] = attr.ib(default=None)
"""
The field of a custom link token that contains the UNIX date, in milliseconds, when the token expires.

https://developer.apple.com/documentation/appstoreservernotifications/tokenexpirationdate
"""
2 changes: 2 additions & 0 deletions appstoreserverlibrary/models/Subtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ class Subtype(str, Enum, metaclass=AppStoreServerLibraryEnumMeta):
SUMMARY = "SUMMARY"
FAILURE = "FAILURE"
UNREPORTED = "UNREPORTED"
ACTIVE_TOKEN_REMINDER = "ACTIVE_TOKEN_REMINDER"
CREATED = "CREATED"
14 changes: 14 additions & 0 deletions appstoreserverlibrary/models/TokenType.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) 2026 Apple Inc. Licensed under MIT License.

from enum import Enum

from .LibraryUtility import AppStoreServerLibraryEnumMeta

class TokenType(str, Enum, metaclass=AppStoreServerLibraryEnumMeta):
"""
The type of an external purchase custom link token.

https://developer.apple.com/documentation/appstoreservernotifications/tokentype
"""
SERVICES = "SERVICES"
ACQUISITION = "ACQUISITION"
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"externalPurchaseId": "b2158121-7af9-49d4-9561-1f588205523e",
"tokenCreationDate": 1698148950000,
"appAppleId": 55555,
"bundleId": "com.example"
"bundleId": "com.example",
"tokenType": "ACQUISITION",
"tokenExpirationDate": 1698149000000
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"externalPurchaseId": "SANDBOX_b2158121-7af9-49d4-9561-1f588205523e",
"tokenCreationDate": 1698148950000,
"appAppleId": 55555,
"bundleId": "com.example"
"bundleId": "com.example",
"tokenType": "ACQUISITION",
"tokenExpirationDate": 1698149000000
}
}
7 changes: 7 additions & 0 deletions tests/test_decoded_payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from appstoreserverlibrary.models.RevocationType import RevocationType
from appstoreserverlibrary.models.Status import Status
from appstoreserverlibrary.models.Subtype import Subtype
from appstoreserverlibrary.models.TokenType import TokenType
from appstoreserverlibrary.models.TransactionReason import TransactionReason
from appstoreserverlibrary.models.Type import Type
from appstoreserverlibrary.models.AdvancedCommercePeriod import AdvancedCommercePeriod
Expand Down Expand Up @@ -360,6 +361,9 @@ def check_environment_and_bundle_id(bundle_id: Optional[str], app_apple_id: Opti
self.assertEqual(1698148950000, notification.externalPurchaseToken.tokenCreationDate)
self.assertEqual(55555, notification.externalPurchaseToken.appAppleId)
self.assertEqual("com.example", notification.externalPurchaseToken.bundleId)
self.assertEqual(TokenType.ACQUISITION, notification.externalPurchaseToken.tokenType)
self.assertEqual("ACQUISITION", notification.externalPurchaseToken.rawTokenType)
self.assertEqual(1698149000000, notification.externalPurchaseToken.tokenExpirationDate)

def test_external_purchase_token_sandbox_notification_decoding(self):
signed_external_purchase_token_notification = create_signed_data_from_json('tests/resources/models/signedExternalPurchaseTokenSandboxNotification.json')
Expand Down Expand Up @@ -389,6 +393,9 @@ def check_environment_and_bundle_id(bundle_id: Optional[str], app_apple_id: Opti
self.assertEqual(1698148950000, notification.externalPurchaseToken.tokenCreationDate)
self.assertEqual(55555, notification.externalPurchaseToken.appAppleId)
self.assertEqual("com.example", notification.externalPurchaseToken.bundleId)
self.assertEqual(TokenType.ACQUISITION, notification.externalPurchaseToken.tokenType)
self.assertEqual("ACQUISITION", notification.externalPurchaseToken.rawTokenType)
self.assertEqual(1698149000000, notification.externalPurchaseToken.tokenExpirationDate)

def test_realtime_request_decoding(self):
signed_realtime_request = create_signed_data_from_json('tests/resources/models/decodedRealtimeRequest.json')
Expand Down