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
Related
I am having a hard time finding the right webhooks in Stripe to use since it seems a lot of get fired off for multiple situations.
So my site sells a few items (like 10) that can be bought as a single purchase or a subscription (you get the item every X days, no SASS jut products). I am using Stripe's Checkout and Portal to handle all subscriptions and single purchase and those parts work great. Person adds stuff to cart, checkouts out, pays, we are all good. The issue is adding an order to our system from the webhook.
Look at this scenario: a person adds 2 single items and 1 subscription to their cart. They checkout and pay. When that happens we had the checkout.session.completed catching the checkout session was completed and we add those items from their cart to an order. The subscription re-ups after "X" Days we would listen for the invoice.payment_succeeded webhook to create a new order in our system. This logic is flawed though since invoice.payment_succeeded is called on the first order too so basically when they checkout our system adds 2 subscription orders: one from the checkout.session.completed and one from the invoice.payment_succeeded. How can we handle this?
What I would like to have is:
1 webhook to know when the checkout is complete and is only called then, which they do: checkout.session.completed
1 webhook that is only called when a subscription is renewed, not also when created, which I cant find.
If they dont have that webhook for subscription renewals only, how can I tell in the "invoice" object is the very first one so I dont do anything on checkout, only create a new order on renewal?
Instead of using invoice.payment_succeeded you should consider using invoice.paid, as it will also fire when you mark an Invoice as paid out-of-band (which won't happen with invoice.payment_succeeded). Both describe an Invoice, so you should be able to switch between them with minimal or no changes to your code.
You're correct that there is no Event specific to renewals for a Subscription only, but you can use the billing_reason property on an Invoice to determine why the Invoice was created. If it's the first Invoice for a new subscription the Invoice will have billing_reason set to subscription_create.
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.
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.
Trying to engineer a payment system with stripe that will bill the customer on a weekly basis. The customer can have as many documents but each one is charged weekly. So if the customer has 2 documents he would have 2 charges every week until he canceled both or one of them. I would like to be able to have a detailed email invoice too.
Would the best way to do this would just keep updating the subscription quantity every time one is added or deleted. Or is there a better way to do this.
AKA: I am new to online payments
You can create the plan on Stripe with a validity of 7 days and subscribed the customer to that plan on the recurring basis. So the customer will be charged automatically every week.
For the quantity, you can change the quantity of subscription on stripe or you can subscribe a customer to different weekly plans(If you have different documents rate)
For sending an email just enable invoice email from admin setting and each time customer will pay an email will be sent.
I have a recurring subscription service using Stripe. An additional Invoice Item is added to each invoice.
When a new user wants to subscribe to my service, the steps are:
create user (if not already existing)
create invoice item (will be added to the next invoice)
create subscription for the user (creates an invoice)
The problem is when the card is valid but can't be charged: the invoice isn't created, and the item stays in pending state, waiting for the next invoice.
Each time the customer retries, there is one more pending item, and if it finally works, he has to pay for the normal price and all the pending items.
What's the best way to handle this kind of thing?