#Daniel M.-webhooks

1 messages · Page 1 of 1 (latest)

round sparrow
#

you can use your Express backend and setup a route there

urban portal
#

Hey, taking over here. Let me know if there's any follow-up Qs I can answer!

vernal cloak
#

Actually yes there are a lot of questions I think haha

#

I´m confused by the docs, because there seem to be so many different "ways" of setting up the end point

#

and I´m really confused on how they work

#

and how to set them up

urban portal
#

Ok, what is it you're actually trying to achieve?

vernal cloak
#

So I want to update my payment status in the database with the webhook

#

so that the users can download their product, as soon as it´s paid

#

before it worked like so ```js
router.post("/webhookMollie", (req, res) => {
updateMolliePaymentStatus(req.body.id, res);
});

#
exports.updateMolliePaymentStatus = (id, res) => {
  // get payment status with id
  mollielient.payments
    .get(id)
    .then(async (response) => {
      // update paymentstatus in db
      const doc = await FileModel.findOne({ paymentId: id });
      doc.paymentStatus = response.status;
      doc.save();
    })
    .catch(() => res.sendStatus(404));
};
#

all I need to do, just with stripe

urban portal
#

There's a full Node example there that will help you get started

vernal cloak
#

hmmm i see, it´s so much more D:
do I need to set up and endpoint secret in local development?

#

or is it just to be safe later on when its live?

#

const stripe = require('stripe')('sk_test_51Ky...) also which key is this?

urban portal
vernal cloak
#

that one

#

also i made this script: "stripewh": "stripe listen --forward-to localhost:4000/stripe_webhooks --skip-verify"

#

installed all dependencies for it, thats the cli you´re talking about right?

urban portal
vernal cloak
#

im only getting 404s from my webhook

#

also is it common, that the webhook is called once when I first run the app?

#

bc I create the intent at the beginning of the app or so?

urban portal
#

Does your stripe_webhooks POST endpoint definitely exist?

vernal cloak
#

it should

#

can stripe reach my localhost or do I have to use something like a tunnel with ngrok?

urban portal
#

Nope, the CLI will be able to reach your localhost (it replaces the need for ngrok or similiar)

vernal cloak
#

hmm okay

urban portal
#

Can you share the code where you define the stripe_webhooks endpoint?

vernal cloak
#

nvm, it works now, forgot to rerun my stripe script after changing routes

#

only restarted the backend

#

my bad

#

but I´ve got another question.
I was told to put the Elements provider at the root level of my app, which means each visitor, even if he doesnt even want to buy something, creates a payment intend... isnt that kinda overkill?

rough crypt
#

it's just how we design the integration, there's no problem having lots of PaymentIntents like that, you only need to look at ones that complete