#surajpatidar
1 messages · Page 1 of 1 (latest)
The steps will be:
- Create the subscription schedule from existing subscription: https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases#existing-subscription
- Update subscription schedule to downgrade the plan at the end of the month with a new phase: https://stripe.com/docs/api/subscription_schedules/update
mean i need to create subsciption shedule with currrent plan right ?
i have already read doc but i can't understand well
mean i need to create subsciption shedule with currrent plan right ?
Yes!
i have already read doc but i can't understand well
Which part you don't understand?
how to downgrade
i have change every time only price in subscription right or need to create new subscription ?
No you just update the Subscription Schedule, which is generated from your existing Subscription
it controls the associated Subscription behaviors
subscription = stripe.Subscription.retrieve(user.subscription.id)
print(subscription)
if not int(new_plan.amount) < int(current_plan.amount):
stripe.Subscription.modify(
subscription.id,
cancel_at_period_end=False,
proration_behavior="always_invoice",
items=[
{
"id": subscription["items"]["data"][0].id,
"price": price_id,
}
],
)
print("Price Greater then current price")
messages.success(request, "Plan Upgrade SuccessFully.")
else:
stripe.SubscriptionSchedule.create(
customer=user.customer,
start_date='now',
end_behavior='release',
phases=[
{
'items': [
{'price': new_plan.id, 'quantity': 1},
],
'iterations': 1,
},
],
)
print("price less then current plan")
messages.success(request, "Plan DownGrade SuccessFully.")
right now i work like that if upgrade show effect immedilty and charge but downgrade show effect after end of the period of current plan
https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases#existing-subscription
You need to create a Subscription Schedule with from_subscription
from exsiting right ?
passing in the subscription.id
my scenario is if customer have 20$ plan current and if he request for upgrade to 30$
so immediately charge and effect but in downgrade i want if customer 20$ plan current and he request for 10$plan downgrade then effect show after the current plan end the period and charge both
for upgrade subscription i write this code and it work
subscription.id,
cancel_at_period_end=False,
proration_behavior="always_invoice",
items=[
{
"id": subscription["items"]["data"][0].id,
"price": price_id,
}
],
)```
but i want for downgrade as my scenario
Yeah, so you will have to write the Subscription Schedule to do your logic
to downgrade at end of current billing cycle
for downgrade can i write only one phase or need two phase
You can write multiple phases
but why need multiple phases for downgrade this my main question and i cant' understand this
You would need to specify the current phase, and the next phase you want in next billing cycle. I would recommend taking a look at the example codes in https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases#downgrading-subscriptions
ok
i will try don't close chat
we need to cancel current plan after downgrade plan
When you downgrade, the Subscription will automatically transit to the new, lower plan on time, so you don't need to cancel, I think
ok
for downgrade it is right or need to modify only subsciption schedule
customer='cus_GBXV9Q95NFT80k',
start_date='now',
end_behavior='release',
phases=[
{
'items': [
{'price': '{{Cuurent_Price}}', 'quantity': 1},
{'price': '{{new_price}}', 'quantity': 1},
],
'iterations': 1,
},
{
'items': [
{'price': '{{new_price}}', 'quantity': 1},
],
'iterations': 1,
},
],
)
Sorry the Doc are 2 separated steps you need to combine. As my colleague mentioned you need to
- Create the subscription schedule from existing subscription: https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases#existing-subscription
- Update subscription schedule to downgrade the plan at the end of the month with a new phase: https://stripe.com/docs/api/subscription_schedules/update
i have created schedule with existing subscition
now downgrade i need only add new phase right ? with new price id
You will also need to specify the current phase. (You will see if you try it)
Play with it in Test mode, try to pass parameters as you think and see how it ends up
okay
i have already this one phase {'items': [{'plan': 'price_1MxquQECJUF37lWXqBf9SptP', 'price': 'price_1MxquQECJUF37lWXqBf9SptP', 'metadata': {}, 'quantity': 1, 'tax_rates': [], 'billing_thresholds': None}], 'coupon': None, 'currency': 'usd', 'end_date': 1691819707, 'metadata': {}, 'trial_end': None, 'start_date': 1689141307, 'description': None, 'on_behalf_of': None, 'automatic_tax': {'enabled': False}, 'transfer_data': None, 'invoice_settings': None, 'add_invoice_items': [], 'collection_method': None, 'default_tax_rates': [], 'billing_thresholds': None, 'proration_behavior': 'create_prorations', 'billing_cycle_anchor': None, 'default_payment_method': None, 'application_fee_percent': None}
now i add second item and add new price id and start date and end date write
Yeah sound good
okay
wait 5 minutes
it look good or not and need any argument or not
end_date = user.subscription.schedule.current_phase['end_date']
start_date = user.subscription.schedule.current_phase['start_date']
stripe.SubscriptionSchedule.modify(
user.subscription.schedule.id,
phases=[
{'items':
[
{
'price': current_plan,
'quantity': 1,
}
],
'end_date': end_date,
'start_date': start_date,
},
{'items':
[
{
'price': new_plan,
'quantity': 1,
}
],
'start_date': end_date,
},
],
)
Yeah looks good, but please test it out on Test mode
ok
it give me error
stripe.error.InvalidRequestError: Request req_6FwrWq3hVHfsjn: No such price: '$79.00 USD/month for Platinum'
https://dashboard.stripe.com/test/logs/req_6FwrWq3hVHfsjn is how you can see your request
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
current_plan you passed in is a String $79.00 USD/month for Platinum
You need a price id there instead
Request req_c1ioTXP4QmQhMN: No such price: '$79.00 USD/month for Platinum'
okay
it give me subscription schedule update and this response now i check to it work or not ?
You would want to examine the phases on the response, check its starting and ending date to see if it's correctly reflected your intention
Or use Test clock to advance the time, and verify it would work as expected
okay
i have one more question
this process work on monthy to monthy but what if monthy to yearly change
Same, Subscription Schedule can do that too