com.stripe.exception.SignatureVerificationException
See original GitHub issueMy webserver is a apache tomcat java servlet webserver. I keep getting the error com.stripe.exception.SignatureVerificationException: No signatures found matching the expected signature for payload
.
I have tried to get the request body with req.getReader().lines().collect(Collectors.joining())
but I still get the error. This is what the payload looks like
{ "id": "evt_1GxflCKnr9az9gTnSx6pa7KT", "object": "event", "api_version": "2020-03-02", "created": 1593032637, "data": { "object": { "id": "cs_test_rwrNI9q1Zw2ESPjNtuJPtTMvbcIdTfv3JBoUk1Er7h0wiSAzmuxUMeVf", "object": "checkout.session", "billing_address_collection": null, "cancel_url": "https://example.com/cancel", "client_reference_id": null, "customer": "cus_HWjDEWSjC9No1F", "customer_email": null, "livemode": false, "locale": null, "metadata": { "message": "m", "buyerName": "m", "email": "gmyoungwps@gmail.com" }, "mode": "subscription", "payment_intent": null, "payment_method_types": [ "card" ], "setup_intent": null, "shipping": null, "shipping_address_collection": null, "submit_type": null, "subscription": "sub_HWjDjtufcasHFy", "success_url": "https://example.com/success?session_id={CHECKOUT_SESSION_ID}" } }, "livemode": false, "pending_webhooks": 1, "request": { "id": "req_BFygc4p4ANudUI", "idempotency_key": null }, "type": "checkout.session.completed"}
. I am not sure how to get the rawbody the way that stripe wants me to with servlets.
I followed this documentation: https://stripe.com/docs/payments/checkout/set-up-a-subscription
This error comes from the event = Webhook.constructEvent(payload, header, endpointSecret);
Issue Analytics
- State:
- Created 3 years ago
- Comments:9
If anyone comes here with my same problem here is how I got the raw body:
String payload = IOUtils.toString(req.getInputStream(), "UTF-8");
@georgemax99 Thanks for sharing your solution. I was encountering the same issue and your solution works perfectly!