#mike-invoice-response
1 messages · Page 1 of 1 (latest)
Hi 👋 are these two separate tasks, or is the one-off Invoice related to the upgrading of the plan?
the same task
https://discord.com/channels/841573134531821608/841573134531821616/threads/1055200013162123295
can you see this thread , i had a convo with a stripe person
@vernal phoenix i want to create a one off invoice for a plan upgrade
I can't, that link seems to take me back to our server.
the recurring amount remains the same after the oneoff invoice upgradwe
i am doing this, because i want to create a manual prorated amount
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.
I want to bill immediately once the user upgrade
Are you also going to change the billing cycle anchor as part of the upgrade?
no , just the amount
its a oneoff invoice so the recurring amount on the plan should bill the next cycle
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
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)})
)
Sure, while you do that, are there any errors that you're encountering either during compilation or execution?
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
You don't, it's a one-off Invoice so it is separate from a Subscription.
ok, but how does the user know what i am charging him for and also will this be billed immediately
You will likely need to show that information to your user/customers, and how the Invoice is billed depends on the collection_method that you specify when creating it (charge_automatically sounds like it is what you're looking for):
https://stripe.com/docs/api/invoices/create#create_invoice-collection_method
You create a request to update the Subscription, changing the ID of the Price object that is provided for the entry in the items array that you want to update:
https://stripe.com/docs/api/subscriptions/update#update_subscription-items-price
ok, i will try this now
Apologies, I sent that message to the wrong chat.
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.
ok
Oh i forgot
is it possible to create a custom amount for the upgrade instead of using the product price id
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.
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
Sorry, I don't understand what you're saying here, I'm confused by the changing prorated amounts.
let me explain
I want to implement an upgrade feature
- generate a manual prorated amount
- 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
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?
the upgrade is still creating a prorated amount \
Can you share the ID of the request you're making to update the Subscription?
how do i get this
You can find them in the logs page in the developers section of the Stripe dashboard, this article walks through the process in more detail:
https://support.stripe.com/questions/finding-the-id-for-an-api-request
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',
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
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.
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
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'
ok thanks
it worked as expected but i cant find the one off invoice that should be created
The ID for it should be returned in the response to your request to create the Invoice, in the id field.
sorry i dont get
When you make a request to this endpoint to create an Invoice, the response that you receive includes the Invoice object.
https://stripe.com/docs/api/invoices/create
The id field that is included is the unique identifier for the Invoice:
https://stripe.com/docs/api/invoices/object#invoice_object-id
If you look at your request to create an Invoice in the dashboard, you'll see the response includes the Invoice object:
https://dashboard.stripe.com/test/logs/req_DXDPKb9dUsei40
mike-invoice-response
ok let me test
hi
are you saying i should include the invoice id in the subscription update endpoint
no
in the response to the Update Subscription API request there will be a Subscription object returned (https://stripe.com/docs/api/subscriptions/object) and that has the latest_invoice property with the id of the most recent Invoice created
ok, what should i do with this
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