Billable contract and a ManagesBilling trait that you drop onto your model — no base class required. The most common case is User, but Team, Organization, or any other model works equally well.
Implementing the Billable contract
Add theBillable interface and the ManagesBilling trait to your model, then implement the two required methods that Subscribd uses to create gateway customers and generate invoices.
billingEmail() and billingName() are the only methods you must define. Everything else — subscription relationships, gateway customer lookups, invoice queries — is provided by ManagesBilling.
Supporting multiple billable types
You can register as many billable types as your application needs. Each key becomes a slug used internally to resolve the correct model class from a subscription record.What ManagesBilling provides
TheManagesBilling trait wires up the following on your model automatically:
subscriptions()— EloquentHasManyrelationship toSubscriptionrecordsinvoices— Eloquent relationship to allInvoicerecords for this billablesubscribed($name)— checks for an active or trialing subscriptiononTrial($name)— checks whether the named subscription is in a trial periodonGracePeriod($name)— checks whether a canceled subscription is still within its grace period
The trait does not add any database columns to your model’s own table. All subscription data is stored in Subscribd’s own tables using a polymorphic relationship keyed by the billable type and ID.