python-3.xgoogle-cloud-firestorestripe-paymentsfastapi

stripe.error.SignatureVerificationError: No signatures found matching the expected signature for payload" - Python FastAPI


I am integrating Stripe API with Firebase using Fastapi and I am facing the issue - "stripe.error.SignatureVerificationError: No signatures found matching the expected signature for payload"

The code is working in local testing with Stripe CLI but doesn't work in deployment. The error is on the last line.

async def feathers_buy_update(request: Request):
    """Endpoint to handle the Stripe session status updates like checkout completed or checkout expired

    Args:

    """
    event = None
    payload = await request.body()
    sig_header = request.headers.get("stripe-signature")
    endpoint_secret = "<endpoint_secret>"

    event = stripe.Webhook.construct_event(payload, sig_header, endpoint_secret)

I printed the type of all three inputs. Payload - bytes, sig_header - string, endpoint_secret - string.


Solution

  • There's a lot of different reasons you could be hitting verification issues, but usually when you hit these issues after already confirming things work locally during testing it's one of the following: