#mike-invoice-response

1 messages · Page 1 of 1 (latest)

gray wraithBOT
vernal phoenix
#

Hi 👋 are these two separate tasks, or is the one-off Invoice related to the upgrading of the plan?

heavy coral
#

the same task

#

@vernal phoenix i want to create a one off invoice for a plan upgrade

vernal phoenix
#

I can't, that link seems to take me back to our server.

heavy coral
#

the recurring amount remains the same after the oneoff invoice upgradwe

#

i am doing this, because i want to create a manual prorated amount

vernal phoenix
#

The reason I was asking if this was related to an existing Subscription, is because it may be easier to add the additional amount to the next Invoice for that Subscription unless that doesn't fit the business scenario that you're trying to model.

heavy coral
#

I want to bill immediately once the user upgrade

vernal phoenix
#

Are you also going to change the billing cycle anchor as part of the upgrade?

heavy coral
#

no , just the amount

#

its a oneoff invoice so the recurring amount on the plan should bill the next cycle

vernal phoenix
#

Gotcha, and what troubles are you running into when trying to create the one-off Invoice?

If you're looking for a place to get started, then this quickstart guide helps show what steps need to be completed and the associated code for them:
https://stripe.com/docs/invoicing/integration/quickstart

heavy coral
#

i want to send a sample code, why am i doing doesnt seem to work

#
   subscription = stripe.Subscription.retrieve(sub_id)
        print(f'subscription  {subscription} {subscription.id}')
        stripe.InvoiceItem.create(
            customer=user_result['customer'],
            currency='USD',
            unit_amount=90000,
            subscription=subscription.id
        )
        invoice = stripe.Invoice.create(customer=user_result['customer'])
        print(f"invoice {invoice}")

        upgrade_result = stripe.Subscription.modify(
            subscription.id,
            cancel_at_period_end=False,
            proration_behavior='always_invoice',
            items=[{
                'id': subscription['items']['data'][0].id,
            }],
            trial_end='now',
        )
        print(f"upgrade_result {upgrade_result}")
    except Exception as e:
        return Response(
            status_code=400,
            content_type="application/json",
            body=json.dumps({"errors": str(e)})
        )
vernal phoenix
#

Sure, while you do that, are there any errors that you're encountering either during compilation or execution?

heavy coral
#

no, its not doing the right thing and the invoice isnt billed immediately

#

hi

vernal phoenix
#

What do you mean when you say "it's not doing the right thing"?

It looks like the Invoice you're creating won't contain the Invoice Item that you're creating because you're associating the Invoice Item with a Subscription, and since the Invoice is not connected to that Subscription it isn't pulling in the Invoice Item:
https://stripe.com/docs/api/invoiceitems/create#create_invoiceitem-subscription
I think you'll want to omit this line:
subscription=subscription.id

You're also not creating a one-off Invoice in that snippet.

Additionally, since you're using proration_behavior-'always_invoice', I believe your request is updating the Subscription and changing the billing cycle anchor. I believe you'll want to use none since you're creating a separate Invoice Item to charge the custom prorated amount.
https://stripe.com/docs/api/subscriptions/update#update_subscription-proration_behavior

heavy coral
#

ok

#

let me see how this work

#

how do i associate the invoice with the subscription

vernal phoenix
#

You don't, it's a one-off Invoice so it is separate from a Subscription.

heavy coral
#

ok, but how does the user know what i am charging him for and also will this be billed immediately

vernal phoenix
heavy coral
#

ok

#

so how do i upgrade the user to a new plan

#

after creating the invoice

vernal phoenix
heavy coral
#

ok, i will try this now

vernal phoenix
#

Apologies, I sent that message to the wrong chat.

heavy coral
#

ok

#

also, I hope the upgrade wont bill immediately?

vernal phoenix
#

It depends on what you're passing for proration_behavior, since you're creating a separate one-off Invoice for the proration amount I believe you'll want to use none for that parameter.

heavy coral
#

ok

#

Oh i forgot

#

is it possible to create a custom amount for the upgrade instead of using the product price id

vernal phoenix
#

You would use the price_data hash (instead of the price field) to provide the necessary details to create a new Price ad-hoc.
That hash is the parameter immediately below the price parameter that I linked to previously.

heavy coral
#

ok, this is what i was thinking

#

i want the upgrade to contain a manual prorated amount that should only billed once.
the recurring amount should work as a expected for the next billing cycle

#

eg prorated amount is $900
i want the upgrade to automatically bill this use 900 immediately .
and leave the prorated amount 1800 for the next cycle

vernal phoenix
heavy coral
#

let me explain

#

I want to implement an upgrade feature

  1. generate a manual prorated amount
  2. pass that amount to the upgrade api so that that amount can be billed immediately.
#

3: the user plan is upgraded and the next billing cycle should contain the original upgrade amount

#

@vernal phoenix

vernal phoenix
#

But you don't want to change the billing_cycle_anchor when you do the upgrade, right? So then you'll need to use a one-off Invoice to charge immediately for the prorated amount, which is what the flow we've been talking through should accomplish. Is the flow we've talked through still not meeting your criteria?

heavy coral
#

the upgrade is still creating a prorated amount \

vernal phoenix
#

Can you share the ID of the request you're making to update the Subscription?

heavy coral
#

how do i get this

vernal phoenix
heavy coral
#

ok

#

req_9pKKEB69vZCqfn

vernal phoenix
#

Thank you, I'm taking a look.

#

You're passing now for trial_end, but it doesn't look like the Subscription was created with a trial period so I don't think you want to do that.

I suggest you remove this line:
trial_end='now',

heavy coral
#

ok

#

some subscriptions are created with trial

#

The major reason I am creating manual proration is because. When a plan is on trial and the user upgrades. The upgrade is done on that trial and so no amount will be charged

#

how can I move a trial plan to an upgrade active plan

vernal phoenix
#

Oh, actually, I think you're still seeing prorations because you aren't providing proration_behavior='none', so the system is following default behavior which is to create prorations.

#

trial_end='now' is the right way to end a trial, but I'm not sure off-hand what happens if you provide that to a Subscription that didn't have a trial period already. I thought that might be where the prorations you're seeing are coming from, but now I think that's because you aren't disabling prorations.

heavy coral
#
upgrade_result = stripe.Subscription.modify(
            subscription.id,
            proration_behavior=None,
            cancel_at_period_end=False,
            items=[{
                'id': subscription['items']['data'][0].id,
                'price': price_id,
            }],
            trial_end='now',
        )
#

i already did this

vernal phoenix
#

The request you shared showed that proration_behavior was not received as an input, and looking at your code that may be because you aren't passing the string 'none' to the parameter. It looks like you're providing the None keyword instead, which is like passing a null value so the API ignores the field.

Can you try updating your code to contain this instead:
proration_behavior='none'

heavy coral
#

ok thanks

#

it worked as expected but i cant find the one off invoice that should be created

vernal phoenix
#

The ID for it should be returned in the response to your request to create the Invoice, in the id field.

heavy coral
#

sorry i dont get

vernal phoenix
last roost
#

mike-invoice-response

heavy coral
#

ok let me test

#

hi

#

are you saying i should include the invoice id in the subscription update endpoint

last roost
#

no

heavy coral
#

ok, what should i do with this

last roost
#

Hey @heavy coral I'm sorry I have no idea what you're asking or what's confusing you. I will need you to provide a lot more context around what is blocking you, all in one message, with exact code and what is not working for you in the response