For those of you not familiar with Stripe, it is a payment processing service that makes it super easy to accept credit cards on your website without worrying about all the ugly PCI compliance bits that cost a lot of time and money. In addition to one time transactions, Stripe offers subscription billing and management in a way that makes a lot of sense. The only that that is missing from the subscription system is the notion of a setup fee. In my mind, it isn’t super obvious how you would create a setup fee with a Stripe subscription and I didn’t find a good explanation from anywhere else, so I thought I’d take a crack at it.
From my perusal of Stripe’s documentation, this is how you would create a setup fee for a subscription:
- Setup Stripe Checkout on your website to accept a user’s credit card details and receive a token
- Post that token to your web app
- Create a customer using the token that you received from Stripe
- Create an Invoice Item for your setup fee and associate it with your customer but do not pass anything as the invoice parameter
- Update the customer’s subscription to whatever subscription plan they signed up for
If you weren’t applying a setup fee to the user’s account, you could create the customer and assign them a subscription at the same time. However, because the initial subscription invoice is charged immediately upon creation, you need to make sure the Invoice Item for the setup fee already exists. That’s why you create the “dangling” Invoice Item – it will automatically get assigned to the next invoice. The next invoice just happens to be the one that starts the subscription for the user.