#krishna-awate_webhooks

1 messages ยท Page 1 of 1 (latest)

tribal hillBOT
#

๐Ÿ‘‹ 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/1406985927955447842

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

surreal atlas
#

hi there!

loud furnace
#

Hello sir.

surreal atlas
#

can you share more details about what you are trying to do exactly?

loud furnace
#

Im using invoice.payment_succeeded webhook to update my payment status after successful transaction.

#

For one time payment and recurring also.

#

I want below data in that webhook.

  1. Current cycle start date & Next due date.
  2. Subscription start & end date
  3. Paid cycle
  4. Total Cycel
  5. Remaining cycle.
surreal atlas
#

and what's your question/issue?

loud furnace
#

I am nto getting required data in webhook event.

tribal hillBOT
loud furnace
#

Also invoice.payment_succeeded is not working for one time payment.

junior fossil
#

I know that period_end and period_start are on the event. However, most of the other data, you would need to store that data on your end.

As for invoice.payment_succeeded events for one-time payment, can you share an example where you did not get one so I can look? It would start with evt _

loud furnace
#

pi_3RxSqfDBfYojrB0W0gtioiA6 This is payment id where webhook not triggered.

junior fossil
loud furnace
#

For my current API which webhook should I use.

junior fossil
#

You can listen to payment_intent.succeeded or charge.succeeded in this case

loud furnace
#

which one will be best to update payemnt status in databse application payment_intent.succeeded or charge.succeeded ?

junior fossil
#

That is up to you

#

Either works fine

loud furnace
#

Okay.

#

for Invoice.payment_succeeded for recurrng.
is period_end as next due? & period_start as current_cycle_start?

junior fossil
loud furnace
#

Let me check after hitting this

#

I have got

period_end =1755526208
period_start =1755526208

both same.

#

I want next due date. Means current cycle period end date.

junior fossil
#

Can you share the event please?

loud furnace
#

pi_3RxTlEDBfYojrB0W1lYc1UlX

#

sub_1RxTlEDBfYojrB0W97kjoxXC

#

in_1RxTlEDBfYojrB0WkGn2tMtO

junior fossil
#

That is because that is the first subscription. The invoice items started and ended on the same date since it's a new subscription.

#

You could instead look at the line items data:

period: {
end: 1758204608,
start: 1755526208
},

#

It's likely waht you'd want

loud furnace
#

not able to see any object like this
period: {
end: 1758204608,
start: 1755526208
},

junior fossil
#

Are you looking under lines.data?

loud furnace
#

There is no period object.

junior fossil
#

It is under: lines: {object: 'list', data: Array(1), has_more: false, total_count: 1, url: '/v1/invoices/in_1RxTz2DBfYojrB0Wl4sRz400/lines'}

Where are you copying this data from?

loud furnace
#

from debug console

#

using node debugger

#

This is whole invoice item

junior fossil
loud furnace
#

Let me check.

junior fossil
#

Did you see it?

loud furnace
#

Not getting in data

#

In webhook

junior fossil
#

Are you saying you're not seeing it in the Dashboard for that event?

#

Are you still here?

loud furnace
#

Yes.

#

Checking in dashboard

#

const event = req.body;
const eventType = event.type;
const eventData = event.data.object;

console.log(Processing webhook: ${eventType});

try {
switch (eventType) {
// Payment Intent Events
case "payment_intent.succeeded":
await handlePaymentIntentSucceeded(eventData);
break;

  case "payment_intent.payment_failed":
    await handlePaymentIntentFailed(eventData);
    break;

  // Invoice Events (Subscriptions)
  case "invoice.payment_succeeded":
    await handleInvoicePaymentSucceeded(eventData);
    break;

  case "invoice.payment_failed":
    await handleInvoicePaymentFailed(eventData);
    break;

  // Subscription Events
  case "customer.subscription.created":
    await handleSubscriptionCreated(eventData);
    break;

  case "customer.subscription.updated":
    await handleSubscriptionUpdated(eventData);
    break;

  case "customer.subscription.deleted":
    await handleSubscriptionDeleted(eventData);
    break;

  // Refund Events
  case "charge.refunded":
    await handleChargeRefunded(eventData);
    break;

  // Dispute Events
  case "charge.dispute.created":
    await handleDisputeCreated(eventData);
    break;

  default:
    console.log(`Unhandled event type: ${eventType}`);
}

return res.status(200).json({ status: "success" });

} catch (error) {
console.error("Webhook processing error:", error);
return res.status(500).json({ error: "Webhook processing failed" });
}
});

#

This is webhook following.

#

Added

customer.subscription.created
invoice.payment_succeeded
payment_intent.succeeded

this event

tribal hillBOT
gloomy pumice
#

Hi ๐Ÿ‘‹

I'm stepping in as my colleague needs to go

tribal hillBOT
#

๐Ÿง‘โ€๐Ÿ’ป How to format code on Discord

Inline code: wrap in single backticks (`)

This:

The variable `foo` contains the value `bar`.

Will turn into this:

The variable foo contains the value bar.

Code blocks: wrap in three backticks (```)

Also, you can specify the language after the first three backticks to get syntax highlighting.

This:

```javascript
function foo() {
return 'bar';
}
```

Will turn into this:

function foo() {
  return 'bar';
}```

Notes about **code blocks**:
- Specifying the language is optional (e.g., you can omit `javascript` in the example above)
  - If you don't specify the language you won't get syntax highlighting
- When you're inside a code block (after you type \`\`\`) the `Return`/`Enter` key will add a new line instead of sending your message
  - Once you end the code block `Return`/`Enter` works normally again

You can [read more about message formatting on Discord's website.](https://support.discord.com/hc/en-us/articles/210298617)
gloomy pumice
#

Can you clearly state what the exact data is you are not receiving and provide the event ID for the event you are reviewing?

loud furnace
#

I want to get next due date for subscription payment and current cycle start date. Once recurring payment is successed. For that I am using event.

  • invoice.payment_succeeded
gloomy pumice
#

Okay, and the event ID?

loud furnace
#

But I am not getting that data

#

in_1RxTz2DBfYojrB0Wl4sRz400

gloomy pumice
#

That's an Invoice ID but okay

loud furnace
#

we_1RrLPlDBfYojrB0WyrzvywFD

gloomy pumice
#

That's also not an event ID. But it's okay, I have what I need.

loud furnace
#

Okay

gloomy pumice
#

FYI I don't see a success response being sent back by your webhook endpoint, so we keep trying to deliver this webhook event

loud furnace
#

"period": {
"end": 1758205464,
"start": 1755527064
},

this event has

gloomy pumice
#

Yup, that defines the billing period

loud furnace
#

but nto getting in my event console

#

in code

gloomy pumice
#

What do you mean by "my event console"? Where is that logged?

loud furnace
#

case "invoice.payment_succeeded":
await handleInvoicePaymentSucceeded(eventData);
break;

#

i am getting eventData

#

in this data not getting that period object.

gloomy pumice
#

Can you tell me the API version for your webhook enpoint?

loud furnace
#

How can I check.

gloomy pumice
#

You can see it in your dashboard

loud furnace
#

exact location.

#

2022-11-15

gloomy pumice
#

And what is in the lines parameter in the eventData object?

loud furnace
#

I din't get what exaclty

gloomy pumice
#

As you can see, we are sending the correct data that includes the period in the payload. This is what you say in that dashboard link. However, there appears to be some incorrect handling in your NodeJS code

#
case "invoice.payment_succeeded":
        // Try adding this to your code
        const period = eventData.lines[0].period
        console.log(period)
        await handleInvoicePaymentSucceeded(eventData);
        break;
#

Can you test out making the modifications I just added and trigger a test Event?

stripe trigger invoice.payment_succeeded
loud furnace
#

Okay.

#

Okasy

#

Webhook processing error: TypeError: Cannot read properties of undefined (reading 'period')

#

I think there is no line object

gloomy pumice
#

Okay so that sounds like the lines data isn't being included, which seems odd

#

since we definitely send that data

loud furnace
#

How can I get that.

gloomy pumice
#

We are sending it so that is where I'm confused.

#

Can you try logging the lines? console.log(eventData.lines)

loud furnace
#

Okay

#

{
object: 'list',
data: [
{
id: 'il_1RxVs8DBfYojrB0WJZi0O1MU',
object: 'line_item',
amount: 20900,
amount_excluding_tax: 20900,
currency: 'inr',
description: '1 ร— Test Product (at โ‚น209.00 / month)',
discount_amounts: [],
discountable: true,
discounts: [],
invoice: 'in_1RxVs8DBfYojrB0WYrTi6R4g',
livemode: false,
metadata: {},
parent: [Object],
period: [Object],
plan: [Object],
pretax_credit_amounts: [],
price: [Object],
pricing: [Object],
proration: false,
proration_details: [Object],
quantity: 1,
subscription: 'sub_1RxVs8DBfYojrB0Wt3vwEdne',
subscription_item: 'si_StITYPSZpGUhIV',
tax_amounts: [],
tax_rates: [],
taxes: [],
type: 'subscription',
unit_amount_excluding_tax: '20900'
}
],
has_more: false,
total_count: 1,
url: '/v1/invoices/in_1RxVs8DBfYojrB0WYrTi6R4g/lines'
}

gloomy pumice
#

Okay so you do have the lines and we can see there is a period

#

So let's update our code

#
case "invoice.payment_succeeded":
        // Try adding this to your code
        const period = eventData.lines.data[0].period
        console.log(period)
        await handleInvoicePaymentSucceeded(eventData);
        break;
#

Try this and see if that works

loud furnace
#

Okay I will check.

loud furnace
#

Yes I am gettng it now

gloomy pumice
#

Okay great!

#

So we know the data is there and you have access to it. Now you can revise your code to extract the period from the eventData and use it

loud furnace
#

Yes sir.

#

I have another query

#

I want to test payment failure webhook. How can I do that?

gloomy pumice
loud furnace
#

For one time payment success I am using ** payment_intent.succeeded**

#

For recurring **invoice.payment_succeeded **

#

Do I have to use seperate webhook for failure for recurring and onte time payment?

gloomy pumice
#

No

#

Your code just needs to handle those types of events correctly

loud furnace
#

why one time payment are not captured in invoice.payment_succeeded webhook

gloomy pumice
#

Not all payments generate Invoices

#

Are you referring to one-time payments that were created from an Invoice?

#

How are your one-time payments being generated?

loud furnace
#

Payment intent

tribal hillBOT
gloomy pumice
#

right, so there is no Invoice

#

We would not send invoice.payment_succeeded events because the Payment Intent isn't related to an Invoice

loud furnace
#

Okay got it.

#

paid_cycle
remaining_cycle
total_cycle
subscription_start
subscription_end

Can I get above data from invoice?

finite finch
#

Hi there. I'll be taking over for Snufkin here, who needed to step away

loud furnace
#

Okay

#

Can you please help me to get this data from invoice webhook

paid_cycle
remaining_cycle
total_cycle
subscription_start
subscription_end

finite finch
#

I'm sorry this looks like some Invoice parameters and some Subscription parameters.

Have you tried testing webhook events to understand what information you receive from them?

https://docs.stripe.com/billing/testing#webhooks

Invoice webhooks - such as invoice.payment_succeeded will give you a copy of the Invoice object. If you need the Subscription as well, there are Subscription events, or you can retrieve the Subscription that created the Invoice (if there is one) by looking at the Invoice's parent

https://docs.stripe.com/api/invoices/object#invoice_object-parent-subscription_details-subscription

loud furnace
#

I have checked this but not getting

  • subscription_start
  • subscription_end
#
  • paid_cycle
    -remaining_cycle
  • total_cycle
finite finch
#

In order to help you, I need you to be more specific. What does "I have checked this" mean? What did you check? In detail, please.

loud furnace
#

I have got invoice object in webhook event. invoice.payment_succeeded

#

In that object I checked each params

#

But did not get required data.

finite finch
loud furnace
#

Okay got it.

#

How can I hit failure webhook.

#

I tried failure card but not hitting webhook.

#

Only showing UI error.

finite finch
#

well, the simplest way is probably to just use the CLI to trigger the event you want

#

but you could also use the "decline after attaching" 0341 test card here

loud furnace
#

4000 0000 0000 0341

Tried this but givign UI error only. Not hitting webhook

finite finch
#

For simplicity's sake can I suggest the Stripe CLI approach I mentioned?

loud furnace
#

We were unable to generate the requested SDK snippet.
Ensure that you've included all required parameters.

finite finch
#

Unfortunately, that doesn't tell me anything about what you did do and why it didn't work

loud furnace
#

I am not able to use CLI for it

#

is there any other way to make payment fail.

finite finch
#

why aren't you able to use the CLI?

Yes, there's another way to make the payment fail. You just need to create a Customer, create/confirm a SetupIntent with the 0341 card, set the resulting payment method as the Customer's invoice_settings.default_payment_method, and then create an Invoice for that Customer and pay it. The payment will fail

loud furnace
#

Okay. I will check.

#

I need to log off. Will check tomorrow.

#

Thank you sir for your help.