#AppleJaxxZ - Webhook
1 messages ยท Page 1 of 1 (latest)
ok
so, I can get a res.status of 200 in the stripe cli only if I run the code in localhost: 4242 but trying to run it in any other localhost it fails
Okay, have you put any logs in your code to ensure the endpointSecret is being properly loaded into the runtime? That the stripe-signature value is being retrieved?
yes
id: 'evt_1KqJwGI5dRZbWosxijFRLvH2',
object: 'event',
api_version: '2020-08-27',
created: 1650385803,
data: {
object: {
id: 'cus_LXOjN9mZItvtyB',
object: 'customer',
address: null,
balance: 0,
created: 1650385802,
currency: null,
default_source: null,
delinquent: false,
description: '(created by Stripe CLI)',
discount: null,
email: null,
invoice_prefix: '6F4BAFDE',
invoice_settings: [Object],
livemode: false,
metadata: [Object],
name: null,
next_invoice_sequence: 1,
phone: null,
preferred_locales: [],
shipping: null,
tax_exempt: 'none',
test_clock: null
},
previous_attributes: { metadata: [Object] }
},
livemode: false,
pending_webhooks: 2,
request: {
id: 'req_E28gID6F9wYQLq',
idempotency_key: '31305fbc-bc4d-49a4-94ee-f9a77f7d619e'
},
type: 'customer.updated'
}
THIS IS THE SIG t=1650385804,v1=05df3ab8432e7c12e757ff305c53195a9a729b89ccebf0699d1b907e585642b6,v0=333ca6c430b0b7b1f96e04aa422bd65d2e8d018448dbca4d230fd0fa5a281b0d```
def getting both
when I would try running it on the endpoint using the dashboard and heroku it would keep saying signatures do not match
even though im getting the secret, payload, and signatures
And when you are running on localhost are you using stripe listen?
correct
And you've registered a separate webhook endpoint for your heroku deployment?
yes
And the Heroku deployment shows the correct secret for that endpoint, not the local listener?
correct, also double checked that too
thats the thing though also, it works fine on localhost:4242 but not my main server or heroku's endpoint. lol'
when I assign it to localhost:4242 though it is in a seperate js file from node express setup
i just used the copy and paste from the stripe docs
would my middlewares interfere?
app.use(express.urlencoded({ extended: true }));
app.use(cors());
app.options("*", cors({ origin: true }));```
Anything that performs any kind of transformation on the data payload will invalidate the signature
The signature verification process needs the raw body
hmmm ok ill try removing my middlewares and seeing if it works
I hope it's that straightfoward
unfortunately it didnt work. when sending the payload should it look like this <Buffer 7b 0a 20 20 22 69 64 22 3a 20 22 65 76 74 5f 31 4b 71 4b 47 4a 49 35 64 52 5a 62 57 6f 73 78 66 4a 30 50 68 74 71 73 22 2c 0a 20 20 22 6f 62 6a 65 63 ... 1018 more bytes>. or a JSON object?
Do you mean when the payload is used in the constructEvent function call?
yes
I suspect as JSON
....i have an older version of stripe cli....although I doubt thats it..ill see if it has anything to do with it
๐ญ I got it
Ok so I have all of my routes in routes.use(). for some reason when I placed the endpoint above all the routes.use() it worked.
for some reason my other routes were effecting it
That is interesting. I haven't built many apps with Express so this is a useful troubleshooting step.
yeah for more than just this example it can come in handy. express can be touchy like that when it comes to order of operations
alright well thanks for your help
lol yeah, well it helped solve one thing, but now my server is getting an error saying Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client. so this has to be an order of operations here...im sure ill figure this out
oh nevermind i solved it
i did a response.send() twice
thats all
im good
yess all is well
๐