Manage Customers
Use this flow when your app needs to create, fetch, validate, or risk-manage Paystack customers ahead of recurring billing or keep remote customer details aligned with your local customer profile.
Typical application flow
- Create a Paystack customer when a billable user first enters your billing system.
- Store the returned Paystack customer code on your local customer record.
- Fetch the remote customer later when you need to refresh local state.
- Validate identification details when your integration requires it.
- Set a risk action only from a trusted server-side workflow.
- Send targeted updates later when trusted profile fields change.
Preferred service-based example
php
namespace App\Services\Billing;
use App\Models\Account;
use Maxiviper117\Paystack\Actions\Customer\CreateCustomerAction;
use Maxiviper117\Paystack\Actions\Customer\FetchCustomerAction;
use Maxiviper117\Paystack\Actions\Customer\SetCustomerRiskAction;
use Maxiviper117\Paystack\Actions\Customer\ValidateCustomerAction;
use Maxiviper117\Paystack\Actions\Customer\UpdateCustomerAction;
use Maxiviper117\Paystack\Data\Input\Customer\CreateCustomerInputData;
use Maxiviper117\Paystack\Data\Input\Customer\FetchCustomerInputData;
use Maxiviper117\Paystack\Data\Input\Customer\SetCustomerRiskActionInputData;
use Maxiviper117\Paystack\Data\Input\Customer\ValidateCustomerInputData;
use Maxiviper117\Paystack\Data\Input\Customer\UpdateCustomerInputData;
class SyncPaystackCustomer
{
public function __construct(
private CreateCustomerAction $createCustomer,
private FetchCustomerAction $fetchCustomer,
private UpdateCustomerAction $updateCustomer,
private ValidateCustomerAction $validateCustomer,
private SetCustomerRiskAction $setCustomerRiskAction,
) {}
public function create(Account $account): string
{
$response = ($this->createCustomer)(
new CreateCustomerInputData(
email: $account->email,
firstName: $account->first_name,
lastName: $account->last_name,
phone: $account->phone,
metadata: [
'account_id' => $account->getKey(),
],
)
);
$account->paystack_customer_code = $response->customer->customerCode;
$account->save();
return (string) $response->customer->customerCode;
}
public function update(Account $account): void
{
if ($account->paystack_customer_code === null) {
return;
}
($this->updateCustomer)(
new UpdateCustomerInputData(
customerCode: $account->paystack_customer_code,
email: $account->email,
firstName: $account->first_name,
lastName: $account->last_name,
phone: $account->phone,
)
);
}
public function fetch(Account $account): void
{
if ($account->paystack_customer_code === null) {
return;
}
($this->fetchCustomer)(new FetchCustomerInputData($account->paystack_customer_code));
}
public function validate(Account $account): void
{
if ($account->paystack_customer_code === null) {
return;
}
($this->validateCustomer)(
new ValidateCustomerInputData(
customerCode: $account->paystack_customer_code,
country: 'NG',
type: 'bank_account',
accountNumber: $account->account_number,
bvn: $account->bvn,
bankCode: $account->bank_code,
)
);
}
public function deny(Account $account): void
{
if ($account->paystack_customer_code === null) {
return;
}
($this->setCustomerRiskAction)(
new SetCustomerRiskActionInputData(
customer: $account->paystack_customer_code,
riskAction: 'deny',
)
);
}
}Facade alternative
php
use Maxiviper117\Paystack\Data\Input\Customer\CreateCustomerInputData;
use Maxiviper117\Paystack\Data\Input\Customer\FetchCustomerInputData;
use Maxiviper117\Paystack\Data\Input\Customer\SetCustomerRiskActionInputData;
use Maxiviper117\Paystack\Data\Input\Customer\ValidateCustomerInputData;
use Maxiviper117\Paystack\Data\Input\Customer\UpdateCustomerInputData;
use Maxiviper117\Paystack\Facades\Paystack;
$created = Paystack::createCustomer(
new CreateCustomerInputData(
email: $account->email,
firstName: $account->first_name,
lastName: $account->last_name,
)
);
$customerCode = $created->customer->customerCode;
$fetched = Paystack::fetchCustomer(
new FetchCustomerInputData(emailOrCode: $customerCode)
);
Paystack::updateCustomer(
new UpdateCustomerInputData(
customerCode: $customerCode,
phone: $account->phone,
)
);
Paystack::validateCustomer(
new ValidateCustomerInputData(
customerCode: $customerCode,
country: 'NG',
type: 'bank_account',
accountNumber: $account->account_number,
bvn: $account->bvn,
bankCode: $account->bank_code,
)
);
Paystack::setCustomerRiskAction(
new SetCustomerRiskActionInputData(
customer: $customerCode,
riskAction: 'allow',
)
);What to store locally
- the Paystack
customerCode - the local model ID tied to that Paystack customer
- any local sync timestamp or audit fields your app needs
Notes
- only send fields your app owns and trusts
- avoid blindly mirroring every local profile change to Paystack
- treat the returned
customerCodeas the durable remote identifier for future billing flows