#abhishek-kumar_subscription-one-time-item

1 messages · Page 1 of 1 (latest)

mild crownBOT
#

đź‘‹ 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.

lapis tulipBOT
#

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.

bold fulcrum
#
        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?

lapis tulipBOT
golden oriole
#

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

mild crownBOT
#

abhishek-kumar_subscription-one-time-item

bold fulcrum
#

So, I have a product with 2 prices:

  1. Metered pricing - Based on number of Requests made
  2. 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.

golden oriole
#

User adds another seat, I want to collect the payment immediately.
Then you just need to increment the quantity for that item

bold fulcrum
#

I'm setting proration_behaviour to none while updating the quantity

golden oriole
#

Do you have an example request ID (req_xxx)?

bold fulcrum
#

Can you please tell me where can I find it?
I'm in developers section of dashboard right now

golden oriole
bold fulcrum
#

checking

bold fulcrum
golden oriole
#

I'd like to see the request where you incremented the quantity as I described but it didn't charge immediately

bold fulcrum
#

got it, jsut creating another for the same and giving

golden oriole
#

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.

https://docs.stripe.com/billing/subscriptions/upgrade-downgrade#changing:~:text=To bill a,the new invoice.

Learn how to upgrade and downgrade subscriptions by changing the price.

bold fulcrum
#

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

golden oriole
bold fulcrum
#

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.

golden oriole
#

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

bold fulcrum
#

yeah, that'd change the billing period itself

golden oriole
bold fulcrum
#

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:

  1. 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?
golden oriole
#

when a customer adds a card can we set that as default automatically?
No, you need to update the invoice_settings[default_payment_method] field on the Customer object

bold fulcrum
#
  1. 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?
bold fulcrum
golden oriole
#

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

golden oriole
#

And then pass the pm_xxx to the payment_method field when calling /pay

bold fulcrum
#

got it awesome!
this'll help me get the invoice paid

bold fulcrum
golden oriole
#

I already did

#

Why not just try the API and see how it behaves?

bold fulcrum
#

alright, I'll check it out.

I tried it but ig my metered usage wasn't billable hence didn't get any extra costs

golden oriole
#

You likely just need to omit the subscription parameter. It's not relevant really as there's no pending items on it

bold fulcrum
#

Got it

#

I just wanted to link the invoice to subscription if it was possible

golden oriole
#

No, that's not possible

#

Perhaps you can leverage metadata on the Invoice

#

But no 'official' way to link it

bold fulcrum
#

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

golden oriole
#

It'll generate an invoice to be paid for the amount you specify yes

bold fulcrum
#

gg ser, this should do it!
I'll try this out and reachout here again if I'm stuck