#AppleJaxxZ - Webhook

1 messages ยท Page 1 of 1 (latest)

fleet cave
#

Hi ๐Ÿ‘‹

#

@sick hound please discuss your issue in this thread here

sick hound
#

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

fleet cave
#

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?

sick hound
#

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

fleet cave
#

And when you are running on localhost are you using stripe listen?

sick hound
#

correct

fleet cave
#

And you've registered a separate webhook endpoint for your heroku deployment?

sick hound
#

yes

fleet cave
#

And the Heroku deployment shows the correct secret for that endpoint, not the local listener?

sick hound
#

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?

fleet cave
#

Yeah, those issues are usually due to secrets not matching.

#

Hmmm ๐Ÿค”

sick hound
#
app.use(express.urlencoded({ extended: true }));
app.use(cors());
app.options("*", cors({ origin: true }));```
fleet cave
#

Anything that performs any kind of transformation on the data payload will invalidate the signature

#

The signature verification process needs the raw body

sick hound
#

hmmm ok ill try removing my middlewares and seeing if it works

fleet cave
#

I hope it's that straightfoward

sick hound
#

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?

fleet cave
#

Do you mean when the payload is used in the constructEvent function call?

sick hound
#

yes

fleet cave
#

I suspect as JSON

sick hound
#

....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

fleet cave
#

You got it?

#

Where was the issue?

sick hound
#

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

fleet cave
#

That is interesting. I haven't built many apps with Express so this is a useful troubleshooting step.

sick hound
#

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

fleet cave
#

I think I was just the rubber duck in this case but I

#

am happy to help ๐Ÿ™‚

sick hound
#

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

fleet cave
#

๐ŸŽ‰