#Yashish
1 messages · Page 1 of 1 (latest)
Hi there!
How does the user upgrade their subscription? With your own UI or the customer portal or something else?
through code
I am having this code for users to update their subscription i want 'allow_promotion_codes' possible
`subscription = stripe.Subscription.retrieve(subscription_id)
subscription_item_id = subscription['items']['data'][0]['id']
new_plan = stripe.Plan.retrieve(plan_id)
new_plan_stripe_id = new_plan["id"]
subscription_item = {
"id": subscription_item_id,
"price": new_plan_stripe_id,
}
# Update the subscription with the new plan and proration behavior
subscription = subscription.modify(
subscription_id,
proration_behavior='always_invoice',
items=[subscription_item],
payment_behavior='pending_if_incomplete',
)
subscription = stripe.Subscription.retrieve(subscription_id)
invoice = stripe.Invoice.retrieve(subscription.latest_invoice, expand=['payment_intent'])
invoice_url = invoice.hosted_invoice_url
print("661 invoice_url-->",invoice_url)
return redirect(invoice_url)`
If it's your own UI then it's completely up to you! And when you update the subscription you can pass a coupon https://stripe.com/docs/api/subscriptions/update?lang=node#update_subscription-coupon
here i am redirecting user to the invoice url of stripe for the payment i want coupon option their
Got it, that's not possible. But you could in your own UI collect the coupon, and then when you update the invoice set the coupon parameter. And then redirect users to the invoice url.
aother option then this
i want the functionality that we get in allow_promotion_codes in Checkout Session