#Louis Daubié
1 messages · Page 1 of 1 (latest)
The two main causes of this are using the wrong webhook secret and not passing in the raw webhook body
Have you double checked your webhook endpoint secret? It is different for every endpoint so you have to use the right one
What do you means about raw body ?
Actually i send the json object of the body
Yes i dooble tcheck it, try to create an other webhook..
Usually it's works good but today with start an migration of the infrastructure to aws, and it's work on th api host in the older server but not on the api hosted in aws
The raw request body is the exact String that we send you as the body of the HTTP request
So i should stringify the body ?
So, not parsing it as json first basically
Yes I believe so
Then try passing that in
I will try it i will tell you if it's ok or not
You shouldn't need to do that, our built in construct event function should work here.
Are you decoding the body with UTF-8? decoding to ASCII can cause issues
Yes i agree but i don't understand why it's not working ? I not decoding the body with UTF-*
It also may be possible that your framework is doing something to the body before you get it. Are you using Express?
Yes i Using Express
This is the response erreur if it's can help
it's the body i got before to send it to the framework :
{
id: 'evt_3MyceeR6tQdZu3Pj1iyMrRyL',
object: 'event',
payment_method: 'pm_1MyceeR6tQdZu3PjksTFBALR',
payment_method_options: [Object],
payment_method_types: [Array],
processing: null,
receipt_email: null,
review: null,
setup_future_usage: null,
shipping: null,
source: null,
statement_descriptor: null,
statement_descriptor_suffix: null,
status: 'succeeded',
transfer_data: null,
transfer_group: null
}
},
livemode: false,
pending_webhooks: 2,
request: {
id: 'req_aqpYKoQkELU849',
idempotency_key: 'b71125df-5525-43d5-a904-6cc2756acd6c'
},
type: 'payment_intent.succeeded'
}
LALALALLALA
{
id: 'evt_3MyceeR6tQdZu3Pj1iyMrRyL',
object: 'event',
account: 'acct_1Jcql1R6tQdZu3Pj',
api_version: '2020-03-02',
created: 1681917046,
data: {
object: {
id: 'pi_3MyceeR6tQdZu3Pj1HmxHyVO',
object: 'payment_intent',
amount: 300,
amount_capturable: 0,
amount_details: [Object],
amount_received: 300,
application: 'ca_KHO21JdU0JWLcXb5VMXUtOYE9o0EYwDF',
application_fee_amount: 24,
automatic_payment_methods: null,
canceled_at: null,
cancellation_reason: null,
capture_method: 'automatic',
charges: [Object],
client_secret: 'pi_3MyceeR6tQdZu3Pj1HmxHyVO_secret_d4wj6uxlp3BqrP7fjTwECYwCw',
confirmation_method: 'automatic',
created: 1681917044,
currency: 'eur',
customer: null,
description: 'Commande n° 113823-10',
invoice: null,
last_payment_error: null,
latest_charge: 'ch_3MyceeR6tQdZu3Pj1cdKg8Qs',
livemode: false,
metadata: [Object],
next_action: null,
on_behalf_of: null,
payment_method: 'pm_1MyceeR6tQdZu3PjksTFBALR',
payment_method_options: [Object],
payment_method_types: [Array],
processing: null,
receipt_email: null,
review: null,
setup_future_usage: null,
shipping: null,
source: null,
statement_descriptor: null,
statement_descriptor_suffix: null,
status: 'succeeded',
transfer_data: null,
transfer_group: null
}
},
livemode: false,
pending_webhooks: 2,
request: {
id: 'req_aqpYKoQkELU849',
idempotency_key: 'b71125df-5525-43d5-a904-6cc2756acd6c'
},
type: 'payment_intent.succeeded'
}
Do you have an idea ?
With express you need to specifically use a raw body parser, this GH issue has a couple of examples https://github.com/stripe/stripe-node/issues/341#issuecomment-304497470
i already do it
router.post(
'/',
express.raw({ type: 'application/json' }),
orderController.stripeWebhook
);
as i told you it's already running on production, but whe migrate to aws and not working on it, its the same code on the 2 server. so i know how it's work, spend my day on the subject
But i really don't uynderstand the issue now it's for this i am here
if only doc could help me i would be ther
Oh in that case it sounds like your secret key may not be being retrieved properly on the new AWS server
The only other thing I can think of is that maybe AWS might have middleware that is messing with the body, but I would double check the secret first to make sure it is set to exactly what you think it is
yes it's exactly the same secret key
Ok but if aws mess the body there is a way to reconstruct it as need
?
That would depend on how AWS is changing the body unfortunately. I will see if I can find mention of this happening before with AWS
Can i have an exemple of the body ?
I mean what you sent looks right, unfortunately even little things like whitespace changing will throw off the hash calculation and invalidate the signature
I am trying to remember of whether there is a good way for you to get the raw body for one of your specific events to compare. Will get back to you on that
thanks
Is your AWS server running from the same URL as your other server was?
I just realized that if you are using a new server at a new URL, that would be a different webhook endpoint so you would want to use that secret key instead of the exact same one as before.