#evh5150_subscription-end-trial-invoice
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/1329563769440964749
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hello
You are updating the Subscription to end the trial?
If so, you can expand the latest_invoice.payment_intent to get information about the PaymentIntent
If succeeded then you know it was successful, otherwise you can look at last_payment_error: https://docs.stripe.com/api/payment_intents/object#payment_intent_object-last_payment_error
Yes, they click a button and we need to charge them for the subscription and end the trial
Or you can look at the latest_charge
What if their card is declined?
I have no problem if everything is perfect, but, if their card doesn't have enough funds or is declined there is no way to know
I just told you how to know -- you expand the latest_invoice.payment_intent and you will receive info about what happened with the PaymentIntent in your Subscription Update request's response.
If you aren't familiar with expansion then take a read through https://stripe.com/docs/expand
The problem I have is payment_intent is null for the subscription
Hi ๐
I'm stepping in as my colleague had to go
Do you have an example Invoice ID I can review?
Yes, in_1Qi0w1IYqz1HSjbtje9ERvod
It's the test card that is approved but then doesn't have enough funds to complete the full subscription price.
Basically, I'm just trying to convert a trial into a paid subscription AND handle if their card is declined. Seems so simple but even after years of working on the stripe api this is a mystery to me
Got it. Where is the failing transaction where their card is declined?
It's very simple. They click a button in my web app, then it calls a c# method where I update it
WHere is the API request ID where the card is declined?
var subscription = await subscriptionService.GetAsync(user.StripeSubscriptionId); // Get the current subscription
// End the trial immediately by setting trial_end to the current time
var options = new SubscriptionUpdateOptions
{
TrialEnd = DateTime.UtcNow, // End trial immediately
};
subscriptionService.Update(user.StripeSubscriptionId, options); // Apply the update
Okay and that request generates and Invoice, right?
At what point do you receive an invoice.payment_failed webhook?
I need to get an immediate response so I can return the answer to the user
When I run that the Latest Invoice is always null
Can you share the Request ID for a recent request where you updated the Subscription using the code you just shared?
Still needing that request ID. It will start with req_
Just ID also, the URL isn't useful for me
Where would I find that?
Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
Thanks, I guess it's this: req_Hxlck9wkJaTl25
Thanks, taking a look
This invoice doesn't appear to have finalized. It won't have a Payment Intent until then
It was created 33 minutes ago so it should finalize in another 27 minutes or so
yeah that's where I'm totally confused. My customer wants to update immediately but I have to wait an hour to see if it processes successfullly? THere has to be an easier way to do this simple task async
Invoices automatically created always default to waiting 1 hour for finalization
So, what is the easiest way to convert a user trial and charge them immediately?
You can speed this up by calling the /finalize API for the invoice. https://docs.stripe.com/api/invoices/finalize
So , end the trial and then call this?
Yes. You can listen for the invoice.created webhook event and respond by finalizing it
See that's what I mean. Why is this so complilcated? Use clicks a button and I try to do the work BUT I have to do the work, wait for my webservice to do something in a completely different process before I can proceed?
Why is this so complilcated?
Because your use case, while it may be straight forward to you, is one of 100K we are trying to enable and sometimes we have to go for the unhappy middle ground to enable all of them.
For what it's worth, I can put in a feature request to allow you to configure your invoices to finalize immediately
Really, that's very hard to believe. No other company wants the user to convert BEFORE the trial ends? The user experience is very bad if you can't tell them immediately what is going on
You made the request to end the trail at 2025-01-16 21:49:00 UTC
The invoice.created event fired at 2025-01-16 21:49:05
But I have to wait an hour for a response OR call Finalize but it only returns: Returns an invoice object with status=open. What does that even mean?
I'm assuming I'll need to make yet ANOTHER call to get some sort of a status of the attempted payment?
Did you finalize the invoice you shared with me?
I haven't changed any code yet
The invoice is set to charge_automatically. So once it is finalized, Stripe will attempt to charge the saved payment method
I'm going to try the call again
How do I finalize the invoice? I can't find it.
var subscription = await subscriptionService.GetAsync(user.StripeSubscriptionId); // Get the current subscription
// End the trial immediately by setting trial_end to the current time
var options = new SubscriptionUpdateOptions
{
TrialEnd = DateTime.UtcNow, // End trial immediately
};
subscriptionService.Update(user.StripeSubscriptionId, options); // Apply the update
var latestInvoice = subscription.LatestInvoice;
latestInvoice is always null
You aren't returning the value from subscriptionService.Update(user.StripeSubscriptionId, options);
You need to assign that to a value. The subscription, when you get it, doesn't have an Invoice
Can you share the subscription id?
sub_1Qi21iIYqz1HSjbtCuAOFJn4
Okay and here is the request where you are ending the trial: https://dashboard.stripe.com/test/logs/req_COVc0IZnKkct8N
I think the problem is that Go is a static typed language so you might need to use .LatestInvoiceId
Because our APIs usually use a kind of polymorphism where we return the ID as a String unless you expand that property and we return the full Invoice object.
Static typed languages are not happy about a property that could be either a String or an Object
hmm, ok, I've never used Go so I'm not sure
Well that might make any kind of integration building harder
But let me see if I can find some code snippets on our site
I've used the stripe.net library probably a decade
Okay, yeah stripe-go is expecting LatestInvoice to be an Invoice object so that won't have the ID as a string https://github.com/stripe/stripe-go/blob/master/subscription.go#L1079
ah
Okay alternate approach
can you try adding
latest_invoice as an expand parameter? https://docs.stripe.com/api/expanding_objects
Thanks, I will try that. I must go but appreciate your help
Sure thing.