#Yashish

1 messages · Page 1 of 1 (latest)

brave brambleBOT
brisk arrow
#

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

forest spade
#

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?

brisk arrow
#

sure, it's the same logic

forest spade
#

`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

brisk arrow
#

what's the issue? What behaviour are you expecting? what happened instead?

forest spade
#

first payment for the update of the plan and also want to provide some free days

brisk arrow
#

is your question why didn't the invoice for the payment generate?

forest spade
#

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

brisk arrow
#

can you share the subscription id?

forest spade
#

sub_1N3iySSGNnwNJbGSb4SJVsQA

brisk arrow
#

you need to use a subscription schedule to implement the behaviour you're looking for

forest spade
#

ook

#

let me check

forest spade
#

can we decide what should be the proration amount when user updates the plan?

brisk arrow
#

no, that's automatically determined

forest spade
#

the whole this is from the stripe side only?

brisk arrow
forest spade
#

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

brisk arrow
#

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

forest spade
#

here in
stripe.SubscriptionSchedule.create(
from_subscription='sub_GB98WOvaRAWPl6',
)

i had to add the free days trial ?

brisk arrow
#

no, you don't need to add a trial at all

#

you would create a Price for $0 that you would use instead

forest spade
#

so where do i need to define the free days?

brisk arrow
#

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
brave brambleBOT
forest spade
#

can you provide a example with a python code?

amber cloak
#

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?

forest spade
amber cloak
#

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

#

I think my colleague shared that with you yesterday. Why does that approach not work?

forest spade
#

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

amber cloak
#

Invoice is generated for?

forest spade
#

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'],
            }
        }]
    )`
amber cloak
#

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

forest spade
#

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

amber cloak
# forest spade but the payment fails?

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

forest spade
amber cloak
# forest spade here the payment for 13-may to 13 june is done after the end of free trial

Delay payments on active subscriptions using trial periods.

forest spade
#

so can it be possible to accept payment for the subscription before the trial period ends?

amber cloak
#

Well, that's kind of what the add_invoice_items simulates yes

brave brambleBOT
amber cloak
#

But no you can't bill for the next billing period before the end of the trial

forest spade
#

but i want to do it like that

#

can there be any solution for that

calm river
#

the solution would be to use add_invoice_items to do a manual payment

forest spade
# forest spade

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

calm river
#

I told you yesterday how to make that happen

forest spade
calm river
#

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".

forest spade
#

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?

calm river
#

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?

forest spade
#

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

calm river
#

what did you want to see instead? what is the problem?

forest spade
#

is this the way you are talking about?

forest spade
# forest spade

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

calm river
#

then can i know why this transaction fails?
because it requires 3D Secure authentication from the user in order to succeed

forest spade
calm river
#

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.

forest spade
#

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?

calm river
#

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.

forest spade
#

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

calm river
#

correct yes, the change has already happened

#

if the customer doesn't pay the subscription will become past_due

forest spade
# forest spade

how it will become past_due the subscription is already in the trial mode for 1 month +10 days

calm river
#

maybe I was wrong then

forest spade
#

then what to do?

calm river
#

clarify the exact question please

forest spade
calm river
#

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).

forest spade
calm river
#

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

forest spade
#

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?

calm river
#

it will not, since it's treated as a payment outside the subscription

forest spade
calm river
#

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!

forest spade
#

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

calm river
#

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.

forest spade
#

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.

calm river
#

I don't see a question @forest spade

brave brambleBOT
forest spade
#

this is a new scenerio

I thought insted of free trial days i would like to implement it

calm river
#

what's the question?

forest spade
calm river
#

yes

forest spade
#

can you provide me some links?

calm river
#

for which specific detail?

#

what did you try already and what part did you have difficulty with?

forest spade
#

no, i am going to start it from the begining

calm river
#

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!

forest spade
calm river
#

you just don't call the Update Subscription API until you want to.

forest spade
#

but I need this updated payment for the subscription

calm river
#

yes

forest spade
#

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

calm river
#

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.

forest spade
#

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

calm river
#

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.

forest spade
#

first i need to clear this things
so can you tell, please?

calm river
#

unfortunately you're not asking a specific question I can answer.

forest spade
#

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, }], )

calm river
#

and what's the question about that?

forest spade
#

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?

calm river
#

that code creates a Subscription, i.e. once the customer pays that Session, a subscription immediately starts.

forest spade
#

because here when a new checkout sessing will be created then the subscription id will be created for that user

calm river
#

yes, indeed.

forest spade
#

so then the history of the subscription will not be manages as it was there is earlier method

forest spade
calm river
forest spade
calm river
#

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, using mode="payment" instead, if you're just doing a one time payment and not creating a new subscription. Sorry if that wasn't clear.

forest spade
#

can there be a use of subscription schedule?

calm river
#

they might be an option, there are many many ways to use Stripe

#

I can't just explain our entire API to you sorry, you need to do your own research. This Discord can help with specific questions you have.