Optional Billing Layer
Use this flow when you want the package to keep local Paystack customer and subscription records for an Eloquent model while still using the existing action-first SDK under the hood.
Typical flow
- Publish and run the package billing migrations.
- Add
Maxiviper117\Paystack\Concerns\Billableto your model. - Sync the remote Paystack customer from the local model.
- Create or fetch subscriptions through the Billable helper methods.
- Use webhooks to keep your own application billing state correct over time.
Setup
bash
php artisan vendor:publish --tag="paystack-migrations"
php artisan migratephp
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Maxiviper117\Paystack\Concerns\Billable;
class User extends Authenticatable
{
use Billable;
}Customer sync example
php
namespace App\Services\Billing;
use App\Models\User;
class SyncBillableCustomer
{
public function handle(User $user): string
{
$customer = $user->syncAsPaystackCustomer();
return (string) $customer->customer_code;
}
}Subscription example
php
namespace App\Services\Billing;
use App\Models\User;
class StartStoredSubscription
{
public function handle(User $user): string
{
$response = $user->createPaystackSubscription(
planCode: 'PLN_growth',
name: 'primary',
);
return $response->subscription->subscriptionCode;
}
}What gets stored locally
- one
paystack_customersrow per billable model - one named
paystack_subscriptionsrow per billable subscription slot - Paystack identifiers such as
customer_code,subscription_code,email_token,plan_code, and snapshot payload data
Notes
- if your model does not use the default
email,first_name,last_name, orphoneattributes, override the trait helper methods - enabling or disabling a stored subscription requires an
email_token, so create or fetch the subscription before trying to toggle it later - keep using webhooks for long-running subscription lifecycle changes