#Yashish
1 messages ยท Page 1 of 1 (latest)
Not sure what you mean by 'cut'. If you're applying a trial, yes we'd generate a zero-amount invoice for that period. There would then be a new invoice for the new amount at the end of that period.
can there be any way to generate the invoice for the new amount at the time of the update instead of at the end of the trial period.
There is not
can i explain you my scenario so that you can suggest me what can i do in it?
Sure, go ahead
If the user updates his subscription can there be any way we can decide what should be the proration amount?
You can't stipulate the prorated amount manually, no. We calculate that based on the parameters used during the update
once the user subscription is updated can we add some free days in it for the first-month interval, and after that from the second month the subscription continues in 30 days interval.
can we add some free days in it for the first-month interval
Sure, you'd just update the Subscription withtrial_period_days
but this trial period days should be added to the particular user subscription plan?
or it is added to the whole subscription plan
I don't understand the question
here for the user subscription plan if we update the trial_period_days then this trial period days would be added to the particular user subscription plan or it will be added to all the user with that subscription plan
No, just the sub_xxx ID that pass during the update. Any other Subscriptions on the same plan/price wouldn't be impacted
can you tell how can we do that in python code?
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
unable to find trial_period_days in subscription update
Ah, maybe that's a create only parameter. Use trial_end then: https://stripe.com/docs/api/subscriptions/update?lang=python#update_subscription-trial_end
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
on an ongoing subscription can I apply trial_end?
without changing the subscription plan
Yes
In my Django application, I am utilizing Stripe to offer various services that come with usage limits. Each service has its own corresponding Stripe subscription plan. For instance, a basic plan allows the user to use up to 100 services in 30 days.
Suppose a user subscribes to the basic plan but only uses 20 services for 15 days. If they wish to upgrade to the advanced plan (which has a 1000 service usage limit), I want to provide them with a 15-day free trial for the remaining unused days of their earlier plan.
When the user upgrades their plan, they will receive a 15-day free trial for the advanced plan, in addition to the original 30 days, making it a total of 45 days. However, during the upgrade process, the user's invoice will show $0. If the user cancels their subscription during the free trial period, they will be able to use the advanced service for free.
I want to provide them with a 15-day free trial for the remaining unused days of their earlier plan.
Why is this is a concern? If you useproration_behavior: 'always_invoice'during your update then we will apply credit for the unused time on the previous plan
but I want it according to the user service also
if the user use 100 services in 1 day only then update the plan to the advance then the user will get more proration amount
I'm sorry I don't understand what you mean. Can you provide a specific example?
hereafter updating the plan if I am trying to add the free trial days then it is also making another payment
I would like to take into account the user's service usage when upgrading their plan. For example, if a user consumes 100 services in just one day and then decides to upgrade to the advanced plan, they will receive a higher proration amount (wich is managed by stripe).
so i want to make the portion amount according to the service used by the user.
Are you using a metered plan with Stripe? Or are you tracking usage externally?
i am building a Django app and in it through webhook calls i would like to get all the details
Ok, but if you track 'usage' externally to Stripe then we cannot account for that in proration: https://stripe.com/docs/billing/subscriptions/usage-based
So this, just isn't possible in your current setup
what about this?
Are you able to just share the sub_xxx ID you're updating?
unable to understand can you elobrate
Can you share the ID of the Subscription you're updating in this screenshot?
sub_1N3dr3SGNnwNJbGSVLMYQ7K0
Hi! I'm taking over this thread.
Can you try to summarize what exact you are trying to do?
on an ongoing subscription can I apply trial_end
then this occured
I'm sorry I don't understand. Can you clarify with a concrete example of what you are trying to achieve?
wait i am up with a new error
Can you share the request Id (req_xxx) with the error?
I am trying to update the user plan with proration_behavior='none'
and after changing it I am trying to add the trial period to the new user update subscription plan
through the below Python code
`trial_period_days = 10
trial_end = int((datetime.utcnow() + timedelta(days=trial_period_days)).timestamp())
subscription = stripe.Subscription.modify(
subscription_id,
proration_behavior='none',
items=[subscription_item],
)
subs=stripe.Subscription.modify(subscription.id, trial_end=trial_end)`
here then why the payment is deducted in the update of the plan when I am passing proration_behavior='none'
you don't pass proration_behavior='none' on the second call to .modify, so it will prorate(since the default is to prorate if you don't explicitly pass the parameter to say to not do it).
is this the correct way to accept the payment at the time of update and also provide user free trial
it seems like a reasonable approach, you'd need to test it exactly against your requirements. I don't really understand the use case or what it means to have a trial period after paying(we don't really natively have that concept in our subscriptions API).
can you go through it
here if the user is updating the plan then instead of returning the user the proration amount we try to give some amount of free trial days on his new subscribtion
sounds good. do you have any specific outstanding questions?
sure, what specific problem are you having?
here if i am changing my code
subs=stripe.Subscription.modify(subscription.id, proration_behavior='none',trial_end=trial_end)
and try to update my plan then the payment for the new plan is not done
but I want the payment to be deducted on the plan update and also add free trial days to it
it's expected there is no payment since you pass proration_behavior='none' which tells us to not calculate the prorated amount , so the change is made and there's no charge for it.
but I want the payment to be deducted on the plan update and also add free trial days to it
which payment?
Let's take an example.
You have a subscrption, started on May 1st. It's a plan that costs $100 a month. The next billing date is June 1st, when they'll pay $100.
It's now May 3rd. You want to switch to a plan that costs $200 a month.
What do you want to happen? what should the customer pay now? When is their next billing date? How much do you want them to pay then?
when the user changes the plan to $200 then I want that amount of $200 payment should be deducted from the user and apart from that I want to add some free trial days(10 days) to the new plan so now the user's next subscription bill become from 13 June to 13 july of $200
Then the easiest way to do that is to manually add an invoice item for $200 directly and set the trial period, and disable our proration entirely.
I don't have an example in Python, but for example like this :
await stripe.subscriptions.update(subscription.id,{
// change to $200/month plan
items:[{id:subscription.items.data[0].id, price : "price_1N3ey4JoUivz182DMj7rTY8v"}],
// no proration, we'll do it manually ourselves
proration_behavior:"none",
// also add a trial period to change billing date
trial_end:moment().add(10,'days').unix(),
add_invoice_items:[{
// add a one-time manual $200 fee
price_data:{
currency:"eur",
unit_amount:20000,// $200.00
product:"prod_MyqWOLS4XDRcM5"
}
}]
})
I guess you actually want more like trial_end: "<end of current period> + 10 days", that can be done too.
how?
you add 10 days to subscription.current_period_end and pass that
like instead of using datetime.utcnow() in your calculation above where you add 10 days to it, use subscription.current_period_end (to get the current next billing date of the subscription)
but i want trial period only for the first month
after that normal 30 days
not sure what that means.
what I'm describing will do what you said you wanted. For example this will charge $200 now, add 10 days to the next billing date(so if it was 1st of June, now it will be the 10th of June), and then from that point onwards it will charge $200 every month on that date.
await stripe.subscriptions.update(subscription.id,{
// change to $200/month plan
items:[{id:subscription.items.data[0].id, price : "price_1N3ey4JoUivz182DMj7rTY8v"}],
// no proration, we'll do it manually ourselves
proration_behavior:"none",
// also add a trial period to change billing date
trial_end:moment.unix(subscription.current_period_end).add(10,'days').unix(),
add_invoice_items:[{
// add a one-time manual $200 dfee
price_data:{
currency:"eur",
unit_amount:20000,// $200.00
product:"prod_MyqWOLS4XDRcM5"
}
}]
})
I highly suggest doing some testing of this and experimenting with your code for calculating the trial_end timestamp to see what you can do.
I have to leave @hollow atlas and we've been helping you for over three hours now which is a lot, so we're going to close the thread for now if that's ok so you can go and experiment.
here once the invoice is created then its payment is not done automatically instead I get the payment failed for it
why did it fail?
you can investigate that yourself by clicking into it and investigating through the dashboard. We can't tell you from just a screenshot.
trial_period_days = 5
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'],
}
}]
)
here is the code
I don't need the code really
you can investigate through your dashboard why the payment failed and if you're not sure, you can share the ID of the Invoice/the PaymentIntent.
in_1N3fKRSGNnwNJbGSKuDWZWhD
why do you think it failed?
sorry but you need to do some investigation/understanding yourself before asking things here, we have limited resources to be able to help.
I assume here the problem is the payment needs 3D Secure authentication. To handle that you'd need to redirect the user to the hosted_invoice_url of the Invoice so they can pay there, or handle the invoice.payment_intent.client_secret in your own custom frontend page.
I have to leave sorry. I suggest taking some time to experiment/investigate/try things out on your end.
can you provide some resource for that
Hello ๐
Stepping in here
Resources for what exactly?
.
We don't have any docs on that really but My colleague explained it in detail above.
but i got this error there
can you tell what changes i need to do in the code
My colleague also shed some light on that above and provided guidance on how you can approach the solution
I assume here the problem is the payment needs 3D Secure authentication. To handle that you'd need to redirect the user to the
hosted_invoice_urlof the Invoice so they can pay there, or handle theinvoice.payment_intent.client_secretin your own custom frontend page.
I have to leave sorry. I suggest taking some time to experiment/investigate/try things out on your end.
can you please tell how can i redirect
hosted_invoice_url
When the invoice payment fails, we send you a invoice.payment_failed webhook event
That event payload is an invoice object.
Each invoice has a property called hosted_invoice_url that can be used to pay for the invoice
https://stripe.com/docs/api/invoices/object#invoice_object-hosted_invoice_url
Your app will have to redirect the users whose payment failed to that URL and have them pay for the invoice there
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.