#mangle8582
1 messages ยท Page 1 of 1 (latest)
Hello! We'll be with you shortly. 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.
- mangle8582, 2 days ago, 36 messages
Hello
Hello
Really the best thing to do is to charge via a one-time item and set a trial
Why don't you want to do that method?
I was thinking that was better if user pays imediately and adds one year on top of monthly that he already paid.
Because otherwise when trial ends, i need to show him a message that he will be charged for yearly at a particular date, i need to show him that it's trial and he didn't paid yet, he will be confused
You can still have them pay immediately and then set the trial for 13 months
With billing_cycle_anchor: 'now', ?
But then if they want a refund for Yearly, he will get the money back?
If it's a trial?
You use the trial to set the billing cycle anchor
It will be moved to whenver the trial ends
billing_cycle_anchor can be 'now' or 'unset' right?
billing_cycle_anchor: 'now',
proration_behavior: 'none',
trial_end: nextBillingCycleEnd
I cannot use billing_cycle_now if trial end is afterwards
Trial end (1734034930) cannot be after billing_cycle_anchor (1699907156)
Correct, you omit billing_cycle_anchor in that case
Any time you set a trial it will automatically set the billing cycle anchor to the end of the trial
Yea, it worked, the endDate looks nice, the thing is that i don't see that the user paid in stripe dashboard in test mode
Correct, because you didn't add an Invoice Item or a one-time Price to charge them
Can you give me link for that or paste some code please?
You create an Invoice Item via https://stripe.com/docs/api/invoiceitems/create
Or just create a one-time Price (https://stripe.com/docs/api/prices/create) and add that to your items when you call your Subscription update
Those are the two options
items: [
{
price
}
]
I'm sending the priceId of yearly into the Subscription Update
Creating an invoice item will automatically charge the user?
Correct, you can send 2 items
Yes if you create an Invoice Item then it will be picked up by the next finalized Invoice
Sorry, what do you mean by 2 items? 2 items in array? that price inside the object is already the priceId of yearly
Yep two different objects within your array. One for each Price (one for the yearly Price and one for the one-time Price)
After i create the price, it can be used only once right?
It won't hang somewhere in Stripe dashboard
Nope, Prices can be used unlimited times
Unless they are archived
A one-time Price means it will only charge the Customer once
Unlike a recurring Price which you use for a Subscription
Oh, i get it and i need to create it each time an user upgrades right? Or create it in dashboard somewhere and use it?
You just have to create it once.
Then you pass that Price ID in your Subscription update request
๐
The price specified is set to type=one_time but this field only accepts prices with type=recurring
Hi there ๐ jumping in as my teammate needed to step away. Please bear with me a moment while I catch up on the context here.
Sure, thanks!
Thank you for your patience, but I think that new error may be different form the rest of the discussion (though related). Can you share the code you're running that encountered that error, or share the ID of the request (req_) that surfaced that error?
items: [
{
price of the annual recurring subscription
},
{
price: 'price_1OC76PDmVlmqORBIachFKg1A'
}
]
const stripePayload = {
payment_behavior: 'pending_if_incomplete',
expand: ['latest_invoice.payment_intent'],
...subscriptionData,
proration_behavior: 'none',
trial_end: nextBillingCycleEnd
};
Is that to create a Subscription? (I don't see the Stripe function you're calling in that snippet)
sub_1OC77RDmVlmqORBIxPdiwHQ4
const updatedSubscription = await stripe.subscriptions.update(
subscriptionId, stripePayload
);
evt_1OC76PDmVlmqORBIULmvxZ8m
I see this event in Webhooks on Test mode local
Ah, Subscription update, got it.
In that case you need to put your one time Price in add_invoice_items , instead of items
https://stripe.com/docs/api/subscriptions/update#update_subscription-add_invoice_items
And keep
items: [
{
price of the annual recurring subscription
},
]
the reccuring one here?
If that price is also being changed, then yes.
What do you mean being changed?
It's the price of the recurring subscription i want to upgrade to.
The add_invoice_items is the one time only to force a imediate payment while i add one year after the end time of the monthly subscription
Also:
const nextBillingCycleEnd = currentSubscription.current_period_end + 365 * 24 * 60 * 60;
Start Date:11/13/2023 11:11 PM
Reactivation Date:12/12/2024 10:52 PM
Now i need to calculate it manually, and i know that invoice is beeing created at the current_period_end and after 1 hour the client starts to be charged for that invoice.
To be on par with stripe logic, what calculations should i do to match it?
I will test with test_clock and add 1 year with moment.js after current_period_end
You said you were updating Subscriptions, but I'm still a bit unclear exactly what you're updating about them, so I wasn't sure if you were also trying to change the Price that the Subscription Item is currently using. If you aren't changing that value, then it doesn't need to be in the update request.
You can't just add 365 days to the timestamp, sometimes years have more days than that and we take that into account.
True, with moment.js seems to work adding one year i think
So I'm trying to update Monthly to Yearly but keep the Monthly time and add 1 year to the 1 month already paid while paying imediately
So i have annual recurring price and i've created one time yearly price with 59.99$ the same as recurring
When i'm updating subscription to yearly i'm calculating with moment.js to add 1 year after monthly current period end. And by adding add_invoice_items, it pays imediately, it adds trial for 1 year and remaining monthly time and all good
Is this okay and reliable?
Yeah, I'm not spotting anything that is a concern with that approach. I would just recommend double checking with Test Clocks that it's behaving exactly as you wish (I recommend that for all Subscription integrations, as they can be complex and seeing the flow can be hugely beneficial).
Sure
Start Date:11/13/2023 11:26 PM
Reactivation Date:12/13/2024 11:16 PM
With moment js with add 1 year
it's 10 minutes behind
Not sure if you had a question you were trying to ask there, but there also appears to be a difference in the Month used there.
Yea, i will try to see if i can manage to do it manually so it will not trigger webhooks before the endtime or something
Is there a way to add this without me setting trial_end unix so i can avoid calculations?
Because i could make a mistake, or miss a case
Not easily, the only other approach that comes to mind is to leverage Subscription Schedules (another type of object that can be used to schedule changs that should be made to a Subscription), but those won't handle the immediate payment requirement well.
Got it, so this is the best solution for me right now