#yadulla malik shaik
1 messages · Page 1 of 1 (latest)
Hi, what's the question?
async function handleEvent(event, req, res) {
const eventType = event.type;
const eventData = event.data;
switch (eventType) {
case "checkout.session.completed":
console.log("Payment is successful and the subscription is created.");
break;
case "invoice.paid":
console.log("Payment is successful and the subscription is renewed.");
break;
case "invoice.payment_failed":
console.log("Payment has failed.");
break;
default:
console.log("Unhandled event type:", eventType);
}
}
these are the switch cases im using, when i did a payment, all three cases are consoling why
Is your question why all three cases are being executed? Do you see all console logs being printed?
Payment has failed.
Payment is successful and the subscription is created.
Payment is successful and the subscription is renewed.
im getting 3 switch cases consoling
Can you print out the event ID too?
You might be getting three different webhook events.
I can see why the first 2 are printed - when you complete checkout you also pay the invoice. However, I the payment failure doesn't seem to be related.
event: evt_1NEXUZSItyvlXDXEtaC1MiU3
Payment has failed.
event: evt_1NEXUeSItyvlXDXEVKT5difj
Payment is successful and the subscription is created.
event: evt_1NEXUeSItyvlXDXEm4MMP5MH
Payment is successful and the subscription is renewed.
As you see these are 3 different events.
im getting 3 diff id's
i want to check invoice.paid case, when i try giving eventType as invoice.paid statically then im getting error why, how to check only for invoice.paid
Could you please give more context on this: "when i try giving eventType as invoice.paid statically then im getting error"?
What error?
in dashboard getting this error when
const eventType="invoice.paid"
i want to invoke a function when invoice is paid after one month interval
What's the error?
I understand. The error happens in your application. Do you see any messages in your console?
no error on console
Could you please try to debug to see where is the error coming from? Your app is responding with status 400 to Stripe webhook event notification.
what are the possible reasons im getting 3 diff id for event
What 3 IDs are you getting for this event?
inside the webhook im using switch case, there are 3 diff cases, and all are printing. so, i tried to print event.id then im getting 3 diff id's
so i want to why im getting 3 diff id's
i want to increase credits to a user when subscription is done every month, so, according to this "I can see why the first 2 are printed - when you complete checkout you also pay the invoice.", i can invoke a function to increase credits inside invoice.paid case.
Can you send me the 3 event IDs that you are seeing (evt_123)?
Oh I see the message above
Yes in this case it would make sense to credit the user from the invoice.paid event
when i try to invoke the function from invoice.paid case, it is not working
Is this a Stripe API call for a credit note? Or is this credit within your own system?
it is my own function api call
If you add a print statement inside of your call, does it get printed when you get the event?
yes, console is getting printed
Gotcha, unfortunately I can't consult on non-Stripe code so I think you will need to step through your code to see where the call is failing or not doing the thing that you are expecting it to.
when i call the same function inside checkout.sessoin.completed, function call is working, only not working in invoice.paid case
Interesting, unfortunately not sure why that would be. If you aren't making Stripe calls then it is still likely something in your code that is causing this. It is possible that there is something slightly different happening in your environment when you process each of those calls. Stepping through that function for both cases would be a good way to learn why it is working in one case but not the other
got any solution?
Recommend doing what my colleague suggested: Stepping through that function for both cases would be a good way to learn why it is working in one case but not the other
im trying to use the test clock api where should i call the test clock in api
Not sure I understand the question. Recommend following this guide: https://stripe.com/docs/billing/testing/test-clocks
im reading this doc, but im confused where to use the testclock
Which part is confusing? Your question needs to be more specific. That guide tells you all the steps you need