#beast-subscription-usage
1 messages · Page 1 of 1 (latest)
beast-subscription-usage
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
there's no proation at all with metered billing
What are you really trying to do? Like reset the whole billing cycle?
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?
no you can pass billing_cycle_anchor: 'now' in that case: https://stripe.com/docs/billing/subscriptions/billing-cycle
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
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
yes the customer does
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
how do i write code for it? I use checkout sessions to save the payment method
which I guess I didn't do*
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?
i think I can just use this right
https://stackoverflow.com/questions/70075154/how-can-i-make-the-card-as-the-default-payment-method-during-checkout-flow
yep
cool thanks!
Are you doing this just in Test mode? Or in production?
test mode
ah gotcha
but it's strange. This is the first time i've encountered this error
likely the first time you haven't set up the card properly on the Customer
hm yeah
what language are you using?
node
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
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)
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
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?
no, that code would set the default properly
I mean that Subscription you shared earlier was not created via Checkout at all
ohhhh
you wrote code in Node to create it, see https://dashboard.stripe.com/test/logs/req_BJAuaOCV8y0Bgh
and you never configured it to have the right default
okay I see where the problem is
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
yeah
so you need a default on the Subscription or update the Customer to have the global default
"update the Customer to have the global default" I want to do this
that's the thing you shared from stackoverflow earlier
yeah but that failed because my checkout session is mode 'subscription' not setup
it should be mode subscription?
sorry that;s a lot of really basic things to explain that are all in our docs 😦
hahaha
Like sure the example is for mode setup and you look at SetupIntent. Yours is mode subscription so look at the Subscription
ok np
it'll have default_payment_method set and you want to set that on the Customer in invoice_settings
got it. Thank you beast
so your code is basically always creating 2 separate Subscriptions?
yeah
can I ask why? No pressure, I'm just curious
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?
they totally can
🙂
nooo way
You can have up to 20 Prices on one Subscription and you can mix usage
just the billing cycle has to be the same
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?
yep
you need to keep track of their PaymentMethod(s) and make sure you pick the right default
is there a guide for that ^?
not really sorry
yeah if you have 2 billing cycles there's no other choice that isn't as hacky
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
unfortunately no, none of that exists today, you have to keep track of it