Apple allows sending an event when a purchase is made.
Step 1 Create the endpoint on your server.
import base64 import json @app.route('/webhook/apple', methods=['POST']) def webhook_apple(): try: signed_payload = request.json.get('signedPayload') if not signed_payload: return '', 200 # JWT tiene 3 partes: header.payload.signature # La del medio es el payload en Base64 payload_b64 = signed_payload.split('.')[1] # Base64 de JWT puede necesitar padding padding = 4 - len(payload_b64) % 4 payload_b64 += '=' * (padding % 4) notification = json.loads(base64.b64decode(payload_b64).decode('utf-8')) except Exception as e: print(f'Error Apple webhook: {e}') return '', 200
Step 2 Register it in App Store Connect
- Go to https://appstoreconnect.apple.com
- Your app → General → App Information
- Scroll down to App Store Server Notifications
- Paste your URL:
https://yourdomain.com/webhook/apple - There are two environments — put the URL in both Production and Sandbox for testing
