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?
Related
My use-case is that whenever I have a trial subscription, once the trial ends and the user has no payment method on stripe, I simply want to cancel the subscription instead of generating an invoice. Is there a way to configure this on Stripe or would it need an external task to run each day and do this for me?
A new invoice will always be generated when a payment is due, and Stripe will try to charge the customer for it. If you want to avoid it, you will need to check if the customer has a PaymentMethod on the last day of the trial, and update the Subscription to set the cancel_at_period_end property to true.
Alternatively, you can listen to customer.subscription.updated webhook event - when the status changes from trialing to active and the customer does not have a PaymentMethod, you can cancel the Subscription manually. In this case, however, a draft Invoice will still be created, but automatic collection will be stopped - the invoice will stay as a draft and will never be finalized.
We are using Stripe subscription. In that if a user creates a Product then they can set the price suppose $9.99.
If the other users wants to subscribe the same product they have to pay $9.99. From the paid $9.99, the admin will get 2% and (2.9 + 0.30)% Stripe fee will be deducted and the remaining amount will be sent to the product creator's connect account.
The issue is if the user subscribe a product, a charge is created and the amount deducted from the subscriber. Then the invoice will generate and that time, again the amount will deduct from the subscriber a/c. Double time payment cuts from the subscriber's account.
I'm using destination-charges method to apply the charge and transfer the amount to creator's connect account for any subscription in the invoice.payment_succeeded webhook's method.
How to prevent 2nd time payment deduction?
enter image description here
Creating a subscription will generate an invoice that will charge for the upcoming period(they are charged in advance, so if you had also done a destination charge before creating the subscription, you are charging the customer twice — I assume that's what you mean?
What you probably want to do here is one of :
instead of doing a one-off destination charge or doing a transfer manually from a webhook handler, just set the application fee on the subscription so it's deducted from the invoice instead, by setting the destination of the funds and the application fee you keep :
https://stripe.com/docs/billing/subscriptions/connect#transfer
https://stripe.com/docs/api/subscriptions/create#create_subscription-application_fee_percent
if for some reason that is not an option and you still need to do a separate charge than the first invoice, maybe create the subscription with trial_end set until the next billing date, which will skip the first payment (sine you already processed it)
https://stripe.com/docs/api/subscriptions/create#create_subscription-trial_end
Is it possible to change the items on an unpaid Stripe order or is that locked in once created?
I'm creating an unpaid placeholder order along with a customer source so that when a user is ready to complete checkout they don't have to wait on multiple API calls when they click the final submit button.
If you are talking about the Orders API (which has since been deprecated), then no once you create the order you can't update the items in it. Instead you should just track the items in your customer's cart yourself and create the Stripe payment when you are ready to initiate the charge.
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 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