#Yashish
1 messages · Page 1 of 1 (latest)
hello! sorry, it looks like i missed out on your question
If you want the user to pay for the subscription plan first and give them some free days, my recommendation is to use Subscription Schedules - you would schedule it such that they pay for the first cycle, then have a new Price that is $0 for x period, and then after which, switch them back to their usual Price
if a user is updating the plan and I want the user to pay for the update an also provide him some free days of trial can happen?
sure, it's the same logic
in case you haven't seen this yet, you can use test clocks to mimic the passing of time : https://stripe.com/docs/billing/testing/test-clocks
`trial_period_days = 5
trial_end = int((datetime.utcnow() + timedelta(days=trial_period_days)).timestamp())
subscription = stripe.Subscription.modify(
subscription_id,
proration_behavior='none',
items=[subscription_item],
payment_behavior='error_if_incomplete'
)
stripe.Subscription.modify(subscription.id, payment_behavior='error_if_incomplete',proration_behavior='none',trial_end=trial_end)
`
can you tell what problem is there in it because i want to take the payment from the user for the update
what's the issue? What behaviour are you expecting? what happened instead?
first payment for the update of the plan and also want to provide some free days
is your question why didn't the invoice for the payment generate?
I don't want this $0 invoice i want user to pay for the update and with update i want to provide user with x amount of free days for the first month of the plan
can you share the subscription id?
sub_1N3iySSGNnwNJbGSb4SJVsQA
you're updating the Subscription with a trial, that's why there's a $0 invoice. Have you gone through this document on how to implement a subscription schedule? https://stripe.com/docs/billing/subscriptions/subscription-schedules
you need to use a subscription schedule to implement the behaviour you're looking for
can we decide what should be the proration amount when user updates the plan?
no, that's automatically determined
the whole this is from the stripe side only?
if you want to manually decide it, you can set proration_behavior=none, and add an invoice_item : https://stripe.com/docs/api/subscriptions/update#update_subscription-add_invoice_items
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 Stripe in my Django app where there are different types of services and according to the service usage limit there are Stripe subscription plans,
Now if in the basic plan user can use 100 services in 30 days, but if the user uses some of the services (20 services for 15 days) and then want to update the plan to the advance one (plan with 1000 service usage limit) so at the update if I want to give the user the free trial for 15 days (unused days of its earlier plan)
Here if the user updates the plan then it is getting a 15-day free trial for the advance plan with 30 days of the advance plan (total of 45 days) but at the time of update, the user invoice of $0 is generated so if the user cancels its subscription in the free trial period then the user is able to use the advance service for free.
can you suggest any thing
like i've mentioned previously, don't use a trial. You should be using Subscription Schedules.
assuming the basic plan user already has an existing subscription and then wants to update it. You should update the Subscription to the advance plan using https://stripe.com/docs/api/subscriptions/update
Once you've collected payment for the Subscription update invoice, create a Subscription Schedule from that Subscription : https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases#existing-subscription
Update the newly created Subscription Schedule such that :
phase 1 : their current (newly upgraded Price) ends at period end
phase 2 : the new daily Price that costs $0 for x days that you want to provide to them
phase 3 : their newly upgraded Price again
here in
stripe.SubscriptionSchedule.create(
from_subscription='sub_GB98WOvaRAWPl6',
)
i had to add the free days trial ?
no, you don't need to add a trial at all
you would create a Price for $0 that you would use instead
so where do i need to define the free days?
you can set multiple phases in a Subscription Schedule, you would define the free days in the second phase. In the phase, you can pass in the specific Price that you want the Subscription to use
Update the newly created Subscription Schedule such that :
phase 1 : their current (newly upgraded Price) ends at period end
phase 2 : the new daily Price that costs $0 for x days that you want to provide to them
phase 3 : their newly upgraded Price again
can you provide a example with a python code?
We don't write code, no. You should be able to figure out the syntax/params from the API reference. What particular issues are you having?
can you tell any another way then the schedule one
Another way to do what?
I'm pretty sure I was helping you on this exact issue yesterday
What's the exact problem you're having? You've spoken to multiple people on my team now, and we seem no further forward
The summary is that you can't control the amount generated for proration. We calculate that based on time remaining on the existing plan, and other parameters (i.e. are you changing the billing anchor?). If you want to offer a free trial, but also charge them upfront then you can do that via the add_invoice_items parameter on the update/modify call: https://stripe.com/docs/api/subscriptions/update#update_subscription-add_invoice_items
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 think my colleague shared that with you yesterday. Why does that approach not work?
in adding the invoice item the the invoice is add but after the free trial is completed then also a invoice is generated for that
Invoice is generated for?
on updating i am adding the invoice item
`trial_period_days = 9
trial_end = int((datetime.utcnow() + timedelta(days=trial_period_days)).timestamp())
subscription = stripe.Subscription.modify(
subscription_id,
items=[subscription_item],
proration_behavior='none',
trial_end=trial_end,
add_invoice_items=[{
'price_data': {
'currency': 'usd',
'unit_amount': new_plan['amount'],
'product': new_plan['product'],
}
}]
)`
Ok, and what is unexpected about that? We'd immediately generate an invoice for the new_plan[amount]
I thought that was what you wanted – to start a trial but also bill the user
but the payment fails?
why?
i want the payment for 13 may to 13 june to be paid first
and next invoice should be generated for 13 june to 13 july
here the payment for 13-may to 13 june is done after the end of free trial
I'm not sure. You'd need to share the in_xxx ID. I suspect maybe 3DS/auth was requested and because its an off-session payment (i.e. your theoretical user isn't online) it'll decline
can you focus on this as you can see it in the image
Yes, that's just how it works. Adding a trial will reset the billing anchor – it is a billing period in itself. At the end of the trial, a new billing period still start and we'll invoice for the upcoming period: https://stripe.com/docs/billing/subscriptions/trials#:~:text=When the trial ends%2C if the subscription status isn’t paused%2C we generate an invoice and send an invoice.created event notification. Approximately 1 hour later%2C we attempt to charge that invoice. A new billing cycle also begins for the customer when the trial ends.
so can it be possible to accept payment for the subscription before the trial period ends?
Well, that's kind of what the add_invoice_items simulates yes
But no you can't bill for the next billing period before the end of the trial
the solution would be to use add_invoice_items to do a manual payment
you can check here also the next invoice will be generated of 13 may to 13 june but i want it to be of 13 june to 13 july
I told you yesterday how to make that happen
i had tried similar code you can check
instead of datetime.utcnow() + timedelta(days=trial_period_days) you can use subscription.current_period_end for example instead of "utcnow" to make the trial period be "10 days after the current next billing date".
can you explain it more briefly
i am unable to understand that in subscription.current_period_end how will i be able to provide X days in free trial?
I can't explain it any other way
when you call the API you pass trial_end. That is the date that you want the trial period to end.
if you do trial_end = int((datetime.utcnow() + timedelta(days=trial_period_days)).timestamp()) that means, "make the trial end at 'now + 10 days'". Do you agree? you wrote that code, that's what it does. So, correct?
yes
i tried with
trial_end = int((datetime.fromtimestamp(subscription.current_period_end) + timedelta(days=10)).timestamp())
whole data is shown in the trial period
what did you want to see instead? what is the problem?
is this the way you are talking about?
then can i know why this transaction fails? i want if the transaction succeed then only the free trial and plan are assigned to the user
then can i know why this transaction fails?
because it requires 3D Secure authentication from the user in order to succeed
Does it mean when the user tries to update the plan we need to again ask the user for payment details and open the stripe Session for the payment?
yes
as I said yesterday, the best option is to use the hosted_invoice_url of the Invoice that was created and redirect the user to that , to do the payment and 3D Secure there.
so de we need to perform this part first?
`trial_end = int((datetime.fromtimestamp(subscription.current_period_end) + timedelta(days=10)).timestamp())
subscription = stripe.Subscription.modify(
subscription_id,
items=[subscription_item],
proration_behavior='none',
trial_end=trial_end,
add_invoice_items=[{
'price_data': {
'currency': 'usd',
'unit_amount': new_plan['amount'],
'product': new_plan['product'],
}
}]
)`
or directly try for the session to accept payment from the user?
the easiest way is to do that first, and then access the Invoice that is created by the above API call , and redirect the customer to the hosted_invoice_url for it.
but in the hosted_invoice_url if user does not do the payment still we have updated user to the advance plan with some trial days also
correct yes, the change has already happened
if the customer doesn't pay the subscription will become past_due
how it will become past_due the subscription is already in the trial mode for 1 month +10 days
maybe I was wrong then
then what to do?
clarify the exact question please
after doing this we redirect the user to hosted_invoice_url and before redirecting we assign the user to the plan here if the user does not do any payment in hosted_invoice_url still he is assigned with the advance plan so how can we handle it
if that's the requirement then probably you want to do this entirely differently
for example, just create a manual Invoice or PaymentIntent or CheckoutSession for the $200 amount manually. Have the customer pay that. When that completes, then you can call the API to update the Subscription(and this time, do not include add_invoice_items since you already got the payment).
on updating the Subscription at that time the invoice will be generated for the new update ore not?
if you don't use add_invoice_items, and use proration_behaviour=none, then I think there is no charge or payment required. There's probably a $0 invoice generated for the trial, but you can't change that
you can test it all out in test mode
for example, just create a manual Invoice or PaymentIntent or CheckoutSession for the $200 amount manually.
here the new payment will be reflected in the user subscription or not?
it will not, since it's treated as a payment outside the subscription
but I want the payment reflected in the subscription
I know
probably you can't really
you can do what I suggested first(changing the subscription and using the Invoice generated) and that will be part of the subscription.
we have this feature to allow for doing a change only after a payment is complete on a subscription : https://stripe.com/docs/billing/subscriptions/pending-updates , but I suspect it will not work for your use case so I didn't suggest it, but you can try it too.
ultimately not all your demands and requirements are possible with the product today. You can experiment with the multiple options we've suggested and see what works best within the constraints.
sorry!
can you please do me a favour
can you keep this thread active if I come up with another way then I can ping you up
because every time in the group a new person is assign in the thread and i need to explain him whole thing again and again
nope, sorry
that's not how this works. Please work on the integration/experiment on your side and ask us specific questions in new posts and we can answer those. We can't keep spending multiple hours in threads with you like this, sorry.
okk i am having a another way..
Suppose today is May 1st, and a user has subscribed to the basic plan. On May 5th, the user wishes to upgrade to the advanced plan. We will open a Stripe checkout session and ask the user to make the payment for the advanced plan, but we will not activate the plan immediately.
Instead, we will offer the user two options. The first option is to activate the advanced plan on June 1st after the completion of its basic plan. The second option is to activate the plan immediately, in which case the user's advanced plan will be valid from May 5th to June 5th.
I don't see a question @forest spade
this is a new scenerio
I thought insted of free trial days i would like to implement it
what's the question?
can i implement this through stripe?
yes
can you provide me some links?
for which specific detail?
what did you try already and what part did you have difficulty with?
no, i am going to start it from the begining
cool, then let us know when you have a specific technical question about the API or code you wrote
you seem very familiar with the overall concepts and creating a Subscription and updating them so I'm sure you can get started!
here i want to accept the payment for the update plan from the user but not want to activate the plan
how can i do it?
you just don't call the Update Subscription API until you want to.
but I need this updated payment for the subscription
yes
then if the user does the payment for the subscription
then how can I give the user the option related to activate now or activate after the completion of the plan
that is not related to Stripe, that is the UI of your own app.
on the Stripe side, to activate the plan, you would call the Subscription Update API with appropriate parameters. The timing of when you do that is part of your own app and business logic and you are the expert there.
in stripe how to first buy the plan and activate it when the user want it to active and in it what would be the invoice cycle
when it is activated then or when the user buy the plan
that question doesn't make any sense sorry
please go write some code and try things out and come back with specific questions about your code and the API.
first i need to clear this things
so can you tell, please?
unfortunately you're not asking a specific question I can answer.
need to create checkout session like
checkout_session = stripe.checkout.Session.create( success_url="YOUR_SUCCESS_URL", cancel_url="YOUR_CANCEL_URL", payment_method_types=["card"], mode="subscription", line_items=[{ "price": "ADVANCED_PLAN_PRICE_ID", "quantity": 1, }], )
and what's the question about that?
here once the payment is done then do i need update the subscription through which id
and where the invoice for this subscription will be store?
that code creates a Subscription, i.e. once the customer pays that Session, a subscription immediately starts.
because here when a new checkout sessing will be created then the subscription id will be created for that user
yes, indeed.
so then the history of the subscription will not be manages as it was there is earlier method
but i not want to start the subscription
then why are you using mode=subscription ?
then what to use?
earlier I said :
for example, just create a manual Invoice or PaymentIntent or CheckoutSession for the $200 amount manually
if you're going to use a CheckoutSession for that payment, it should be a one-time payment, usingmode="payment"instead, if you're just doing a one time payment and not creating a new subscription. Sorry if that wasn't clear.
can there be a use of subscription schedule?