#evh5150_subscription-end-trial-invoice

1 messages ยท Page 1 of 1 (latest)

wintry waspBOT
#

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

fiery bloom
#

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

jolly parcel
#

Yes, they click a button and we need to charge them for the subscription and end the trial

fiery bloom
#

Or you can look at the latest_charge

jolly parcel
#

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

fiery bloom
#

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.

wintry waspBOT
jolly parcel
#

The problem I have is payment_intent is null for the subscription

deft juniper
#

Hi ๐Ÿ‘‹

I'm stepping in as my colleague had to go

Do you have an example Invoice ID I can review?

jolly parcel
#

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

deft juniper
#

Got it. Where is the failing transaction where their card is declined?

jolly parcel
#

It's very simple. They click a button in my web app, then it calls a c# method where I update it

deft juniper
#

WHere is the API request ID where the card is declined?

jolly parcel
#

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

deft juniper
#

Okay and that request generates and Invoice, right?

#

At what point do you receive an invoice.payment_failed webhook?

jolly parcel
#

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

deft juniper
#

Can you share the Request ID for a recent request where you updated the Subscription using the code you just shared?

jolly parcel
#

one sec

#

I believe this one but I can try it again

deft juniper
#

Still needing that request ID. It will start with req_

#

Just ID also, the URL isn't useful for me

jolly parcel
#

Where would I find that?

deft juniper
jolly parcel
#

Thanks, I guess it's this: req_Hxlck9wkJaTl25

deft juniper
#

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

jolly parcel
#

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

deft juniper
#

Invoices automatically created always default to waiting 1 hour for finalization

jolly parcel
#

So, what is the easiest way to convert a user trial and charge them immediately?

deft juniper
jolly parcel
#

So , end the trial and then call this?

deft juniper
#

Yes. You can listen for the invoice.created webhook event and respond by finalizing it

jolly parcel
#

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?

deft juniper
#

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

jolly parcel
#

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

deft juniper
#

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

jolly parcel
#

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?

deft juniper
#

Did you finalize the invoice you shared with me?

jolly parcel
#

I haven't changed any code yet

deft juniper
#

The invoice is set to charge_automatically. So once it is finalized, Stripe will attempt to charge the saved payment method

jolly parcel
#

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

deft juniper
#

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

jolly parcel
#

oh @#$

#

LatestInvoice is still null

deft juniper
#

Can you share the subscription id?

jolly parcel
#

sub_1Qi21iIYqz1HSjbtCuAOFJn4

deft juniper
#

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

jolly parcel
#

hmm, ok, I've never used Go so I'm not sure

deft juniper
#

Well that might make any kind of integration building harder

#

But let me see if I can find some code snippets on our site

jolly parcel
deft juniper
jolly parcel
#

ah

deft juniper
#

Okay alternate approach
can you try adding

jolly parcel
#

Thanks, I will try that. I must go but appreciate your help

deft juniper
#

Sure thing.