#Yashish

1 messages · Page 1 of 1 (latest)

native orbitBOT
hasty yarrow
#

Hi there!

#

How does the user upgrade their subscription? With your own UI or the customer portal or something else?

spare laurel
#

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)`
hasty yarrow
spare laurel
#

here i am redirecting user to the invoice url of stripe for the payment i want coupon option their

hasty yarrow
#

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.

spare laurel
#

aother option then this

i want the functionality that we get in allow_promotion_codes in Checkout Session