How to send purchase notifications in an iOS app to a webhook

Tiempo de lectura: < 1 minuto

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

  1. Go to https://appstoreconnect.apple.com
  2. Your app → General → App Information
  3. Scroll down to App Store Server Notifications
  4. Paste your URL: https://yourdomain.com/webhook/apple
  5. There are two environments — put the URL in both Production and Sandbox for testing

Leave a Comment