stripe-node icon indicating copy to clipboard operation
stripe-node copied to clipboard

com.stripe.exception.SignatureVerificationException:

Open georgemax99 opened this issue 6 years ago • 3 comments

My 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": "[email protected]" }, "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);

georgemax99 avatar Jun 24 '20 22:06 georgemax99

This is the repo for stripe-node, whereas it looks like you're using stripe-java. Closing this as it doesn't have anything to do with this repo specifically.

To unblock you, the body that you pass into Webhook.constructEvent must be the raw body. It looks like your body here has been parsed as JSON, which makes it impossible for stripe-java to verify its signature.

paulasjes-stripe avatar Jun 25 '20 01:06 paulasjes-stripe

@paulasjes-stripe The json is from just printing to my logs what is returned from req.getReader().lines().collect(Collectors.joining()). The req.getReader().lines().collect(Collectors.joining()) is the raw body I am getting. There are two methods of getting the body which is req.getReader() which returns a BufferedReader or req.getInputStream() which returns a ServletInputStream. The constructEvent method takes three strings as inputs. Is there any other way that I am supposed to get the rawbody in the form of a String?

georgemax99 avatar Jun 25 '20 01:06 georgemax99

@paulasjes-stripe Oh sorry I posted it in stripe-java.

georgemax99 avatar Jun 25 '20 01:06 georgemax99