PHP SDK
Use the official PHP SDK for server-side PHP applications that need customers, virtual accounts, virtual cards, or bill payments. Keep credentials in the hosting environment or a secret manager.
What the SDK supports
| Product | SDK support | Start here |
|---|---|---|
| Customers and virtual accounts | Customer creation, static/dynamic accounts, payment confirmation, sandbox simulation | This guide |
| Virtual cards | Create, fund, withdraw, controls, and transactions | This guide |
| Bill payments | Airtime, data, electricity, cable, and more | This guide |
| Transfers and payouts | Not yet exposed by this SDK | REST payout guide |
Install and configure
composer require payscribe/php-sdk
<?php
require __DIR__ . '/vendor/autoload.php';
use Payscribe\Payscribe;
$apiKey = getenv('PAYSCRIBE_API_KEY')
?: throw new RuntimeException('PAYSCRIBE_API_KEY is required');
$payscribe = Payscribe::sandbox($apiKey);
Use Payscribe::production($apiKey) only after completing the go-live checklist.
First integration: create a customer and static account
Create and persist the customer first. Then create the reusable virtual account and retain the returned account number and Payscribe identifiers with your customer record.
$customer = $payscribe->customers->create(
firstName: 'Ada',
lastName: 'Lovelace',
email: 'ada@example.com',
phone: '+2348099228833',
);
$customerId = $customer['customer_id'] ?? $customer['id'] ?? null;
if (!$customerId) {
throw new RuntimeException('Payscribe did not return a customer ID.');
}
$account = $payscribe->virtualAccounts->createStatic(
customerId: $customerId,
banks: ['9PSB'],
currency: 'NGN',
);
echo $account->accountNumber;
Account creation is not payment confirmation. Use the verified webhook and transaction data before updating an invoice or customer balance. Follow the Virtual accounts guide.
Cards
$card = $payscribe->virtualCards->create(
customerId: $customerId,
currency: 'USD',
brand: 'visa',
amount: 50,
reference: 'card_issue_order_10021',
);
$result = $payscribe->virtualCards->topUp(
cardId: $card->id,
amount: 10,
reference: 'card_topup_order_10021',
);
Use masked card details for display and do not log sensitive card data. The Card issuance guide explains the complete lifecycle.
Bill payments
Discover a product or validate the recipient before payment. Keep the same reference while you reconcile a timeout or uncertain response.
$plans = $payscribe->bills->data->lookup(network: 'mtn', category: 'sme');
$payment = $payscribe->bills->data->vend(
plan: 'PSPLAN_177', // Use a plan returned by lookup().
recipient: '08030000000',
network: 'mtn',
reference: 'data_order_10021',
);
Follow the Bill payments guide before displaying a token, PIN, or success state.
Handle errors and webhooks
Catch typed SDK exceptions and log only safe correlation values.
use Payscribe\Exception\PayscribeException;
try {
$payscribe->virtualAccounts->get('5031240100');
} catch (PayscribeException $exception) {
error_log(sprintf('Payscribe request failed: %s', $exception->getMessage()));
throw $exception;
}
For webhook verification, use the canonical Webhooks & Events reference. It contains the current signature format, raw-body requirement, timestamp validation, event IDs, and replay protection.
Continue
Was this page helpful?