Stripe - possible for zero quantity subscription - stripe-payments

I have a subscription plan on stripe, and use this for per seat pricing.
The specific use case is:
Customer has previously paid and so has customer id and subscription id in the database
They remove all of their users one month
The next month they add a user again
I want the end date to have been updated to the end of the current month when the bill period rolls over, so that I don't display a message saying they didn't pay for previous bill period.
In the stripe subscription object, can I set the quantity for the subscription to 0, meaning the customer won't get billed?
If I do this, will the webhook for invoice.payment_succeeded still be called? This allows me to update information in the database.
Is there a different webhook I should be using for this?

Yes if you will set quantity of subscription to 0 then still a zero dollar invoice still come in payment_succeeded webhook and will update the invoice.

Related

How to give discount on new Stripe subscription?

We have a free subscription concept separate from Stripe. When a user signs up for a paid subscription we want to charge them immediately but still honor any remaining free-period.
I know I can use trial period to delay the start of the Stripe subscription, but we wanted to charge immediately to confirm valid credit card details. Is it possible to give a discount on a new subscription instead, to account for the users remaining free-time?
For example, if
today is the 1st
user has free subscription until 15th
monthly subscription is $10
I would like to charge them $5 today and immediately begin their subscription in Stripe with a Stripe renewal on the next 1st.
Easiest way to do this is to add an invoice item for the amount you want to charge and set a trial period until you want the renewing charge to occur (so in your example you set a trial_end for the next 1st of month). This will generate an initial invoice with the invoice item and then set your recurring payment as you desire.

Stripe subscription set billing date as first of each month

I'm using Stripe Checkout flow to collect the users' payment details and automatically collect the subscription. I have also implemented webhooks to listen to checkout.session.completed so that I can edit the subscription. What I want is as follows:
Say, the user registers on January 15th. I'm using metered billing, so the user pays $0.00 on the first invoice.
In webhooks, I apply a trial period of 7 days to the subscription like so stripe.subscriptions.update([id], {trial_end: [seven_days_into_future]}). So the billing anchor date on the subscription becomes the 22nd of each month.
However, I would like to set the billing anchor date as the first day of each month. So I would like the user to receive the first invoice for January 22-31 (prorated), and then get invoices for full calendar months onwards.
How do I achieve that?
I cannot set the billing_cycle_anchor to the desired date because it accepts only now and unchanged values...
If you're working with already created subscriptions, then you'll need to add trial periods to shift the billing_cycle_anchor:
https://stripe.com/docs/billing/subscriptions/billing-cycle#using-a-trial-to-change-the-billing-cycle
If you know exactly how you want to structure your trial and billing_cycle_anchor at the time the subscription is being created, then you can future-date the billing_cycle_anchor during creation:
https://stripe.com/docs/billing/subscriptions/billing-cycle#new-subscriptions

Stripe Start Date

How do you set the start date for a subscription? Many of our customers began using our service a few days before we could collect their payment information so we'd like to charge them for these additional days.
This is not something that the Subscriptions API supports today. You would need to charge your customer the full amount and then put them on a trial period until their next billing date.
The flow would look like this:
Create a Customer with the card token
Create an invoice item for the plan amount
Create a subscription and set them on a trial period until their next billing date using trial_end
The last step will create an invoice for the trial, automatically pull the pending invoice item into the invoice and charge the customer for that amount. Then, they won't be charged until the date you set in trial_end and each month moving forward on that date.

Stripe monthly subscription with annual payment?

What is the best way to subscribe my users to a plan that renews monthly yet bills yearly using stripe subscriptions, as i contacted Stripe's support and they said a plan with an interval of month and interval_count of 12 will not generate any events (ex: customer.subscription.updated event) until the end of the 12 months interval while i need these events to be generated on monthly basis.
The best solution here would be to subscribe the customer to a $0 monthly plan. This ensures that, each month, a new billing cycle starts and a new invoice is created. The invoice will be for $0 but send an invoice.created event to your webhook endpoint.
There, you can decide whether you need to bill the customer anything or not. If you don't, you simply ignore the event and the customer won't be charged anything. If you do, you will simply add an invoice item for the correct amount to this invoice. This is covered in the Invoices section of Stripe's documentation.
For the first invoice, you would add the invoice item first which means three steps:
Create the customer
Create the invoice item for the correct price
Create the subscription to the $0 monthly plan
The last step will automatically pull the invoice item in the invoice and charge them that amount as expected.
If you have follow up questions, I'd recommend talking to Stripe's support here.

Adding shipping to first subscription invoice using stripe

I am integrating stripe to enable the user to subscribe to a physical product shipping to the US and Canada.
I want to use the invoice.created webhook to modify the invoice and add a shipping charge depending on the delivery address.
The problem according to stripe docs is that the first invoice is charged immediately, implying that I cannot modify it prior to the first charge as I could with the subsequent.
If this is so, then the only way around this I believe is to add plans for us and canada for each of the subscription intervals e.g product-weekly-us, product-monthly-us, product-weekly-ca, product-monthly-ca instead of just product-monthly, product-weekly
The shipping would then be static (no line item) and part of the total.
Edit
So looking into invoices from koopajah's answer, here is what I can work out (please confirm):
Create the invoice items for your customer (pending invoice items) - does this exclude the line item for the subscription?
Create the subscription for the customer (which adds those pending invoice items to the new invoice for the subscription) - this will fire invoice.created webhook, which you would have to inspect and ignore - would you have to track the invoice numbers? **edit: oh wait! It would be closed, so you can just check that :D **
All subsequent invoices are modified with the invoice.created webhook for open invoices
If you want to keep using Invoice Items you just have to create one for the first cycle before creating your user subscription. Then once the subscription is created the first invoice will be created and automatically pick up the Invoice Item for your current customer.
You can then create the next Invoice Items in the webhook as you planned to do.
EDIT:
The steps would be something like that:
Create a Customer with the Stripe token
Create an Invoice Item for this customer for the shipping amount (not the subscription one)
Create the subscription for this customer which will automatically add the Invoice Item created at step 2 to the total charge
6.... In the webhook "invoice.created" check whether the invoice is closed and if not repeat step 2 also adding the current invoice identifier to the invoice parameter

Resources