[Python] Verify an App Store receipt always staus code 21003

Discussão em 'Python' iniciado por Stack, Janeiro 3, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to verify a receipt with the App Store server in the sandbox environment. I've checked all values are correct but keep receiving:

    {
    "environment": "Sandbox",
    "status": 21003
    }


    My code:

    def verify_receipt(receipt_data: str, sandbox: bool = True) -> dict:
    """
    Verify an App Store receipt with Apple's verification service

    Args:
    receipt_data: The base64 encoded receipt data
    sandbox: Whether to use sandbox environment (default True)

    Returns:
    dict: The verification response from Apple
    """
    # URLs for verification
    SANDBOX_URL = "https://sandbox.itunes.apple.com/verifyReceipt"
    PRODUCTION_URL = "https://buy.itunes.apple.com/verifyReceipt"

    # Shared secret from App Store Connect
    SHARED_SECRET = "xxx......"

    # Prepare the verification URL
    verify_url = SANDBOX_URL if sandbox else PRODUCTION_URL

    # Prepare the request payload
    payload = {
    'receipt-data': receipt_data,
    'password': SHARED_SECRET,
    'exclude-old-transactions': True
    }
    response = requests.post(verify_url, json=payload)
    result = response.json()


    [​IMG]

    Continue reading...

Compartilhe esta Página