#ben_api

1 messages ยท Page 1 of 1 (latest)

mighty oreBOT
#

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

cosmic jackal
#

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.

gray sequoia
#

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

cosmic jackal
#

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

gray sequoia
#

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?

cosmic jackal
#

So for a scheudle I need to call ['expand' => 'subscription'] ?
yep, that will contain the Subscription object, which does contain the Invoice ID in lastest_invoice

gray sequoia
cosmic jackal
#

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']

gray sequoia
#

why did i not know this

#

And what about getting the charge? Is it that possible when creating a sub?

cosmic jackal
#

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.

gray sequoia
#

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!

cosmic jackal
#

yep. I recommend testing all of this in test mode to make sure it works as you expect.

gray sequoia
#

ofc ty ๐Ÿ™‚

mighty oreBOT
gray sequoia
#

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

calm totem
#

I don't think there's a specific doc or diagram unfortunately, but happy to try and clarify anything

gray sequoia
#

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?

calm totem
#

params, the second argument (i.e. not the third argument hash that might have stripe_account or some other request options in it)

gray sequoia
#

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?

calm totem
#

yep

gray sequoia
#

roger that

gray sequoia
#

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?

calm totem
#

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

gray sequoia
#

yes 2 moments

calm totem
#

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

gray sequoia
#

What im surprised by is thar this doesnt happen when Icall subsription create

#

in_1QSfrPKCc0YxVqNUQtRkFrp7

calm totem
gray sequoia
#

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?

calm totem
#

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

gray sequoia
#

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