Billing Layer
The package now includes an optional local billing layer for Laravel apps that want package-owned tables for stored Paystack customers and subscriptions.
This layer is opt-in:
- if you only want the SDK, keep using actions, DTOs, the manager, and the facade
- if you want local persistence similar to a lightweight Cashier-style workflow, publish the package migrations and use the
Billabletrait on your Eloquent model
What it provides
- a
Maxiviper117\Paystack\Concerns\Billabletrait for app models such asUserorAccount - a
paystack_customerstable backed byMaxiviper117\Paystack\Models\PaystackCustomer - a
paystack_subscriptionstable backed byMaxiviper117\Paystack\Models\PaystackSubscription - convenience methods that still delegate to
PaystackManagerand the existing action classes under the hood
Install the optional tables
bash
php artisan vendor:publish --tag="paystack-migrations"
php artisan migrateAdd the trait to your model
php
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Maxiviper117\Paystack\Concerns\Billable;
class User extends Authenticatable
{
use Billable;
}By default, the trait reads the local email, first_name, last_name, and phone attributes when it needs to create or update the remote Paystack customer. If your model uses different field names, override the protected helper methods exposed by the trait.
Common methods
createAsPaystackCustomer(): creates the remote Paystack customer and persists a localpaystack_customersrowupdateAsPaystackCustomer(): updates the remote customer using the stored customer codesyncAsPaystackCustomer(): creates or updates the customer depending on whether a local record already existscreatePaystackSubscription($planCode, $name = 'default'): creates the remote subscription and persists a localpaystack_subscriptionsrowfetchPaystackSubscription($idOrCode, $name = 'default'): fetches a remote subscription and refreshes the local stored recordenablePaystackSubscription($name = 'default'): enables a stored subscription using its local code and email tokendisablePaystackSubscription($name = 'default'): disables a stored subscription using its local code and email token
Example
php
use App\Models\User;
$user = User::query()->findOrFail($id);
$customer = $user->syncAsPaystackCustomer();
$subscription = $user->createPaystackSubscription(
planCode: 'PLN_growth',
name: 'default',
);Important boundaries
- this is a convenience layer, not a replacement for the action-first SDK
- webhook handling still matters for authoritative recurring billing lifecycle updates
- local tables store identifiers and snapshots; your app still owns entitlement rules, access control, and domain-specific billing state