#beast-subscription-usage

1 messages · Page 1 of 1 (latest)

dawn cobaltBOT
glad saffron
#

beast-subscription-usage

limber oar
#

const subscriptionUsageUpdated = await stripe.subscriptions.update(
subscription_usage.id,
{
cancel_at_period_end: false,
proration_behavior: "always_invoice", // prorate charge at EOM
items: [
{
id: subscription_usage.items.data[0].id,
price: subscriptionItems.report_id,
},
{
id: subscription_usage.items.data[1].id,
price: subscriptionItems.white_label_id,
},
{
id: subscription_usage.items.data[2].id,
price: subscriptionItems.invoicing_id,
},
],
}
);

I thought I just have to set protation_behavior to always_invoice but that doesn't do anything and just carries the usages over

glad saffron
#

there's no proation at all with metered billing

#

What are you really trying to do? Like reset the whole billing cycle?

limber oar
#

Hmm now that you mention that, I guess I would be resetting the billing cycle

#

So would I just cancel the subscription and create a new one for them?

glad saffron
limber oar
#

Got it! Let me try that

#

hm when I tried to do that I got an error that the customer has no payment method attached and the subscription failed to update. Not sure why this happened because the test customer does have a payment method and the plan subscription was able to upgrade

sub_1Nim4SE1KiUDtCG0whoIoozo

glad saffron
#

when you change the billing cycle that way it tries to charge immediately. Does your Customer have a default PaymentMethod or at least the Subscription? If not that's your issue

limber oar
#

yes the customer does

glad saffron
#

I mean it doesn't

#

it has a PaymentMethod, not a default one

#

you didn't configure the Customer/Subscription properly

#

you can manually make it the default in the Dashboard or write code for it

limber oar
#

how do i write code for it? I use checkout sessions to save the payment method

#

which I guess I didn't do*

glad saffron
#

Sorry there are 200 ways to integrate Stripe. What does

I use checkout sessions to save the payment method
mean?

#

Like you did setup mode?

glad saffron
#

yep

limber oar
#

cool thanks!

glad saffron
#

Are you doing this just in Test mode? Or in production?

limber oar
#

test mode

glad saffron
#

ah gotcha

limber oar
#

but it's strange. This is the first time i've encountered this error

glad saffron
#

likely the first time you haven't set up the card properly on the Customer

limber oar
#

hm yeah

glad saffron
#

what language are you using?

limber oar
#

node

glad saffron
#
  payment_method: 'pm_card_visa',
  invoice_settings: {
    default_payment_method: 'pm_card_visa',
  },
});```

If you create a Customer this way, it has a card PM attached and it's already the default. Makes it a lot easier to write tests
limber oar
#

gotcha! But I encountered this error when going through the flow in my app in local (create an acount on the app -> purchase subscription -> upgrade subscription)

glad saffron
#

not sure what you mean unfortunately. Really what matters is making sure you have a default PaymentMethod set. It's crucial for Subscriptions. So however you set up your Subscription is incorrect if you don't have that

limber oar
#

Let me clarify, when they want to buy a subscription, I link them to the checkout page w the following code

const session = await stripe.checkout.sessions.create({
mode: "subscription",
customer: customer_id,
line_items: [
{
price: plan_price_id,
quantity: 1,
},
],
success_url: process.env.CHECKOUT_SUCCESS_URL,
cancel_url: process.env.CHECKOUT_FAILURE_URL,
});

After this, I never wrote any code to save to a default payment method or anything else. So do I need to write code to do this?

glad saffron
#

no, that code would set the default properly

limber oar
#

right that's what I thought

#

so why did I get that error hahaha

glad saffron
#

I mean that Subscription you shared earlier was not created via Checkout at all

limber oar
#

ohhhh

glad saffron
#

and you never configured it to have the right default

limber oar
#

okay I see where the problem is

glad saffron
#

I assume that Customer has another Subscription with a default set

limber oar
#

When they buy a 'tier' subscription - lets say a pro subscription - we create a usage subscription for them that depends on the pro plan on the checkout.session.completed event. So when I create this usage subscription, I don't specify a default payment method

glad saffron
#

yeah

#

so you need a default on the Subscription or update the Customer to have the global default

limber oar
#

"update the Customer to have the global default" I want to do this

glad saffron
#

that's the thing you shared from stackoverflow earlier

limber oar
#

yeah but that failed because my checkout session is mode 'subscription' not setup

#

it should be mode subscription?

glad saffron
#

sorry that;s a lot of really basic things to explain that are all in our docs 😦

limber oar
#

hahaha

glad saffron
#

Like sure the example is for mode setup and you look at SetupIntent. Yours is mode subscription so look at the Subscription

limber oar
#

ok np

glad saffron
#

it'll have default_payment_method set and you want to set that on the Customer in invoice_settings

limber oar
#

got it. Thank you beast

glad saffron
#

so your code is basically always creating 2 separate Subscriptions?

limber oar
#

yeah

glad saffron
#

can I ask why? No pressure, I'm just curious

limber oar
#

because we have 3 possible tiers where each tier corresponds to a different usage price

#

tiers cost x a month

#

and usages and fixed amounts cant be on the same subscription, right?

glad saffron
#

they totally can

limber oar
#

at least that's what I understood from the docs

#

wtf

glad saffron
#

🙂

limber oar
#

nooo way

glad saffron
#

You can have up to 20 Prices on one Subscription and you can mix usage

#

just the billing cycle has to be the same

limber oar
#

ahhhhh yes that was the problem

#

because we want to charge the usages monthly

#

and the tiers can be annual or monthly subscriptions

#

so to cover both cases it'd just be easier to make them all separate

#

was i dumb to do that lol

#

One more question - sorry. So lets say upon checkout i make the customer's default payment method whatever they used for it. If they remove this payment method and add a new one, will my code fail because now there's no 'default payment method' for the customer? So will I need to use the paymentmethod.attached event to always update whatever they add as their default payment method?

glad saffron
#

yep

#

you need to keep track of their PaymentMethod(s) and make sure you pick the right default

limber oar
#

is there a guide for that ^?

glad saffron
#

not really sorry

limber oar
#

hm ok

#

so was it okay that i made two subscriptions lol

#

you have me intrigued...

glad saffron
#

yeah if you have 2 billing cycles there's no other choice that isn't as hacky

limber oar
#

is there anything we can configure in stripe settings to select any one of the available payment methods the customer has on their profile as default if they don't have a default payment method set?

#

yeah okay fair

glad saffron
#

unfortunately no, none of that exists today, you have to keep track of it

limber oar
#

got it

#

alright that's all from me

#

thank you legend

#

got the usages working

#

lfg