#nadiya_code

1 messages ยท Page 1 of 1 (latest)

cursive hillBOT
#

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

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

uneven pebble
inland sand
#

yes a minute

uneven pebble
inland sand
#

req_cwBM1nhLkVjcg2

inland sand
#

also, i'm retrieving the schedule from stripe, and using its phase
const schedule = await stripe.subscriptionSchedules.retrieve(subscription.schedule);

uneven pebble
#

Or set a valid decimal, you are sending empty value

inland sand
#

i'm not manually adding it.

uneven pebble
#

Ah your backend is sending it according to the request Id ๐Ÿค”

inland sand
#
if (subscription.schedule) {
    const schedule = await stripe.subscriptionSchedules.retrieve(subscription.schedule);

    const updatedPhases = schedule.phases.map((phase) => {
        // Destructure all keys except `coupon`
        const { coupon, ...rest } = phase;

        // Return the phase with discounts applied
        return {
            ...rest,
            discounts: [{ coupon: couponId }],
        };
    });


    // Step 3: Apply coupon to all phases
    const updatedSchedule = await stripe.subscriptionSchedules.update(schedule.id, {
        phases: updatedPhases,
    });

    console.log(`โœ… Applied coupon ${couponId} to ALL phases of scheduled subscription ${subscriptionId}`);
    return updatedSchedule;
}
#

do i need to santize all the input that have blank or null values from the stripe?
is it there better or simpler soultion to just update coupon to all the phases of subscription schedule?

uneven pebble
#

You need to omit for empty fields here:

    // Destructure all keys except `coupon`
    const { coupon, ...rest } = phase;

    // Return the phase with discounts applied
    return {
        ...rest,
        discounts: [{ coupon: couponId }],
    };
#

is it there better or simpler soultion to just update coupon to all the phases of subscription schedule?
No, You need to fetch all the Subscription schedule phases and update them one by one.

#

You should update your code, and remove blank fields

inland sand
#

i see, okay

cursive hillBOT
inland sand
#

another question: do we need to pass entire 'not null' existing phases data attributes while updating?
or can we just update it with the key that we want (like a PATCH update)

uneven pebble
#

Yeah it's like a patch update, you pass null attribute only when you want to omit/delete a value of an attribute

#

otherwise, you can send only the fields that you want to update

uneven pebble
#

Ah sorry, I knew about passing all phases, but not all attributes too.

#

Then yeah you should pass all phases and all attributes, but remove the blank fields

inland sand
#

hmm okay, let me try that then

alpine fable
#

๐Ÿ‘‹ taking over for my colleague. Let me know if there's any follow-up Qs I can answer!