#abhishek-kumar_subscription-one-time-item
1 messages · Page 1 of 1 (latest)
đź‘‹ Welcome to your new thread!
⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đź”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1222838199236427909
📝 Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- abhishek-kumar_docs, 12 hours ago, 68 messages
- abhishek-kumar_docs, 17 hours ago, 16 messages
await stripe.subscriptionItems.update(seatItem.id, {
quantity: orgMemberships.length,
proration_behavior: "none",
});
console.log({ seatItem });
const invoice = await stripe.invoices.create({
customer: subscription.customer.toString(),
});
// TODO(abhishek): create invoice and charge immediately
await stripe.invoiceItems.create({
customer: subscription.customer.toString(),
price: "price_id",
invoice: invoice.id,
});
console.log({ invoice });
await stripe.invoices.pay(invoice.id);
Here's the code snippet I'm using, I'd love to get some support as to what's wrong?
Do I have to pass subscription id while creating an invoice?
Hi! The error implies that seatItem.id in your code is nullish
What specifically are you trying to do? What you describe isn't really possible – you can't add a one-time item to a subscription or 'add' an invoice to a subscription
If the intention is to add a one-time item to the next invoice on the subscription, then use this parameter in your update call: https://docs.stripe.com/api/subscriptions/update#update_subscription-add_invoice_items
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
abhishek-kumar_subscription-one-time-item
So, I have a product with 2 prices:
- Metered pricing - Based on number of Requests made
- Per seat pricing - $10 / seat based on users invited
Per seat pricing is a flat-price pricing
And upon every addition, I want to charge the user upfront.
eg.
1 Jan,
User subscribes to product and pays $10 for 1 seat.
10 Jan,
User adds another seat, I want to collect the payment immediately.
To do this, I've added another one_time pricing in my product and when user adds seat then I want to immediately charge them with $10 by creating an invoice and calling the /pay endpoint.
I want charge the user for this seat right when they add it, and if possible show it in subscription as well.
User adds another seat, I want to collect the payment immediately.
Then you just need to increment the quantity for that item
But that wouldn't charge immediately right?
I'm setting proration_behaviour to none while updating the quantity
Do you have an example request ID (req_xxx)?
Can you please tell me where can I find it?
I'm in developers section of dashboard right now
Find help and support for Stripe. Our support site provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
checking
alright, got the req_id section
You want a request in which I'm getting the error I mentioned above right?
I'd like to see the request where you incremented the quantity as I described but it didn't charge immediately
got it, jsut creating another for the same and giving
Passing proration_behaviour: 'none' will likely be the issue:
To bill a customer immediately for a change to a subscription on the same billing cycle, set proration_behavior to always_invoice. This calculates the proration, then immediately generates an invoice after making the switch. Combine this setting with pending updates so the subscription doesn’t update unless payment succeeds on the new invoice.
yeah, correct but with this the customer will be billed with prorated amount. for how many ever days they can use the seat.
if just 5 days left for billing then they'll be charged around: $3 ( example )
But I want full seat to be charged.
req_O6Klve9fXjDgKS
This is the req_id for the subscription updation
That's just not really possible today
correct, so for this I'm charging the customer with a one_time pricing.
Generate the invoice and have it paid.
And update the subscriptino with the same quantity so that from next month onwards the updated quantity is billed
But I'm facing some issues with the invoice generation and payment.
You'd need to reset the billing anchor to now in the same update, but that will charge the full amount for all items on the subscription
yeah, that'd change the billing period itself
OK, so coming back to this. What's the issue?
I saw the tip you gave to check the seatItem making sure it's not nullish and tried that. it worked but I got few queries:
- I see a default_payment_method has to be present to be able to charge the invoice automatically, when a customer adds a card can we set that as default automatically? Or can we pick the first payment method from whatever the customer has added and use it to charge for the invoice?
when a customer adds a card can we set that as default automatically?
No, you need to update theinvoice_settings[default_payment_method]field on the Customer object
- While creating an invoice, if I pass the subscription Id then that'd just bill the metered product as well right? Is there any way around it?
Okay, and this is something to be done by us right?
No default option or a way where we can query all the payment methods of a customer and pick the first method to process this invoice?
, if I pass the subscription Id then that'd just bill the metered product as well right? Is there any way around it?
That parameter doesn't work like you expect:
If set, the created invoice will only include pending invoice items for that subscription. The subscription’s billing cycle and regular subscription events won’t be affected.
Yes, you'd make an API call to update the field. You can list all PMs saved for a Customer sure: https://docs.stripe.com/api/payment_methods/customer_list
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
And then pass the pm_xxx to the payment_method field when calling /pay
got it awesome!
this'll help me get the invoice paid
Can you please give me some more clarity on this?
alright, I'll check it out.
I tried it but ig my metered usage wasn't billable hence didn't get any extra costs
You likely just need to omit the subscription parameter. It's not relevant really as there's no pending items on it
No, that's not possible
Perhaps you can leverage metadata on the Invoice
But no 'official' way to link it
ahh, I see
metadata can help yes
but alright, this solves most of it.
Create an invoice with one time pricing and charge with the appropriate payment method from customer's payment method.
and update the quantity in subscription as well for next month's payments.
This would help me charge the customer immediately for the seat in the current billing cycle itself.
right?
wanted to confirm this
It'll generate an invoice to be paid for the amount you specify yes
gg ser, this should do it!
I'll try this out and reachout here again if I'm stuck