#asittingduck_api
1 messages ¡ Page 1 of 1 (latest)
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- asittingduck_api, 46 minutes ago, 61 messages
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can 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/1250509099880284273
đ Have more to share? Add details, code, screenshots, videos, etc. below.
You would create a new Invoice Item for the Invoice: https://docs.stripe.com/api/invoiceitems/create
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
So my collection webhook requests that i got when a customer uses the payment link to start their subscription and pay first payment of the installment plan includes a bunch of invoice objects, but i never saw one that said "draft" just a few "paid" and "open"
For the first Invoice on a Subscription, you need to make sure you have all your items added to the Subscription before the invoice is created. Each Invoice created after that will have a 1 hour window where it can be updated after creation, so you would listen for invoice.paid webhooks and make updates then if you needed to
Right so I can record invoice paid, but you know what, here I have my source so you can see my logic thus far
import StripeEvent from '@/lib/mongo/model/StripeEventsModel'
import Installment from '@/lib/mongo/model/InstallmentsModel'
export const POST = async request => {
const data = await request.json()
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY)
// only worry about if the event is an invoice event
if (data.object !== 'invoice') {
return Response.json({ message: 'Webhook received' }, { status: 200 })
}
const eventRes = await StripeEvent.create(data)
const installmentRes = await Installment.findOne({ customer: data.customer })
if (installmentRes.length > 0) {
const { history } = installmentRes
// if there are more than two payments in the history, simply return the response as is
if (history.length > 2) {
// get the request and save it to the database
return Response.json({ message: 'Webhook received' }, { status: 200 })
} else if (history.length === 1) {
// add a new line item to the invoice if the event is invoice.created
} else {
// if there are two payments in the history, then no need to add a new line item
return Response.json({ message: 'Webhook received' }, { status: 200 })
}
}
return Response.json({ message: 'Webhook received', eventRes }, { status: 200 })
}
I'm not really sure what to do with this. Is there a question here somewhere?
I need to know when i need to send the request to add a line item. For example, if the invoice status is paid... then I am too late to adjust it right?
correct
What does a webhook request look like when the invoice is for a subscription in say its second payment cycle
The Invoice will remain in draft for an hour after the webhook is received, so you'd receive an Invoice object in draft1
so the "status" prop will be "draft" or what?
The payload for invoice.paid is an Invoice object. The Invoice has a status: https://docs.stripe.com/api/invoices/object#invoice_object-status
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
But yes, it will be draft
So if I were to set up a webhook to sent to my api with invoice.created, if the invoice is set to draft, then it would be appropriate for my program to analyze the invoice and check the history on the app database to see if the line item should be added and if it should, add the line item?
request prop of status is "draft" I mean
Yup, exactly
ok that is what I needed to make this work thanks