#Yashish

1 messages ยท Page 1 of 1 (latest)

cloud fjordBOT
clever fiber
#

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.

hollow atlas
#

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.

clever fiber
#

There is not

hollow atlas
#

can i explain you my scenario so that you can suggest me what can i do in it?

clever fiber
#

Sure, go ahead

hollow atlas
#

If the user updates his subscription can there be any way we can decide what should be the proration amount?

clever fiber
#

You can't stipulate the prorated amount manually, no. We calculate that based on the parameters used during the update

hollow atlas
#

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.

clever fiber
#

can we add some free days in it for the first-month interval
Sure, you'd just update the Subscription with trial_period_days

hollow atlas
#

but this trial period days should be added to the particular user subscription plan?

#

or it is added to the whole subscription plan

clever fiber
#

I don't understand the question

hollow atlas
clever fiber
#

No, just the sub_xxx ID that pass during the update. Any other Subscriptions on the same plan/price wouldn't be impacted

hollow atlas
clever fiber
hollow atlas
#

unable to find trial_period_days in subscription update

clever fiber
hollow atlas
#

on an ongoing subscription can I apply trial_end?
without changing the subscription plan

clever fiber
#

Yes

hollow atlas
#

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.

clever fiber
#

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 use proration_behavior: 'always_invoice' during your update then we will apply credit for the unused time on the previous plan

hollow atlas
#

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

clever fiber
#

I'm sorry I don't understand what you mean. Can you provide a specific example?

hollow atlas
# clever fiber Yes

hereafter updating the plan if I am trying to add the free trial days then it is also making another payment

hollow atlas
clever fiber
#

Are you using a metered plan with Stripe? Or are you tracking usage externally?

hollow atlas
clever fiber
clever fiber
clever fiber
#

Are you able to just share the sub_xxx ID you're updating?

hollow atlas
#

unable to understand can you elobrate

clever fiber
hollow atlas
#

sub_1N3dr3SGNnwNJbGSVLMYQ7K0

cloud fjordBOT
viscid magnet
#

Hi! I'm taking over this thread.

#

Can you try to summarize what exact you are trying to do?

hollow atlas
viscid magnet
#

I'm sorry I don't understand. Can you clarify with a concrete example of what you are trying to achieve?

hollow atlas
#

wait i am up with a new error

viscid magnet
#

Can you share the request Id (req_xxx) with the error?

hollow atlas
#

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'

stable egret
#

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

hollow atlas
#

is this the correct way to accept the payment at the time of update and also provide user free trial

stable egret
#

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

hollow atlas
stable egret
#

sounds good. do you have any specific outstanding questions?

hollow atlas
#

yes

#

now i am doing the webhook setup for it

#

can you help me in it

stable egret
#

sure, what specific problem are you having?

hollow atlas
#

but I want the payment to be deducted on the plan update and also add free trial days to it

stable egret
#

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.

hollow atlas
#

but I want the payment to be deducted on the plan update and also add free trial days to it

stable egret
hollow atlas
#

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

stable egret
#

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.

stable egret
#

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)

cloud fjordBOT
hollow atlas
#

after that normal 30 days

stable egret
#

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.

hollow atlas
stable egret
#

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.

hollow atlas
#

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

stable egret
#

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.

hollow atlas
#

in_1N3fKRSGNnwNJbGSKuDWZWhD

stable egret
#

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.

hollow atlas
#

can you provide some resource for that

solar swallow
#

Hello ๐Ÿ‘‹
Stepping in here
Resources for what exactly?

solar swallow
#

We don't have any docs on that really but My colleague explained it in detail above.

hollow atlas
#

can you tell what changes i need to do in the code

solar swallow
#

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

hollow atlas
#

can you please tell how can i redirect
hosted_invoice_url

solar swallow
#

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