#beastboy_code
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/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.
- beastboy_subscription-updates-manual-prorations, 3 days ago, 113 messages
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 customer where it behaves correctly:
https://dashboard.stripe.com/test/customers/cus_RQhOliXJ9gWQEW
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Prod customer where it doesnt:
https://dashboard.stripe.com/customers/cus_QnnSB9gPBiWJzm
Notice how it creates an invoice for the invoice item, and then I had to manually renew the customer's billing cycle so that they get charged appropriately
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Test request ID:
req_evbstcscqrnc1H
Prod Request ID: req_P9V0veVE8tQVNK
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?
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
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)",
I see
so if it is trialing, how do I get it to perform the behavior I want to? Pass in trial_end: true?
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
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?
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
Happy to shed what ๐ก I can ๐
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?
That request generated an invoice for 102492 which was paid here: https://dashboard.stripe.com/test/events/evt_1QgstODyFtOu3ZuTg6elTxnd
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)
But they hadn't paid previously, because it was a free trial, right?
Ahh I see
I put it on a free trial to extend the subscription out a couple days
How do I account for that?
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.
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!
You can add a one time invoice item with add_invoice_items that charges the user before the trial starts
You can do it on the create or update invoice calls
Wait im confused
So before running the subscription update code, I make a new call to update / create the invoice?
No, this is being passed into the creation or update call
https://docs.stripe.com/api/subscriptions/create#create_subscription-add_invoice_items
https://docs.stripe.com/api/subscriptions/update#update_subscription-add_invoice_items
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