#gassin_webhooks

1 messages ยท Page 1 of 1 (latest)

static cairnBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1308134936531701863

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

light hollow
#

Hi ๐Ÿ‘‹

You said webhook events are failing. Do you have any event ID I can review? They start with evt_

distant prism
#

Sure let me get that for you

#

evt_1QMZ9CBH8SJ1NP7tDjFXWQPm

#

This is the latest one, but they all failed.

#

Obviously this is what we need to ensure that the monthly payment was made so help would be appreciated ๐Ÿ˜† .

light hollow
#

It looks like your webhook endpoint isn't responding to our POST request.

#

You never sent a response back

distant prism
#

That's odd, this is the code for when an API request is made (snippet):

app.post("/api/v1/webhook", async (req, res) => {
    let event = req.body;
    let userId;
    let user;
    switch (event.type) {
        case "invoice.paid":
            console.log("[+] INVOICE PAID EVENT!")
            userId = event.data.object.customer;
            user = await User.findOne({ stripeId: userId }).populate({
                path: "purchasedPackage.package",
                select: "-__v",
            });
            const customer = await stripe.customers.retrieve(userId, {
                apiKey: stripesecret
            });
            if (!user) {
                user = await User.findOne({ email: customer.email }).populate({
                    path: "purchasedPackage.package",
                    select: "-__v",
                });
            }
            user.purchasedPackage.remainingLines =
                user.purchasedPackage.package.lineLimit;
            const now = new Date();
            const futureDate = new Date(now);
            futureDate.setDate(futureDate.getDate() + 30);
            user.purchasedPackage.nextPaymentDue = futureDate;
            await user.save();
            console.log("Paid!");

            break;
#

Does this not constitute a response back?

#

And while we're already here. If a user wants to modify their card details, how can I fetch the external link for them to do so for recurring payments?

light hollow
#

You need to make sure your integration returns a 200 response to our API. It is not doing so currently and you need to figure out why

static cairnBOT
restive scroll
#

I think that customer retrieval request might be missing a param

#

If that's where you get the authentication error, you can try adding an empty params arg:

const customer = await stripe.customers.retrieve(userId, 
  {}, // empty params
  { // options
    apiKey: stripesecret
  }
);
#

And verifying your stripesecret is populated at runtime (don't share any secret key here, though)

#

But as @light hollow noted, you should ensure you respond to the delivery request with a success message before you do any processing on the request data