#Yashish

1 messages · Page 1 of 1 (latest)

covert valleyBOT
tight nebula
regal current
#

I am using this for subscription update

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)
tight nebula
#

coupon can be set in your subscription.modify(..) function

regal current
#

coupon = True

#

?

tight nebula
#

The value of coupon should be the coupon ID that you intend to apply to

regal current
#

but i want user to enter the coupon on the portal

#

and also get this error
stripe.error.InvalidRequestError: Request req_kGQ4sZsfnbcvWg: When payment_behavior is set to pending_if_incomplete, you can only pass supported params. coupon is not supported.

tight nebula
regal current
#

no customer portal

tight nebula
#

but i want user to enter the coupon on the portal
Which portal are you referring to then?

regal current
#

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',
            # coupon = True
        )

        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)

here when user is redirected to return redirect(invoice_url) I want there a text field where user can enter coupon code

tight nebula
#

I see that you're referring to Invoice URL. Entering coupon/promotion code in Invoice URL is not supported

#

Invoice URL is only available after an invoice is finalised. After an invoice is finalised, it's not possible to update it or set coupon/promotion code

regal current
#

once the subscription is created with a coupon of 100 % off then on updating the subscription plan or changing the subscription plan the coupon remain applied?

tight nebula
#

It depends on how your coupon is set up and when you update the subscription. If the coupon is set up to only use once, then it will not remain in the next billing cycle. If your coupon is set up to be applied forever, it will remain

regal current
#

ook