#sajid_api

1 messages ยท Page 1 of 1 (latest)

dreamy depotBOT
#

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

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

weary aspen
#

I am encountering an issue when attempting to update subscription schedules in my application. Specifically, when I try to update the first phase (phase[0]), I receive an error indicating that some attributes are empty strings. This occurs for attributes that I did not set during the initial creation of the phase.

Additionally, when I attempt to set these attributes while updating, I receive a different error stating that I cannot update a phase that has already ended.

Could you please clarify the following for me?

Handling Empty Attributes: How should I manage attributes that were not set during the creation of a phase? Is there a way to bypass the empty string error without having to set all attributes?

Updating Ended Phases: What are the specific limitations regarding updating phases that have already ended? Is there a way to modify attributes for these phases, or should I handle this differently?

Your assistance in resolving these questions would be greatly appreciated. Thank you for your help!

covert minnow
#

You provided an account ID, not a request ID. Can you provide a request ID?

#

How are you creating Subscription Schedules in the first place?

#

It is not recommended to directly update the first phase of a subscription schedule. The point of subscription schedules is to allow you to schedule the changes for a later time.

weary aspen
#

req_u22BBQQnT0u4EP

#

When I do not update first phase it gives empty string errors for attributes those I did not set while creating the schedule.

covert minnow
#

Oh, you mean you aren't passing the first phase?

#

Yeah that is required.

weary aspen
#

I pass the phases. that why it gives empty string erros.

covert minnow
#

Subscription Scheudles update in kind of a weird way. If you pass the phases parameter it will completely overwrite, not add to, the existing data

#

Can you provide a request that shows these errors?

#

The request you provided is successful

weary aspen
#

Yes sure.

weary aspen
covert minnow
#

That is an update request though. The schedule already exists

#

A creation request would use just this URL /v1/subscription_schedules without the ID

weary aspen
#

req_iIE68T9vUC6gog

#

I am passing same phases I get from retreive schedule. along with my new phase.

covert minnow
#

Can you share how you are doing that in your NodeJS code?

#

You can see that, for the first phase, you specified collection_method: "charge_automatically",

#

You need to pass all these values again (not empty strings) when you attempt to add a second phase

weary aspen
#

Let me try it.

covert minnow
#

This is because they were not included

weary aspen
#

When I try to set it says the phases that are expired can not be edited.

covert minnow
#

In which request?

weary aspen
#

req_IgsQj236lt1kB1

#

In this request.

covert minnow
#

It looks like this schedule is using a test clock

weary aspen
#

Yes they are using.

covert minnow
#

The frozen time for that clock is 2024-10-26 but the phase you are trying to edit ends on 2024-09-30. So that is why you are getting this error

dreamy depotBOT
covert minnow
#

I recommend you review this approach to make sure you are setting all the necessary values in your code

weary aspen
#

I have currently two phases. I dont want to edit previous phase that ended that date you mentioned. I pass the first as it as it get in retreive schedule response. then it gives error of empty string for some attributes I mentioned earlier.

#

I have gone through docs but I did'nt get solution for me. I tried everything. Please help me to make it work.

covert minnow
#

I think you will need to start fresh with a new Subscription Schedule. There have been many confusing changes made to this current one.

In your NodeJS code, copy the entire Phases array to a variable and add the new phase you want to make to the end of it. Then pass the whole array back in the update API request.

weary aspen
#

Can I make changes in last phase in array like changing items or add_invoice_items?

#

Please dont close thred I am trying it now.

errant reef
#

Hi there ๐Ÿ‘‹ jumping in as my teammate needs to step away. Yes, you can make adjustments to the last phase that you provide in the phases array, but you will need to provide all phases that are currenlty in the phases array when making that update.

#

So if you have a Subscription Schedule with two phases after the current one, and want to only update the last one, you still need to include all three phases in the phases array in the update request.

weary aspen
#

Okay I am trying these both options. Please dont close the thread or go away.

#

It needs end date for previous phase. How can I edit that?

#

When I am adding new phase.

errant reef
weary aspen
#

I create schedule just now and I did't gave it coupon while creating. but when I tried to update it gave me error:
"You passed an empty string for 'phases[0][coupon]'. We assume empty values are an attempt to unset a parameter; however 'phases[0][coupon]' cannot be unset. You should remove 'phases[0][coupon]' from your request or supply a non-empty value."

errant reef
#

Can you share the ID of that request?

weary aspen
#

req_m8gK3RyRnoDJou

#

const updatedPhases = currentSchedule.phases;

updatedPhases.push({
start_date: unixNextIterationStartDate, // Set new phase start date
items: items, // New items for the next phase
add_invoice_items: invoiceItems, // New one-time invoice items
iterations: 3, // Number of billing cycles for the new phase
billing_cycle_anchor: 'automatic', // Automatically set the billing cycle anchor
collection_method: 'charge_automatically', // Collection method for the new phase
metadata: {
reason: 'Added new phase starting from next iteration'
}
});

// Now update the subscription schedule with updated phases
const updatedSubscriptionSchedule = await stripe.subscriptionSchedules.update(scheduleId, {
end_behavior: 'release', // What happens when the schedule ends
phases: updatedPhases // Pass the updated phases directly
});

errant reef
#

Your request included the phases.coupon parameter for the first phase, and passed an empty string for that parameter. You should remove that from your request.

weary aspen
#

I never included it while creation.

errant reef
#

Unfortunately passing in the entire existing phase isn't a great approach, because that object will include empty fields.

#

You included it in this line it seems:
const updatedPhases = currentSchedule.phases;
by including the entire existing phase.

weary aspen
#

When I filter it says you can not edit phases that are already ended. Read the conversation in start of this thread.

errant reef
#

The phase isn't ended, or it wouldn't be in the phases array anymore.

weary aspen
#

You mean if phases ended it will not be in phases array anymore?

errant reef
#

Yup

weary aspen
#

Oh but it was there. was it due to test clock?

errant reef
#

Can you elaborate?

I see two phases on that Subscription Schedule, where the first one ends on Sep 30, 2024. The test clock's time is frozen at Sep 26, 2024.

So the first phase in the phases array is the current phase, and then there is one more phase after that. When the Subscription Schedule moves to that next phase, the phases array should drop to only contain the remaining phase.

weary aspen
#

Ok I got your point. I have one more doubt. If I dont give end date for previous phase would that both run parallel?

errant reef
#

That'll fail, because the system won't know when you want the phase to end and won't know how to order the phases you provide in the array. That should lead to the error you mentioned previously about an end_date not being provided. It's not possible to have phases run in parallel, they must be sequential.

weary aspen
#

Ok I got it.

#

keep thread open for a while so i can test out these things.

errant reef
#

@weary aspen did that do the trick?

weary aspen
#

still same issues i am working on them. pleas keep thread open.

errant reef
#

Do you want to tell me what you're seeing now, do you still need help with that? I'm not inclinde to leave the thread open if there isn't an active discussion going. You're welcome to test on your own and open a new thread to discuss any questions that arise from that testing.

weary aspen
#

updatedPhases[updatedPhases.length - 1].end_date = unixNextIterationStartDate;
updatedPhases[updatedPhases.length - 1].iterations = null;

#

When I add end date for current phase. to start the next I set iterations to null. is it correct way to do it? it still say you can only give either end date or iterations.

errant reef
#

Can you share the request ID throwing that error? You would omit the iterations parameter entirely if you're using start and end dates to control the length of your phases.

weary aspen
#

req_HTC8NkV1LYLnfB

#

onst updatedPhases = currentSchedule.phases.map(phase => {
return {
start_date: phase.start_date,
items: phase.items || [], // Use existing items or an empty array if undefined
add_invoice_items: phase.add_invoice_items || [], // Use existing add_invoice_items or an empty array
proration_behavior: phase.proration_behavior || 'create_prorations', // Default to 'create_prorations' if undefined
billing_cycle_anchor: phase.billing_cycle_anchor || 'automatic', // Default to 'automatic' if not specified
metadata: {
invoiceNo: phase.metadata.invoiceNo || invoiceNo, // Use existing invoiceNo or the new one
// Map any other metadata fields as needed
},
collection_method: phase.collection_method || "charge_automatically", // Default if not specified
};
});

#

I already remvoed iteration parameter .

errant reef
#

You can also view these requests in your Stripe dashboard and see exaclty what we're receiving from your calls to our API.
https://dashboard.stripe.com/test/logs/req_HTC8NkV1LYLnfB
It's the same thing as before with coupon it looks like. You're passing iterations with an empty string, rather than avoiding passing it.

weary aspen
#

But I removed the coupon in same way you see updatedPhases. but why its not working with iterations then.

errant reef
#

I'm not sure, it doesn't look like you shared your full code, and I don't see anything in the code you shared that looks like it's filtering out any iterations fields.

dreamy depotBOT
weary aspen
#

is there any unique error code for this:
message: 'Each phase must be at minimum 1 second long. Phase 1 has the same start_date and end_date of 1727722800.',

so when this comes up. I should add items to existing phase without creating other one.

mighty bolt
#

Hello! I'm taking over and catching up...

#

I don't think there's a unique error code for that, no. You can perform a check on your end to compare the start and end timestamps being used, though.

weary aspen
#

updatedPhases[updatedPhases.length - 1].iterations = remainingIterations || 5;

#

can I update iterations like this. when I updating the same phase.

#

still it expire after one month.

mighty bolt
#

I don't know, I don't have enough context. I don't know what updatedPhases is. I don't know what .length is on it. I don't know what remainingIterations is. I recommend you try it in test mode and see if it works the way you expect.

weary aspen
#

req_PJXlPZTIJjkis8

#

can you check this request ID does it got proper iteratoin numbers.

mighty bolt
#

That's a GET request to retrieve the Subscription Schedule. We don't log responses to GET requests, so I can't see what data you got back. Did you get the numbers you expected back?

weary aspen
#

let me figuer it out the exact problem.