Laravel Cashier And Stripe: How To Tie Subscriptions To Resources
I'm trying to setup a subscription based service where a company that has a billing account can create a single subscription for each individual venue registered in their company. The idea is that the company owner which uses the user model, has the billable trait and can create a subscription for each venue. A company can create as many venues as they want, but must pay individually for each venue that they register for their company. The subscription types a venue can have is either monthly, yearly or trial.
I want to attach the subscription to a resource so I know which subscription that venue is for. Company and venue both have separate models and are linked through a has many relationship.
The structure looks like this
Company Owner (user model, has billable trait) | Company (model) | Venue 1 (model) - Monthly subscription | Venue 2 (model) - Yearly subscription | Venue 3 (model) - Yearly subscription | etc ...
I was thinking of adding the column
venue_id to the
subscriptions table that comes with Cashier. I don't know if it's possible to attach multiple venue subscriptions to the same billable user because I don't know if Cashier supports this. If not would it be better to attach the billable trait to the venue model and just bill the venue instead?
Laravel Cashier still doesn't support multiple subscriptions per entity, nor multi-plan subscriptions either. There has been a talk and a few pull requests to do this in the future versions of the Cashier since Stripe allows that.
Try to use Stripe's official PHP SDK for the API calls.
You could try using Catalyst's package for Stripe, with or without direct integration for Laravel, but you need to build DB models in order to have an overview and bind it to the billable entity.
Or you can use their paid package - Stripe - Billing - Laravel
If you want to build DB models on your own, you should create at least tables for Subscriptions, Plans, and Invoices.
In the subscriptions table, you should have a column for billable entity id, in this case, Company, and venue_id that relates to the Venue that belongs to the company.
Other than that, to have a better figure on how to build the rest of the tables, take a look at the Cashier's Stripe related table structure, and take a look for the Subscription Object, Invoice Object, etc. at the Stripe's comprehensive docs for the API:
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms