#seor_webhooks

1 messages ¡ Page 1 of 1 (latest)

cyan cloudBOT
#

👋 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/1397167745824587839

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

latent jacinth
#

hi there!

#

i tried to trigger via stripe cli the invoice.payment_failed but i did not succeed
what do you mean by "it did not suceed"? what's the issue exactly?

#

when I type stripe trigger invoice.payment_failed, I do get the event generated

muted wasp
#

hello, i get the event generated but not for the customer i need

#

i don't know how to ovverride the customer value and also how to attach a failing payment method in order to trigger the invoice.payment_failed event

#

e,g, i ran this command:
stripe trigger invoice.payment_failed --override payment_method:customer="cus_SitR4T1wjSUMwZ" --override invoiceitem:customer="cus_SitR4T1wjSUMwZ" --override invoice:customer="cus_SitR4T1wjSUMwZ"

#

the cli says everything is good but on the UI dashboard or in the webhook local logs i see no such event

latent jacinth
#

I just copy pasted your code, and replaced your cus_xxx ID with my own customer ID. and I did receive a invoice.payment_failed for the correct customer.

cyan cloudBOT
drifting kite
#

When you run stripe trigger ... does it emit a evt_xxx ID? Can you share it?

muted wasp
#

here we go

drifting kite
#

Please just paste the ID

muted wasp
#

it does not emit any event id
it just states that the command was executesd

#

it says check dashboard for event detail but i can't see any

drifting kite
#

Yes it does, they're right there in the bottom half of the screenshot

muted wasp
#

but those are older events, from other commands

#

not this one

#

the hours is 2h ago as you can see

#

those are events triggered by my application flow

#

i need to test only invoice.payment_failed

drifting kite
#

Can you just share one of the IDs please

muted wasp
#

evt_1RnclHKKWf9Suo5241Oi4V1l

drifting kite
#

evt_1RnclHKKWf9Suo5241Oi4V1l was generated via the CLI, not your application flow

#

Any chance you're authenticated on different accounts in the CLI between the sessions/windows?

muted wasp
#

nope, not a chance

#

only have one account

#

and it is in test mode

muted wasp
#

and all the others are sent and received correctly by my handler

drifting kite
#

Yes, because your endpoint is returning a 400 error

#

You need to add some code/logs to your handler to debug why

muted wasp
#

export const getWebhookAction = async ( action: StripeWebhookAction, input: Stripe.Event.Data.Object, ) => { switch (action) { case "customer.subscription.updated": return handleUpdateCustomerSubscription(input as Stripe.Subscription); case "customer.subscription.deleted": return handleDeleteCustomerSubscription(input as Stripe.Subscription); case "checkout.session.completed": return handleCheckoutSessionCompleted(input as Stripe.Checkout.Session); case "invoice.payment_failed": return handleInvoicePaymentFailed(input as Stripe.Invoice); default: break; } };

#

that's my switch case handler

#

so either the name of the event i'm handling is incorrect or i don't know

drifting kite
#

Does it reach the handleInvoicePaymentFailed function? Add some logging to that

muted wasp
#

it does not reach unfortunately

#

logger.info("WEBHOOK - INVOICE.PAYMENT_FAILED"); const { status, customer: invoiceCustomer } = invoice; logger.info(invoice is in status: ${status});

#

those are the first lines of the function called

#

and there are no such logs

drifting kite
#

OK, so where in the webhook handler do you return a 400?

muted wasp
#

on the controller level here

#

export async function StripeWebhookController( req: express.Request, res: express.Response, ) { logger.info(WEBHOOK_HANDLER_STARTED @${new Date().toLocaleString()}`);
const signature = req.headers["stripe-signature"];
try {
const event = stripeClient.webhooks.constructEvent(
//@ts-ignore
req.rawBody,
signature!,
res.locals.stripeWhSec,
);

    await getWebhookAction(
        event.type as StripeWebhookAction,
        event.data.object,
    );

    res.status(200).send();
    return;
} catch (error: any) {
    logger.error(error);
    res.status(400).send(`Webhook error: ${error.message}`);
}`
drifting kite
#

And what does logger.error(error) print? I would guess your secret is the wrong one. Are you using the one that the CLI emits when you start stripe listen?

drifting kite
muted wasp
#

i checked stripe whsec from cli and it's the same in my env file

#

it's not wrong

drifting kite
#

You need to help me out here and share the actual error thrown in your catch block. I'm flying blind