PHP code example of orbitconnect / orbit-server-php

1. Go to this page and download the library: Download orbitconnect/orbit-server-php 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/ */

    

orbitconnect / orbit-server-php example snippets


use OrbitConnect\Server\OrbitServer;

$orbit = new OrbitServer(secretKey: 'sk_live_...');

$orbit = new OrbitServer(
    secretKey:     'sk_live_...',
    signingSecret: 'whsec_...',
);

// Create an app user
$user = $orbit->users->create([
    'external_id'  => 'user_123',
    'display_name' => 'Jane Doe',
    'metadata'     => ['plan' => 'pro'],
]);

// Issue a short-lived token for your frontend (pass to client SDK)
$token = $orbit->users->createToken($user['id'], ttl: 3600);

// Fetch by your own ID
$user = $orbit->users->getByExternalId('user_123');

// Deactivate (soft-delete, preserves history)
$orbit->users->deactivate($user['id']);

// Start a direct conversation
$conv = $orbit->conversations->create(
    ['type' => 'direct', 'participant_id' => $otherUserId],
    $actingUserId
);

//context conversations
$orbit->conversations->create([
    'type' => 'direct',
    'participant_id' => $customerId,
    'context' => [
        'type' => 'booking',
        'referenceId' => 'booking_888',
        'title' => 'Hair Appointment',
        'status' => 'confirmed',
        'actor' => ['id' => $providerId, 'type' => 'provider', 'name' => 'Glow Salon'],
    ],
], $providerId);

// Update context
$orbit->conversations->updateContext($convId, ['status' => 'completed'], $providerId);

// Find by reference
$convs = $orbit->conversations->findByReference('booking_888', $customerId);


// Send a message
$msg = $orbit->messages->send([
    'conversation_id' => $conv['id'],
    'content'         => 'Hey there!',
    'type'            => 'text',
], $actingUserId);

// Reply
$orbit->messages->reply([
    'conversation_id'     => $conv['id'],
    'content'             => 'Hello back!',
    'reply_to_message_id' => $msg['id'],
], $actingUserId);

// Paginate messages
$messages = $orbit->messages->list($conv['id'], [
    'limit'         => 50,
    'afterSequence' => 100,
], $actingUserId);

// Search
$results = $orbit->messages->search($conv['id'], 'hello', $actingUserId);

$call = $orbit->calls->initiate([
    'callee_id' => $calleeId,
    'type'      => 'video',
], $callerId);

$orbit->calls->accept($call['id'], $calleeId);
$orbit->calls->end($call['id'], $callerId);

$meeting = $orbit->meetings->create([
    'title'        => 'Team standup',
    'scheduled_at' => '2026-05-02T09:00:00Z',
], $hostId);

$orbit->meetings->addParticipant($meeting['id'], $guestId, $hostId);
$orbit->meetings->start($meeting['id'], $hostId);

// Generate a join token for a guest
$token = $orbit->meetings->generateToken($meeting['id'], [
    'app_user_id' => $guestId,
    'role'        => 'participant',
], $hostId);

$orbit->meetings->end($meeting['id'], $hostId);

// Get a pre-signed upload URL
$session = $orbit->media->generateUploadUrl('video/mp4', $userId);
// PUT your file to $session['upload_path']

// Get a stream URL once processing is done
$stream = $orbit->media->getStreamUrl($mediaId, $userId);

// Grant another user download access
$orbit->media->grantAccess($mediaId, [
    'app_user_id' => $otherUserId,
    'access_type' => 'download',
], $userId);

$wh = $orbit->webhooks->create('https://yourapp.com/webhooks/orbit');

$orbit->webhooks->subscribe($wh['id'], 'message.sent');
$orbit->webhooks->subscribe($wh['id'], 'call.ended');

// Publish a custom event
$orbit->webhooks->publish('user.upgraded', ['user_id' => $userId, 'plan' => 'pro']);

// Rotate the signing secret
$orbit->webhooks->rotateSecret($wh['id']);

$wallet = $orbit->billing->getWallet();
echo $wallet['balance'];

$orbit->billing->topUp(50.00);

$invoice = $orbit->billing->generateInvoice(
    new DateTime('2026-04-01'),
    new DateTime('2026-04-30'),
);

use OrbitConnect\Server\OrbitServerException;

try {
    $meeting = $orbit->meetings->get('mtg_unknown', $userId);
} catch (OrbitServerException $e) {
    echo $e->status;     // HTTP status code, e.g. 404
    echo $e->errorCode;  // API error code string, e.g. "resource_not_found"
    echo $e->getMessage();
}
bash
composer