Last active
January 10, 2024 21:25
-
-
Save dcox/64ef1394e7f290ba7164cbe8d544bcb4 to your computer and use it in GitHub Desktop.
applestore.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def load_private_key(): | |
keyfile = os.environ.get("APPSTORE_CONNECT_KEYFILE") | |
with open(keyfile, 'rb') as privatefile: | |
return privatefile.read() | |
def get_appstore_client(private_key): | |
key_id = os.environ.get("APPSTORE_CONNECT_KEY_ID") | |
issuer_id = os.environ.get("APPSTORE_CONNECT_ISSUER_ID") | |
bundle_id = os.environ.get("APPSTORE_CONNECT_BUNDLE_ID") | |
environment = Environment.PRODUCTION | |
return AppStoreServerAPIClient(private_key, key_id, issuer_id, bundle_id, environment) | |
def test_appstore_connection(client): | |
try: | |
response = client.request_test_notification() | |
return response.testNotificationToken | |
except APIException as e: | |
print(e) | |
def get_transaction_history(client, transaction_id): | |
request = TransactionHistoryRequest() | |
return client.get_transaction_history(transaction_id, None, request) | |
def get_transaction_info(client, transaction_id): | |
return client.get_transaction_info(transaction_id) | |
def jwt_payload(jwt): | |
return base64.b64decode(jwt.split('.')[1]).decode() | |
if __name__ == "__main__": | |
private_key = load_private_key() | |
client = get_appstore_client(private_key) | |
token = test_appstore_connection(client) | |
# transaction = get_transaction_info(client,<TID>}) | |
# print(jwt_payload(transaction.signedTransactionInfo)) | |
history = get_transaction_history(client, <TID>) | |
print(history.signedTransactions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment