#yadulla malik shaik

1 messages · Page 1 of 1 (latest)

atomic galeBOT
cold tulip
#

Hi, what's the question?

empty ravine
#

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

cold tulip
#

Is your question why all three cases are being executed? Do you see all console logs being printed?

empty ravine
#

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

cold tulip
#

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.

empty ravine
#

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.

cold tulip
#

As you see these are 3 different events.

empty ravine
#

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

cold tulip
#

Could you please give more context on this: "when i try giving eventType as invoice.paid statically then im getting error"?

#

What error?

empty ravine
#

in dashboard getting this error when
const eventType="invoice.paid"

#

i want to invoke a function when invoice is paid after one month interval

cold tulip
#

What's the error?

#

I understand. The error happens in your application. Do you see any messages in your console?

atomic galeBOT
empty ravine
#

no error on console

cold tulip
#

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.

empty ravine
#

what are the possible reasons im getting 3 diff id for event

white hedge
#

What 3 IDs are you getting for this event?

empty ravine
#

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.

white hedge
#

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

empty ravine
#

when i try to invoke the function from invoice.paid case, it is not working

white hedge
#

Is this a Stripe API call for a credit note? Or is this credit within your own system?

empty ravine
#

it is my own function api call

white hedge
#

If you add a print statement inside of your call, does it get printed when you get the event?

empty ravine
#

yes, console is getting printed

white hedge
#

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.

empty ravine
#

when i call the same function inside checkout.sessoin.completed, function call is working, only not working in invoice.paid case

white hedge
#

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

atomic galeBOT
empty ravine
#

got any solution?

half moss
#

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

empty ravine
#

im trying to use the test clock api where should i call the test clock in api

half moss
empty ravine
#

im reading this doc, but im confused where to use the testclock

half moss
#

Which part is confusing? Your question needs to be more specific. That guide tells you all the steps you need