#ben_api
1 messages ยท Page 1 of 1 (latest)
๐ 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/1314215311515586622
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
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.
hi there!
when you create a schedule that starts immediately, the first invoice is in draft yes. but you can finalize the invoice yourself with an extra API call if needed.
Ah ok! So the create schedule returns a schedule object. What endpoint am I calling to finalise the invoice?
Or i suppose a better question is, how do i get the invoice_id from the schedule? As it doesnt look like this is included in the response
the schedule contains a subscription, and the subscription contains a latest_invoice. note that you can use expand to retrieve all of these objects in a single API call: https://docs.stripe.com/expand
then, to finalize the invoice, call this endpoint: https://docs.stripe.com/api/invoices/finalize
man i wish I had known this sooner lol. Do you know how many API calls I could reduce ๐คฃ
So for a scheudle I need to call ['expand' => 'subscription'] ?
Or is there something I can expand to get the invoice?
And presumbly I can do this when creating a subscripiton too? So for example, if I wanted to get the charge when I create a sub, how can i do this?
So for a scheudle I need to call ['expand' => 'subscription'] ?
yep, that will contain the Subscription object, which does contain the Invoice ID inlastest_invoice
is it possible to get the invoice object directly?
And presumbly I can do this when creating a subscripiton too?
yes you can use expand when creating/updating/retrieving objects
is it possible to get the invoice object directly?
then it would be['expand' => 'subscription.latest_invoice']
why did i not know this
And what about getting the charge? Is it that possible when creating a sub?
it depends. if you are creating a Sub and the customer already has a payment method to charge, then yes you should be able to get the Charge. It should be in latest_invoice -> payment_intent -> latest_charge.
this would be on the creation of a new sub
currenrlt I rely on the webhook to receive the charge and store it our end, but i have one circumstance (checkout) where I need to return some of the data within. Really want I want here is the invoice_url, so if I can get that from the sub using latest_invoice then that is more than sufficient.
So to recap, I need to expand the schedule to get the latest_invoice, and then calll finalize the invoice via the api.
And in respect to creating a sub without a schedule, similar approach to get the invoice.
thanks soma!
yep. I recommend testing all of this in test mode to make sure it works as you expect.
ofc ty ๐
Is there a list of the related resources anywhere I can refer to? It isnt clear how a charge for example may or may not be related to an invoice
I don't think there's a specific doc or diagram unfortunately, but happy to try and clarify anything
no worries, let me make some test api calls and see what happens!
For clarity, where should the expand go? I had put this in options, but should be in params?
params, the second argument (i.e. not the third argument hash that might have stripe_account or some other request options in it)
there are examples on https://docs.stripe.com/expand?lang=php
ah, ok il try that
Sorry, this is on schedule->create, which the first param to the function is the data array. The second param is options. So this shiould go inside the data array?
yep
roger that
right so I've got it finalizing the invoice now, however it hasnt been charged and is in an imcomplete state. do you know why this might be?
do you have the ID of the schedule or subscription or invoice etc so I can have a look?
but it's probably just the exepcted 1 hour wait on a finalized invoice
yes 2 moments
if you want to process the payment right now you would confirm the Invoice's PaymentIntent on the frontend, or call the Pay Invoice API endpoint. unfortuantly starting a subscription using a schedule is pretty unergonomic and requires a ton of extra steps, and the docs don't really cover it
What im surprised by is thar this doesnt happen when Icall subsription create
in_1QSfrPKCc0YxVqNUQtRkFrp7
yeah because it's a quirk that Schedules work differently and don't finalize the first invoice so they instead use the flow of recurrring invoices where they wait an hour (https://docs.stripe.com/billing/invoices/subscription#subscription-renewal)
Ugh... well, at least i konw this. So i can expand to get the latest invoice from the schedule, then i have to call finalize invoice, then i have to call pay?
I cant skip finalize?
e.g. just call pay without finalizing?
looking at that invoice it's just that really, you can either wait for it to auto advance or manually pay by confirming the PaymentIntent or the Pay Invoice endpoint
So i can expand to get the latest invoice from the schedule, then i have to call finalize invoice, then i have to call pay?
basically yes
: e.g. just call pay without finalizing?
no
Ok not an issue, 3 API calls. This type of checkout product is unsual anyway, its just that we let our users create complex product structures that ultimatley is a schedule that moves a subscription through various stages