#alexisadeveloper
1 messages ยท Page 1 of 1 (latest)
Hi there!
Can you share the ID (req_xxx) of the failing API request?
https://support.stripe.com/questions/finding-the-id-for-an-api-request
Yes here it is req_n6iDbzZh2YpgYC
according to that requestId, Phase 0's end date is 1691658944 which is 2023-08-10 09:15:44 UTC, the request was made at 2023-07-10 11:40:51 UTC UTC, after the phase was ended, which exaplains the error.
But the end date is in august and the request is now, so shouldn't it be within the time window?
Ah right, sorry missed that
Here's another, similar request: req_AvXtuXkalrurDV
Taking over here, let me catch up
I'd imagine it's because you're passing the start_date and end_date parameters to a phase that is already underway (i.e. 'current' phase). You just just omit those parameters, and just pass the updates and existing items
Then I get this error
Did you try passing iterations?
What's the req_xxx for that?
req_VCRR0Z2KV7bYKv
my stripe account is not accepting my documents.whats the problem>
Hmm, the Schedule API is notrious for cryptic error messages ๐ฆ
Wait, can you retrieve the sub_sched_xxx and paste the JSON here
I think phases[0] has ended
So according to what I'm seeing you likely just need to update phase[1], not the first in the index
sub_sched_1NSGHDEwHpTUe8W7W111H888
No, can you share the JSON response if you retrieve the object from the API
How would I get it to consistenly update the current month and the next one
aah ok yes
sched {
id: 'sub_sched_1NSGHDEwHpTUe8W7W111H888',
object: 'subscription_schedule',
application: null,
canceled_at: null,
completed_at: null,
created: 1688980863,
current_phase: { end_date: 1691658944, start_date: 1688980972 },
customer: 'cus_OEjfER65QHvUGc',
default_settings: {
application_fee_percent: null,
automatic_tax: { enabled: false },
billing_cycle_anchor: 'automatic',
billing_thresholds: null,
collection_method: 'charge_automatically',
default_payment_method: 'pm_1NSGCMEwHpTUe8W7vecMYR3l',
default_source: null,
description: null,
invoice_settings: { days_until_due: null },
on_behalf_of: null,
transfer_data: null
},
end_behavior: 'release',
livemode: false,
metadata: {},
phases: [
{
add_invoice_items: [],
application_fee_percent: null,
billing_cycle_anchor: null,
billing_thresholds: null,
collection_method: null,
coupon: null,
currency: 'eur',
default_payment_method: null,
default_tax_rates: [Array],
description: null,
end_date: 1688980972,
invoice_settings: null,
items: [Array],
metadata: {},
on_behalf_of: null,
proration_behavior: 'create_prorations',
start_date: 1688980544,
transfer_data: null,
trial_end: null
},
Yeah, so phases[0] has an end_date of 1688980972 (Mon Jul 10 2023 09:22:52 GMT+0000)
So the API error is correct โ you're trying to update a phase that has ended
You need to just omit that phase from your update call
But sometimes I need to add an item to the current phase of the subscription
and simultaneously to the next
how would I achieve that
Yep, and that's possible. The issue is you're updating the wrong phase. phase[0] isn't necessarily the current phase, it can be a past phase (as is the case here)
So how would I update the current phase?
and also how would I update every phase after the current one?
Confirming
What do you mean?
I'm confirming how this is expected to work, bear with me
ah oki
I think the easiest way would be to just pass the all the phases in the update payload, including the past phase[0]
But the API reference says they can be omitted, just not sure how
(still checking)
LMK if this works in the meantime
I'm really confused because this logic that I have has been working till today and we have customers that are already on subscription schedules. When I initially added the subscription schedule, it was a recommendation by stripe because it would allow me to easily add products to the current billing cycle and the coming one, and the structure I have is the one that was suggested. Getting all the past phases, then figuring out the current one so that it can be updated seems like quite a hassle to me
Yep, I agree the usage of this API is confusing at best.
I think what is missing from this request (https://dashboard.stripe.com/test/logs/req_VCRR0Z2KV7bYKv) is a start_date in phase[0]
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
And it wouldn't be the subscription.current_period_start, right? It would be the start date of the initial phase?
because I just tried it and it says "You can not update a phase that has already ended. Trying to update phase 0." again. The request id is "req_T4GDLZGqiSgQQy".
start_date should be 1688980972 I think as that was the end_date of the past phase
So I have to write a function that finds me the past phase or is there anything for that?
Well, the start_date is just the existing value from the phases[1] object that was returned by the API
So if you're updating phase[1] (as is the case here), then start_date must match that value of the existing phase
Hello, ynoj had to step away but my colleagues found the right way to do this. One sec as I catch up on that...
THere could be infinitely many phases since we do not limit that for our customers. Would I have to figure out if the current date fits within the start and end date of a particular phase?
Okay: basically i need a simple solution that allows me to always update the current and all upcoming cycles (until they are updated) .
So it looks like your code was just slightly off. The API expected the first phase to have its start date and end date provided. Your call had
start_date: "1688980544" end_date "1691658944"
But that phase actually had
start_date: "1688980972" end_date: "1691658944"
So that is what the API needed for this call to suceed
To be clear, those were the existing start_date and end_date of phase[1] in the subscription that you got back. So the way to do this would be to iterate until you find a phase that has not ended, then start including phases from there when you make the update call, and make sure to include both that phase's start date and end date
So I would still just put two phases (the current and the next ) but instead of getting the phase start and end from the subscription, I get it from the last phase that hasn't ended yet? I guess that's doable but won't it change when the user then actually pays their subscription since it isn't pegged to the subscription's start and end?
The billing cycle anchor should stay unaffected as far as I know. Would you mind testing out this call and checking the billing_cycle_anchorto see if it has changed? I don't think it will change but if it does we can find a workaround
Nice!
Could we leave this chat open while I test around a bit more? I dont wanna have to catch up somebody completely new in case it didnt actually fix it
We typically keep these open for 30 mins to an hour after they close. After that point, it is typically best to start again in the main channel. My colleagues should be able to pick this back up if need be