#Yashish
1 messages · Page 1 of 1 (latest)
You may use Subscription Update API and set the coupon to apply: https://stripe.com/docs/api/subscriptions/update#update_subscription-coupon
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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)
coupon can be set in your subscription.modify(..) function
The value of coupon should be the coupon ID that you intend to apply to
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.
If you wish to support promotion code in Customer Portal, it's not done through Subscription Update API. It should be the configuration on the customer portal by enabling promotion code support: https://stripe.com/docs/customer-management/configure-portal#customer-billing-configurations
no customer portal
but i want user to enter the coupon on the portal
Which portal are you referring to then?
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
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
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?
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