Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update code and method annotation #82

Merged
merged 8 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 20 additions & 19 deletions appstoreserverlibrary/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,17 +472,17 @@ def _generate_token(self) -> str:

def _make_request(self, path: str, method: str, queryParameters: Dict[str, Union[str, List[str]]], body, destination_class: Type[T]) -> T:
url = self._base_url + path
c = _get_cattrs_converter(type(body)) if body != None else None
json = c.unstructure(body) if body != None else None
c = _get_cattrs_converter(type(body)) if body is not None else None
json = c.unstructure(body) if body is not None else None
headers = {
'User-Agent': "app-store-server-library/python/1.1.0",
'Authorization': 'Bearer ' + self._generate_token(),
'Accept': 'application/json'
}

response = self._execute_request(method, url, queryParameters, headers, json)
if response.status_code >= 200 and response.status_code < 300:
if destination_class == None:
if 200 <= response.status_code < 300:
if destination_class is None:
return
c = _get_cattrs_converter(destination_class)
response_body = response.json()
Expand Down Expand Up @@ -536,7 +536,7 @@ def get_all_subscription_statuses(self, transaction_id: str, status: Optional[Li
:throws APIException: If a response was returned indicating the request could not be processed
"""
queryParameters: Dict[str, List[str]] = dict()
if status != None:
if status is not None:
queryParameters["status"] = [s.value for s in status]

return self._make_request("/inApps/v1/subscriptions/" + transaction_id, "GET", queryParameters, None, StatusResponse)
Expand All @@ -547,13 +547,13 @@ def get_refund_history(self, transaction_id: str, revision: Optional[str]) -> Re
https://developer.apple.com/documentation/appstoreserverapi/get_refund_history

:param transaction_id: The identifier of a transaction that belongs to the customer, and which may be an original transaction identifier.
:param revision: A token you provide to get the next set of up to 20 transactions. All responses include a revision token. Use the revision token from the previous RefundHistoryResponse.
:param revision: A token you provide to get the next set of up to 20 transactions. All responses include a revision token. Use the revision token from the previous RefundHistoryResponse.
:return: A response that contains status information for all of a customer's auto-renewable subscriptions in your app.
:throws APIException: If a response was returned indicating the request could not be processed
"""

queryParameters: Dict[str, List[str]] = dict()
if revision != None:
if revision is not None:
queryParameters["revision"] = [revision]

return self._make_request("/inApps/v2/refund/lookup/" + transaction_id, "GET", queryParameters, None, RefundHistoryResponse)
Expand All @@ -564,7 +564,7 @@ def get_status_of_subscription_renewal_date_extensions(self, request_identifier:
https://developer.apple.com/documentation/appstoreserverapi/get_status_of_subscription_renewal_date_extensions

:param request_identifier: The UUID that represents your request to the Extend Subscription Renewal Dates for All Active Subscribers endpoint.
:param product_id: The product identifier of the auto-renewable subscription that you request a renewal-date extension for.
:param product_id: The product identifier of the auto-renewable subscription that you request a renewal-date extension for.
:return: A response that indicates the current status of a request to extend the subscription renewal date to all eligible subscribers.
:throws APIException: If a response was returned indicating the request could not be processed
"""
Expand Down Expand Up @@ -592,7 +592,7 @@ def get_notification_history(self, pagination_token: Optional[str], notification
:throws APIException: If a response was returned indicating the request could not be processed
"""
queryParameters: Dict[str, List[str]] = dict()
if pagination_token != None:
if pagination_token is not None:
queryParameters["paginationToken"] = [pagination_token]

return self._make_request("/inApps/v1/notifications/history", "POST", queryParameters, notification_history_request, NotificationHistoryResponse)
Expand All @@ -603,36 +603,37 @@ def get_transaction_history(self, transaction_id: str, revision: Optional[str],
https://developer.apple.com/documentation/appstoreserverapi/get_transaction_history

:param transaction_id: The identifier of a transaction that belongs to the customer, and which may be an original transaction identifier.
:param revision: A token you provide to get the next set of up to 20 transactions. All responses include a revision token. Note: For requests that use the revision token, include the same query parameters from the initial request. Use the revision token from the previous HistoryResponse.
:param revision: A token you provide to get the next set of up to 20 transactions. All responses include a revision token. Note: For requests that use the revision token, include the same query parameters from the initial request. Use the revision token from the previous HistoryResponse.
:param transaction_history_request: The request parameters that includes the startDate,endDate,productIds,productTypes and optional query constraints.
:return: A response that contains the customer's transaction history for an app.
:throws APIException: If a response was returned indicating the request could not be processed
"""
queryParameters: Dict[str, List[str]] = dict()
if revision != None:
if revision is not None:
queryParameters["revision"] = [revision]

if transaction_history_request.startDate != None:
if transaction_history_request.startDate is not None:
queryParameters["startDate"] = [str(transaction_history_request.startDate)]

if transaction_history_request.endDate != None:
if transaction_history_request.endDate is not None:
queryParameters["endDate"] = [str(transaction_history_request.endDate)]

if transaction_history_request.productIds != None:
if transaction_history_request.productIds is not None:
queryParameters["productId"] = transaction_history_request.productIds

if transaction_history_request.productTypes != None:
if transaction_history_request.productTypes is not None:
queryParameters["productType"] = [product_type.value for product_type in transaction_history_request.productTypes]

if transaction_history_request.sort != None:
if transaction_history_request.sort is not None:
queryParameters["sort"] = [transaction_history_request.sort.value]

if transaction_history_request.subscriptionGroupIdentifiers != None:
if transaction_history_request.subscriptionGroupIdentifiers is not None:
queryParameters["subscriptionGroupIdentifier"] = transaction_history_request.subscriptionGroupIdentifiers

if transaction_history_request.inAppOwnershipType != None:
if transaction_history_request.inAppOwnershipType is not None:
queryParameters["inAppOwnershipType"] = [transaction_history_request.inAppOwnershipType.value]

if transaction_history_request.revoked != None:
if transaction_history_request.revoked is not None:
queryParameters["revoked"] = [str(transaction_history_request.revoked)]

return self._make_request("/inApps/v1/history/" + transaction_id, "GET", queryParameters, None, HistoryResponse)
Expand Down
4 changes: 2 additions & 2 deletions appstoreserverlibrary/models/ExtendRenewalDateRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class ExtendRenewalDateRequest:
extendByDays: Optional[int] = attr.ib(default=None)
"""
The number of days to extend the subscription renewal date.

The number of days is a number from 1 to 90.
hakusai22 marked this conversation as resolved.
Show resolved Hide resolved

https://developer.apple.com/documentation/appstoreserverapi/extendbydays
maximum: 90
"""

extendReasonCode: Optional[ExtendReasonCode] = attr.ib(default=None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class JWSTransactionDecodedPayload(AttrsRawValueAware):

transactionReason: Optional[TransactionReason] = TransactionReason.create_main_attr('rawTransactionReason')
"""
The reason for the purchase transaction, which indicates whether it's a customer's purchase or a renewal for an auto-renewable subscription that the system initates.
The reason for the purchase transaction, which indicates whether it's a customer's purchase or a renewal for an auto-renewable subscription that the system initiates.

https://developer.apple.com/documentation/appstoreserverapi/transactionreason
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ class NotificationHistoryResponse:
"""
An array of App Store server notification history records.

https://developer.apple.com/documentation/appstoreserverapi/notificationhistoryresponseitem
"""
2 changes: 1 addition & 1 deletion appstoreserverlibrary/models/NotificationTypeV2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class NotificationTypeV2(str, Enum, metaclass=AppStoreServerLibraryEnumMeta):
"""
A notification type value that App Store Server Notifications V2 uses.

https://developer.apple.com/documentation/appstoreserverapi/notificationtype
https://developer.apple.com/documentation/appstoreservernotifications/notificationtype
"""
SUBSCRIBED = "SUBSCRIBED"
DID_CHANGE_RENEWAL_PREF = "DID_CHANGE_RENEWAL_PREF"
Expand Down
2 changes: 2 additions & 0 deletions appstoreserverlibrary/models/OrderLookupResponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ class OrderLookupResponse(AttrsRawValueAware):
signedTransactions: Optional[List[str]] = attr.ib(default=None)
"""
An array of in-app purchase transactions that are part of order, signed by Apple, in JSON Web Signature format.

https://developer.apple.com/documentation/appstoreserverapi/jwstransaction
"""
2 changes: 2 additions & 0 deletions appstoreserverlibrary/models/RefundHistoryResponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class RefundHistoryResponse:
signedTransactions: Optional[List[str]] = attr.ib(default=None)
"""
A list of up to 20 JWS transactions, or an empty array if the customer hasn't received any refunds in your app. The transactions are sorted in ascending order by revocationDate.

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

revision: Optional[str] = attr.ib(default=None)
Expand Down
1 change: 1 addition & 0 deletions appstoreserverlibrary/models/StatusResponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ class StatusResponse(AttrsRawValueAware):
"""
An array of information for auto-renewable subscriptions, including App Store-signed transaction information and App Store-signed renewal information.

https://developer.apple.com/documentation/appstoreserverapi/subscriptiongroupidentifieritem
"""
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ class SubscriptionGroupIdentifierItem:
lastTransactions: Optional[List[LastTransactionsItem]] = attr.ib(default=None)
"""
An array of the most recent App Store-signed transaction information and App Store-signed renewal information for all auto-renewable subscriptions in the subscription group.

https://developer.apple.com/documentation/appstoreserverapi/lasttransactionsitem
"""
4 changes: 2 additions & 2 deletions appstoreserverlibrary/models/Subtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

class Subtype(str, Enum, metaclass=AppStoreServerLibraryEnumMeta):
"""
A notification subtype value that App Store Server Notifications 2 uses.
A notification subtype value that App Store Server Notifications V2 uses.

https://developer.apple.com/documentation/appstoreserverapi/notificationsubtype
https://developer.apple.com/documentation/appstoreservernotifications/subtype
"""
INITIAL_BUY = "INITIAL_BUY"
RESUBSCRIBE = "RESUBSCRIBE"
Expand Down
2 changes: 1 addition & 1 deletion appstoreserverlibrary/models/TransactionHistoryRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ class TransactionHistoryRequest:

revoked: Optional[bool] = attr.ib(default=None)
"""
An optional Boolean value that indicates whether the response includes only revoked transactions when the value is true, or contains only nonrevoked transactions when the value is false. By default, the request doesn't include this parameter.
An optional Boolean value that indicates whether the response includes only revoked transactions when the value is true, or contains only non-revoked transactions when the value is false. By default, the request doesn't include this parameter.
hakusai22 marked this conversation as resolved.
Show resolved Hide resolved
"""
2 changes: 1 addition & 1 deletion tests/test_decoded_payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_renewal_info_decoding(self):
self.assertEqual(1698148800000, renewal_info.recentSubscriptionStartDate)
self.assertEqual(1698148850000, renewal_info.renewalDate)

def test_notificaiton_decoding(self):
def test_notification_decoding(self):
signed_notification = create_signed_data_from_json('tests/resources/models/signedNotification.json')

signed_data_verifier = get_default_signed_data_verifier()
Expand Down