Using Laravel Cashier with Multiple Subscriptions

Viewed 458

My employer has asked that a User has multiple Subscriptions, and each Subscription relates to a Server Model, which contains a Unique Server ID, and other generated information.

So a User might have 2 servers:

  1. Server 1 - Title, Username, etc -> Linked to Subscription
  2. Server 2 - Title, Username, etc -> Linked to Subscription

So in total, that User would have two subscriptions, linked to two servers.

In this particular case, the User would be paying for both Subscriptions for Each Server.

As it's 1 Subscription to 1 Server, and a User can have many Servers.

Any recommendations on how to organize this with Cashier/Stripe?

Or would it be better to attach Server ID to Stripe Meta?

'metadata' => [
    'server_id' => 'Some server id'
]

Or do I apply the billable trait to the Server model? In which case will I still be able to create one billing portal for a user to manage all of their subscriptions?

In addition, how would the creation of Servers to Subscriptions work?

auth()->user()->server()->create(title, username, etc)->->newSubscription()->checkout?
1 Answers

Extra fields (server_id, your system generated information, etc.) can be included in the Stripe Subscription metadata field {0}. In your example, it can be visualised as, the Customer subscribed to multiple Subscriptions which contains information about the server_id and others in the respective metadata.

There is no Server object in Stripe API, if you are referring to the server code and how it relates to Subscription and Checkout, here is an example overview: Subscription Checkout Workflow

You can definitely leverage the Customer Portal {1} to allow customers to view and manage their subscriptions, payment methods, etc. via settings {2}.

{0} https://stripe.com/docs/api/subscriptions/create#create_subscription-metadata

{1} https://stripe.com/docs/billing/subscriptions/customer-portal

{2} https://dashboard.stripe.com/test/settings/billing/portal

Related