PHP code example of robase / sdk
1. Go to this page and download the library: Download robase/sdk library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
robase / sdk example snippets
se = new Robase\Client(getenv('ROBASE_API_KEY'));
$sent = $robase->otp->send('+2348012345678');
echo $sent->id, ' expires ', $sent->expiresAt?->format('c'), PHP_EOL;
// ...after the user types in the code they received:
$result = $robase->otp->verify($sent->id, '123456');
if ($result->valid) {
echo "verified\n";
}
$robase = new Robase\Client(
apiKey: 'robe_...',
baseUrl: 'http://localhost:8080', // default: https://api.robase.dev
timeout: 10.0, // seconds, default: 30.0
maxRetries: 3, // default: 2
transport: $myTransport, // default: CurlTransport
extraHeaders: ['X-App' => 'checkout'],
);
$robase->sms->send('+2348012345678', 'Shipped!', options: [
'idempotency_key' => "order-{$orderId}",
'max_retries' => 0,
'headers' => ['X-Trace-Id' => $traceId],
]);
$sent = $robase->otp->send(
phoneNumber: '+2348012345678', // o 6
ttlSeconds: 600, // optional, ≤3600, defaults to 600
metadata: ['user_id' => 'u_123'],
);
use Robase\Exception\ConflictException;
try {
$result = $robase->otp->verify($otpId, $code);
if ($result->valid) {
// success
} else {
printf("wrong code, %d attempts left\n", $result->attemptsRemaining);
}
} catch (ConflictException $e) {
// $e->getType() is otp_expired | otp_already_verified | max_attempts_exceeded
}
$msg = $robase->sms->send(
phoneNumber: '+2348012345678',
message: 'Your order #12345 has shipped.', // ≤918 characters
metadata: ['order_id' => '12345'],
);
use Robase\Exception\InsufficientCreditsException;
use Robase\Exception\RobaseException;
try {
$robase->otp->send($phoneNumber);
} catch (InsufficientCreditsException $e) {
// top up and retry
} catch (RobaseException $e) {
error_log("{$e->getType()}: {$e->getMessage()} (HTTP {$e->getStatus()})");
}
use Robase\Exception\SignatureVerificationException;
use Robase\Webhook;
use Robase\WebhookEvent;
// The raw bytes matter — a re-encoded body won't match the signature.
$payload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_ROBASE_SIGNATURE'] ?? null;
try {
$event = Webhook::parse($payload, $signature, $secret);
} catch (SignatureVerificationException) {
http_response_code(401);
exit;
}
match ($event->event) {
WebhookEvent::OtpVerified => handleVerified($event->string('id')),
WebhookEvent::SmsDelivered => handleDelivered($event->string('id')),
WebhookEvent::CreditLow => alertLowBalance($event->int('balance')),
default => null,
};
http_response_code(200);