Skip to content

Instantly share code, notes, and snippets.

@dcox
Last active January 10, 2024 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcox/64ef1394e7f290ba7164cbe8d544bcb4 to your computer and use it in GitHub Desktop.
Save dcox/64ef1394e7f290ba7164cbe8d544bcb4 to your computer and use it in GitHub Desktop.
applestore.py
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