#kennyjack_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/1368866282010710056
📝 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.
- kennyjack_api, 43 minutes ago, 3 messages
- kennyjack_best-practices, 2 days ago, 29 messages
- kennyjack_best-practices, 2 days ago, 54 messages
- kennyjack_best-practices, 4 days ago, 20 messages
$payload = [
"customer" => "cus_xxxxxx"
"schedule" => "sub_sched_1RLJcRArTeYcLw6yXjhKnEoa"
"schedule_details" => [
"phases" => [
[
"start_date" => 1746428400
"end_date" => "now"
"items" => array:1 [
[
"price" => "price_1PmpGcArTeYcLw6yySKT5l4b"
"quantity" => 1
]
]
]
[
"start_date" => "now"
"end_date" => 1777949434 // May 5 2026
"items" => [
[
"price" => "price_1KX0lEArTeYcLw6yla88Vatn"
"quantity" => 1
]
]
]
]
"proration_behavior" => "create_prorations"
"end_behavior" => "release"
]
];
\Stripe\Invoice::upcoming($payload);
Hi, let me help you with this.
In the payload, price_1PmpGcArTeYcLw6yySKT5l4b is Price A and price_1KX0lEArTeYcLw6yla88Vatn is Price C?
Yes
In the payload, price_1PmpGcArTeYcLw6yySKT5l4b is Price A and price_1KX0lEArTeYcLw6yla88Vatn is Price C
Let me know if you need the response from upcoming invoice line data 🙏
Yes, please
"data" => array:3 [▼
0 => array:29 [▼
"id" => "il_tmp_18f51fArTeYcLw6y283b20d9"
"object" => "line_item"
"amount" => -119982
"amount_excluding_tax" => -119982
"currency" => "usd"
"description" => "Unused time on Annual Engage after 05 May 2025"
"quantity" => 1
"subscription" => "sub_1RLJ0OArTeYcLw6yWKJgZpiy"
"subscription_item" => "si_SFodCY8uaSN7ym"
"tax_amounts" => []
"tax_rates" => []
"taxes" => []
"type" => "invoiceitem"
"unit_amount_excluding_tax" => "-119982"
]
1 => array:29 [▼
"id" => "il_tmp_110b8dArTeYcLw6y75b04079"
"object" => "line_item"
"amount" => 269959
"amount_excluding_tax" => 269959
"currency" => "usd"
"description" => "Remaining time on Annual Captivate after 05 May 2025"
"quantity" => 1
"subscription" => "sub_1RLJ0OArTeYcLw6yWKJgZpiy"
"subscription_item" => "si_SFpvRA3xMizw82"
"tax_amounts" => []
"tax_rates" => []
"taxes" => []
"type" => "invoiceitem"
"unit_amount_excluding_tax" => "269959"
]
2 => array:28 [▼
"id" => "il_tmp_122340ArTeYcLw6y75700c42"
"object" => "line_item"
"amount" => 270000
"amount_excluding_tax" => 270000
"currency" => "usd"
"description" => "1 × Annual Captivate (at $2,700.00 / year)"
"quantity" => 1
"subscription" => "sub_1RLJ0OArTeYcLw6yWKJgZpiy"
"subscription_item" => "si_SFpvRA3xMizw82"
"tax_amounts" => []
"tax_rates" => []
"taxes" => []
"type" => "subscription"
"unit_amount_excluding_tax" => "270000"
]
]
My expected output is, shouldn't return me the line.data.2 ("amount" => 270000)
Still looking...
Perhaps the problem is that you're ending the first phase "now"?
Instead of keeping it on until May 5, 2026.
I'm changing the first phase to 1777964400 May 5, 2026
I'm getting error There is a gap between phase 0 (1746428400, 1777964400) and phase 1 `(1746434926, 1777964400)
It's because you're starting the second phase "now" as well. Weren't you planning to start it on May 5, 2026?
In general, you don't need to provide both start_date and end_date for every phase explicitly.
Yes, planing to start the second phase. Because trying to upgrade to second phase by preview the invoice
Weren't you planning to start it on May 5, 2026?
If i don't define every phase, will the proration calculate correctly?
In general, you don't need to provide both start_date and end_date for every phase explicitly.
Proration date doesn't have to do with start_date or end_date, it's defined by https://docs.stripe.com/api/invoices/create_preview#create_create_preview-subscription_details-proration_date
You should just set the first phase end date to May 5, 2026.
Currently, the values are incorrect.
And since you're updating the next phase, and not the current phase, proration date could be the default. I.e. no need to use the parameter I shared.
Can you check if i'm correctly define the payload. I didn't set the start_date anymore
'phases' => [
[
'end_date' => 1777964400, // May 5 2026
'items' => [
[
'price' => 'price_1PmpGcArTeYcLw6yySKT5l4b', // existing
'quantity' => 1,
],
],
],
[
'start_date' => 'now',
'end_date' => 1777964400,
'items' => [
[
'price' => 'price_1KX0lEArTeYcLw6yla88Vatn', // upgrade plann price
'quantity' => 1,
],
],
],
but i get error The subscription schedule update is missing at least one phase with a start_date to anchor end dates to.
Why are you setting start_date=now on the second phase?
I try with don't set on second phase.
I getting error The subscription schedule update is missing at least one phase with a start_date to anchor end dates to.
Question: if i don't set the start date, how does each of phase know when it should start?
Hey! Taking over for my colleague. You need to set a Start date for each phase
my colleague wanted to say that you shouldn't use now for the second phase
the second phase's start date should be the end date of the first phase actually
I see. So if i want to end my first phase and start the second phase immediately
- What end_date i should put in first phase?
- What start_date i should put in second phase?
Ok, i try to put the in future timestamp 1746439005, not using now. But the expected response from stripe invoice is not what i expected.
It same as what i describe start from this message #1368866282010710056 message
Use timestamps yeah
But the expected response from stripe invoice is not what i expected.
Can you share the invoice Id and what are you execpting ?
Yes, i'm using timestamp now
Invoice Id: il_tmp_18f51fArTeYcLw6y283b20d9
My expected output is, shouldn't return me the line.data.2 ("amount" => 270000)
Below is the payload i pass
$payload = [
'customer' => 'cus_SFodjavmyD4P5Z',
'schedule' => 'sub_sched_1RLJcRArTeYcLw6yXjhKnEoa',
'schedule_details' => [
'phases' => [
[
'start_date' => 1746428400,
'end_date' => 1746438339,
'items' => [
[
'price' => 'price_1PmpGcArTeYcLw6yySKT5l4b', // existing
'quantity' => 1,
],
],
],
[
'start_date' => 1746438339,
'end_date' => 1777964400,
'items' => [
[
'price' => 'price_1KX0lEArTeYcLw6yla88Vatn', // upgrade plann price
'quantity' => 1,
],
],
],
],
'proration_behavior' => 'create_prorations',
'end_behavior' => 'release',
],
];
This is the update request Id: req_puAyf6FHLolxGt
The first phase starts today and ends tomorrow
with price price_1PmpGcArTeYcLw6yySKT5l4b
and phase 2, starts next year and ends the year after with price price_1R7DhsArTeYcLw6yl1wAighO
Is this what you wanted to do ?
No no, this req_puAyf6FHLolxGt is not the request i recently send. It was end at 5/5/25, 3:42:08 PM +8
are we discussing this req_puAyf6FHLolxGt or the recent I made?
Give me a moment to clear up. I'm confusing now
I just checked. It shouldn't be that request req_puAyf6FHLolxGt.
I try pass below payload
$payload = [
'customer' => 'cus_SFodjavmyD4P5Z',
'schedule' => 'sub_sched_1RLJcRArTeYcLw6yXjhKnEoa',
'schedule_details' => [
'phases' => [
[
'start_date' => 1746428400,
'end_date' => 1746438209,
'items' => [
[
'price' => 'price_1PmpGcArTeYcLw6yySKT5l4b', // existing
'quantity' => 1,
],
],
],
[
'start_date' => 1746438209,
'end_date' => 1777964400,
'items' => [
[
'price' => 'price_1KX0lEArTeYcLw6yla88Vatn', // upgrade plan price
'quantity' => 1,
],
],
],
],
'proration_behavior' => 'create_prorations',
'end_behavior' => 'release',
],
];
checking this one...
and call this Invoice::upcoming($payload); But when i check on the stripe log, i couldn't find that request ID
It's the same
You should be able to get the request Id from the response header
No this request req_puAyf6FHLolxGt is create subscription_schedules endpoint.
I'm now is preview upcoming invoice
Sorry, but that request (req_puAyf6FHLolxGt) is for updating the Subscirption schedule
Have you had a chance to check it via your Dashboard ?
http://dashboard.stripe.com/test/logs/req_puAyf6FHLolxGt
I've check, couldn't find the log. Is that i'm using legacy upcoming invoice endpoint /v1/invoices/upcoming , that why log not showing up?
No for every APi call, you should have a requestId generated in the response header
Ok, i manage to create the request now. https://dashboard.stripe.com/test/logs/req_MGgp26aWBRB40d
Sorry for taking long time. Can help to take a look?
No worries, checking now...
I got it now, and what you are expecting from that call ?
I'm expecting the response should not return
[▼
"amount" => 270000
"currency" => "usd"
"description" => "1 × Annual Captivate (at $2,700.00 / year)"
"quantity" => 1
]
It should only return unused time & remaining time
[▼
"amount" => -119960
"currency" => "usd"
"description" => "Unused time on Annual Engage after 05 May 2025"
]
[▼
"amount" => 269911
"amount_excluding_tax" => 269911
"currency" => "usd"
"description" => "Remaining time on Annual Captivate after 05 May 2025"
]
What is 'end_date' => 1746438209,
Where does it come from?
are you referring this request req_MGgp26aWBRB40d ?
I don't see i define 'end_date' => 1746438209 in this request req_MGgp26aWBRB40d
But, the end_date i defined is to make the phase ended after few minute from the current time i send the request
No, I looked at the last payload you shared. Looking at the Request now.
I am looking at it and I see:
- phase 1 starting today and ending today.
- pahse 2 starting today and ending in a year.
This makes no sense for your use case. Instead you need to make sure that:
- phase 1 starts where it originaly started (copy the start date from the existing Schedule), and ends in a year.
- phase 2 has implicit dates. You can set duration to 1 cycle and then release the Schedule.
Is the suggestion still aligned with the scenario i describe on this ticket?
I’ve an active subscription on Price A ($1200) that runs from May 5, 2025, to May 5, 2026.
Now today May 5, I’ve increased the price to Price B ($1300).
I’ve create subscription schedule that on May 5 , 2026. to automatically switch to Price B when they renew.Then the active subscription try to update to Price C ($2700)
When I create preview invoices, the response show that the amount get charged is $4199.77
My expected amount is less than $1500 (proration and unused time)
I've try and that not I would like to achived (
req_JKVUv8mX2ZH7SI). Because the invoice preview the second phase amount. Not the unused time & remaining time
This makes no sense for your use case. Instead you need to make sure that:
- phase 1 starts where it originaly started (copy the start date from the existing Schedule), and ends in a year.
- phase 2 has implicit dates. You can set duration to 1 cycle and then release the Schedule.
Yes, I am just referring to your initial case.
From what I gather, on a given date next year, instead of updating Product A to Product B, you want to update Product A to Product C.
Can you confirm if my understanding is correct?
Yes, I want to update Product A to Product C immediately. Not on next year
Okay, this was not clear.
But you still want Product C to update to Product B in a year?
No, after update to Product C. The subscription will stay in Product C and no more subscription schedule will be needed
Okay. Then you just need to release the Schedule, and update it as a regular Subscription.
For my case, because of UX. User before succesfully update to Product C, I need to show how much amount. That time the subscription still attach to schedule.
If i just release the schedule, and when show the amount to user and decide not to update. Then I have to create back the schedule
Then you just need to release the Schedule, and update it as a regular Subscription.
is there a way to avoid re-create and needed to release schedule before the action on update the Product C?
Okay, I get it.
In this case, you need to copy the exact start_date and end_date from the existing phases of the Subscription Schedule to the Invoice Preview request, and just use the new Price ID in phase 0. Everything else must remain intact.
Here I asked you about where is Price A and Price C, and you said it's correct. But it's not, therefore me and my collegue were confused.
Oh, I'm really sorry 🙏
No worries, Subscription Schedules are probably the most advanced subject at Stripe.
Good we figured this out now.
Can you help to check if my request is correct?
https://dashboard.stripe.com/test/logs/req_SUJ4eyLaS1yq5w
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Does it produce the result you're looking for?
It not, so i wonder if my request payload is wrong
https://dashboard.stripe.com/test/logs/req_SUJ4eyLaS1yq5w
What's the exact issue with the result?
The total amount is not correct. Due to lines.data have 3 items and the last amount: 270000 "description": "1 × Annual Captivate (at $2,700.00 / year)", shouldn't return me this
Because the subscription subscribe product A $1200 update to product B $2700. The total amount should be or less than (2700 - 1200) - proration
Thanks for the additional details. let's narrow the output of this request:
So there is a proration item -119946 for the old price price_1PmpGcArTeYcLw6yySKT5l4b
The new price price_1KX0lEArTeYcLw6yla88Vatn (2700$) with proration 269879
A third item with price price_1KX0lEArTeYcLw6yla88Vatn (2700$) for year 2026-2027 (phase 2)
I see, sorry didn't noticed that. The third item is not I want.
A third item with price price_1KX0lEArTeYcLw6yla88Vatn (2700$) for year 2026-2027 (phase 2)
You should remove it from the schedule then
is that mean i need to release the schedule?
Or how can i remove it from schedule?
Let me check something..
This issue will require an in-depth investigation from our team in order to figure out the root cause. Can we ask that you write in to us via https://support.stripe.com/contact, providing as much detail and context as possible (you can also reference this thread).