#michael_error

1 messages ยท Page 1 of 1 (latest)

urban terraceBOT
#

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

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

steady scarab
#

Hello!

#

Thats the request payload:

#

{
"phases": {
"0": {
"automatic_tax": {
"enabled": "false"
},
"collection_method": "charge_automatically",
"currency": "pln",
"end_date": "1765271217",
"items": {
"0": {
"plan": "price_1SXHBDDWTAUoo6QNWmPF0Cml",
"price": "price_1SXHBDDWTAUoo6QNWmPF0Cml",
"quantity": "1"
}
},
"proration_behavior": "none",
"start_date": "1764666417",
"trial": "true",
"trial_end": "1765271217"
},
"1": {
"discounts": {
"0": {
"coupon": "vMrQ3uto"
}
},
"duration": {
"interval": "day",
"interval_count": "30"
},
"items": {
"0": {
"price": "price_1SXHBDDWTAUoo6QNWmPF0Cml",
"quantity": "1"
}
}
}
}
}

#

And the logic:

#

Find active subscription

subscriptions = stripe.Subscription.list(
    customer=stripe_customer_id, status="active", limit=1
)
if not subscriptions.data:
    subscriptions = stripe.Subscription.list(
        customer=stripe_customer_id, status="trialing", limit=1
    )
    if not subscriptions.data:
        return None  # no active or trialing subscription

subscription = subscriptions.data[0]

# Get the current price from the subscription
current_price = subscription['items']['data'][0]['price']['id']

discount_phase = {
    "items": [{"price": current_price, "quantity": 1}],
    "duration": {"interval": "day", "interval_count": days},
    "discounts": [{"coupon": settings.STRIPE_FULL_DISCOUNT_COUPON_ID}],
}

# Check if subscription already has a schedule
if subscription.get("schedule"):
    schedule = stripe.SubscriptionSchedule.retrieve(subscription.schedule)
else:
    schedule = stripe.SubscriptionSchedule.create(
        from_subscription=subscription.id,
    )
    
# Update the schedule with the new phase
existing_phases = schedule['phases']
existing_phases.append(discount_phase)
updated_schedule = stripe.SubscriptionSchedule.modify(
    schedule.id,
    phases=existing_phases
)
    
return updated_schedule
#

Seems like schedule = stripe.SubscriptionSchedule.create(from_subscription=subscription.id) creates schedule where first phase contains logic error

slate frigate
#

๐Ÿ‘‹ Hi there! Can you share a request ID where you're creating the schedule?

steady scarab
#

req_ROeUGRri73eHlf

#

There you go

slate frigate
#

Thanks. So you're using the existing phases when updating the Schedule, but the existing phases have both trial and trial_end?

steady scarab
#

Thats right

#

But i create Schedule using schedule = stripe.SubscriptionSchedule.create(
from_subscription=subscription.id,
)

#

Which gave me 200ok

#

Existing phase is the one which was created when i passed 'subscription.id' to 'from_subscription'. Then i modify schedule by appending new phase to already existing ones, thats where error/bug occured

slate frigate
#

As a workaround for now, you would have to remove trial from the phases when making the update call

steady scarab
#

Right, the docs says i shoudnt pass two parameters which is totally fine, it just seems like some kind of logic error or smth like that

#

Sure

#

Will do it

slate frigate
#

Yeah, thanks for pointing this out. I'll bring this up internally and see if we can update this behaviour

steady scarab
#

Thanks and have a good day! Let me know i you have any bug bounty program ๐Ÿ™‚

slate frigate
steady scarab
#

Ok, got it ๐Ÿ™‚