Package: app-store-server-library
Apple App Store Server Python LibraryThe Python server library for theApp Store Server APIandApp Store Server Notifications. Also available inSwift,Node.js, andJava.Table of ContentsBetaInstallationDocumentationUsageSupportInstallationRequirementsPython 3.7+Gradlepipinstallapp-store-server-libraryDocumentationDocumentationWWDC VideoUsageAPI Usagefromappstoreserverlibrary.api_clientimportAppStoreServerAPIClient,APIExceptionfromappstoreserverlibrary.models.EnvironmentimportEnvironmentfromappstoreserverlibrary.models.SendTestNotificationResponseimportSendTestNotificationResponseprivate_key=read_private_key("/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8")# Implemenation will varykey_id="ABCDEFGHIJ"issuer_id="99b16628-15e4-4668-972b-eeff55eeff55"bundle_id="com.example"environment=Environment.SANDBOXclient=AppStoreServerAPIClient(private_key,key_id,issuer_id,bundle_id,environment)try:response=client.request_test_notification()print(response)exceptAPIExceptionase:print(e)Verification Usagefromappstoreserverlibrary.models.EnvironmentimportEnvironmentfromappstoreserverlibrary.signed_data_verifierimportVerificationException,SignedDataVerifierroot_certificates=load_root_certificates()enable_online_checks=Truebundle_id="com.example"environment=Environment.SANDBOXsigned_data_verifier=SignedDataVerifier(root_certificates,enable_online_checks,environment,bundle_id)try:signed_notification="ey.."payload=signed_data_verifier.verify_and_decode_notification(signed_notification)print(payload)exceptVerificationExceptionase:print(e)Receipt Usagefromappstoreserverlibrary.api_clientimportAppStoreServerAPIClient,APIExceptionfromappstoreserverlibrary.models.EnvironmentimportEnvironmentfromappstoreserverlibrary.receipt_utilityimportReceiptUtilityfromappstoreserverlibrary.models.HistoryResponseimportHistoryResponsefromappstoreserverlibrary.models.TransactionHistoryRequestimportTransactionHistoryRequest,ProductType,Orderprivate_key=read_private_key("/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8")# Implemenation will varykey_id="ABCDEFGHIJ"issuer_id="99b16628-15e4-4668-972b-eeff55eeff55"bundle_id="com.example"environment=Environment.SANDBOXclient=AppStoreServerAPIClient(private_key,key_id,issuer_id,bundle_id,environment)receipt_util=ReceiptUtility()app_receipt="MI.."try:transaction_id=receipt_util.extract_transaction_id_from_app_receipt(app_receipt)iftransaction_id!=None:transactions=[]response:HistoryResponse=Nonerequest:TransactionHistoryRequest=TransactionHistoryRequest(sort=Order.ASCENDING,revoked=False,productTypes=[ProductType.AUTO_RENEWABLE])whileresponse==Noneorresponse.hasMore:revision=response.revisionifresponse!=NoneelseNoneresponse=client.get_transaction_history(transaction_id,revision,request)fortransactioninresponse.signedTransactions:transactions.append(transaction)print(transactions)exceptAPIExceptionase:print(e)Promotional Offer Signature Creationfromappstoreserverlibrary.promotional_offerimportPromotionalOfferSignatureCreatorimporttimeprivate_key=read_private_key("/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8")# Implemenation will varykey_id="ABCDEFGHIJ"bundle_id="com.example"promotion_code_signature_generator=PromotionalOfferSignatureCreator(private_key,key_id,bundle_id)product_id="<product_id>"subscription_offer_id="<subscription_offer_id>"application_username="<application_username>"nonce="<nonce>"timestamp=round(time.time()*1000)base64_encoded_signature=promotion_code_signature_generator.create_signature(product_id,subscription_offer_id,application_username,nonce,timestamp)SupportOnly the latest major version of the library will receive updates, including security updates. Therefore, it is recommended to update to new major versions.