#beastboy_code

1 messages ยท Page 1 of 1 (latest)

lucid summitBOT
#

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

๐Ÿ“ 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.

upbeat pier
#

await stripe.subscriptions.update(subscription.id, {
items: [
{
id: subscription.items.data[0].id,
price: new_price_id,
},
],
proration_behavior: 'none',
add_invoice_items: [
{
price_data: {
currency: 'USD',
product: product_id,
unit_amount: -oldPrice.unit_amount,
},
},
],
});

#

Test request ID:
req_evbstcscqrnc1H

Prod Request ID: req_P9V0veVE8tQVNK

waxen drift
#

Okay I'm confused. In both requests you update a Subscription and include a one-off invoice item for a negative amount.

#

In both cases, an invoice is generated and immediately paid

#

due to proration_behavior: "none"

#

What part is unexpected for you?

upbeat pier
#

No not true, in prod an invoice is generated here after running that request

in_1QfrMIDyFtOu3ZuTbLVVI4zv

#

I had to manually reset the billing cycle of the subscription such that the user gets billed for the new product - the negative amount here:

in_1QfrUbDyFtOu3ZuTbTVEiTze

#

After running the code in prod, the only thing that happened was generating that negative invoice

waxen drift
#

Ah the amount for the second line item is 0 on the prod invoice.

#

The product description suggests this is a free trial period

#

description: "Trial period for Semaglutide Multi-Month - 15mg (5 mg, 5 mg, 5 mg)",

lucid summitBOT
upbeat pier
#

I see

#

so if it is trialing, how do I get it to perform the behavior I want to? Pass in trial_end: true?

waxen drift
#

trial_end takes either a timestamp or the string "now". I think "now" would get you the behavior you want

#

But I recommend you code a simulation in Test mode and be sure to include the trial period so you match production behavior

upbeat pier
#

Got it

#

So I totally missed this 'case' when I was testing

#

If they're on a trial or not

#

Can you think of any more cases I could have missed?

waxen drift
#

I recommend just ensuring that you use the exact same parameters between test and live mode for susbcription creation when testing the impact of different updates

upbeat pier
#

I see okay.

#

Thank you

waxen drift
#

Happy to shed what ๐Ÿ’ก I can ๐Ÿ™‚

upbeat pier
#

For this code:

await stripe.subscriptions.update(stripeSubscription.id, {
items: [
{
id: stripeSubscription.items.data[0].id,
price: new_price_id,
},
],
billing_cycle_anchor: 'now',
proration_behavior: 'always_invoice',
payment_behavior: 'pending_if_incomplete',
proration_date: stripeSubscription.current_period_start,
trial_end: 'now',
});

#

for this request id: req_RuKsN7Q0XK2qOo

#

Why did it not charge the user the difference between the 2 products? And how do I get it to?

waxen drift
upbeat pier
#

Yes but the intent was to charge the difference between the current product the user is on and the new product its switching to

#

This just charges the price of the full product.

#

Normally this code works for this (but w/o a sub schedule attached to it I believe)

waxen drift
#

But they hadn't paid previously, because it was a free trial, right?

upbeat pier
#

Ahh I see

#

I put it on a free trial to extend the subscription out a couple days

#

How do I account for that?

waxen drift
#

Sorry but this is your business logic so I cannot really provide more advice. I think you should take a step back and review what it is you are ultimately trying to do.

#

I have to step away but my colleague @cerulean zealot will be able to assist with further questions.

upbeat pier
#

I mean if the subscription is on a free trial, how do I still upcharge it for the difference between the two produfts?

#

thank you for your help!

cerulean zealot
#

You can add a one time invoice item with add_invoice_items that charges the user before the trial starts

upbeat pier
#

In a seperate request before this?

#

or can do in the same sub update request

cerulean zealot
#

You can do it on the create or update invoice calls

upbeat pier
#

Wait im confused

#

So before running the subscription update code, I make a new call to update / create the invoice?

cerulean zealot
#

Basically add_invoice_items is our parameter for adding one time charges that get billed along with your recurring charges. If you add invoice items to a subscription that is trialing, we will charge only the one-off fee upfront