PHP code example of nexorams / sdk

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

    

nexorams / sdk example snippets




exora\Sdk\Nexora;

// Initialize the Nexora client
$nexora = new Nexora(
    apiKey: $_ENV['NEXORA_API_KEY']
);

// List available modular features
$modules = $nexora->modules()->list([
    'organizationType' => 'hospital',
]);

// Provision a new tenant hospital
$organization = $nexora->organizations()->create([
    'name' => 'Apex Specialist Hospital',
    'type' => 'HOSPITAL',
    'country' => 'NG',
    'currency' => 'NGN',
    'timezone' => 'Africa/Lagos',
    'owner' => [
        'firstName' => 'Clara',
        'lastName' => 'Oswald',
        'email' => '[email protected]',
        'phone' => '+2348012345678',
    ],
    'modules' => ['telemedicine', 'pharmacy'],
], idempotencyKey: 'hospital-provision-001');

echo "Provisioned: " . $organization['name'] . PHP_EOL;
echo "Portal URL: " . $organization['portalUrl'] . PHP_EOL;

// List organizations authorized under your developer workspace
$organizations = $nexora->organizations()->list([
    'page' => 1,
    'limit' => 20,
    'type' => 'hospital',
    'status' => 'ACTIVE',
]);

// Retrieve organization details by ID
$org = $nexora->organizations()->get('org_12345');

// Update branding colors, address, or contact phone
$updated = $nexora->organizations()->update('org_12345', [
    'name' => 'Apex Medical Centre',
    'primaryColor' => '#0052cc',
    'theme' => 'dark',
]);

// Update active feature modules
$modules = $nexora->organizations()->updateModules('org_12345', [
    'telemedicine',
    'pharmacy',
    'laboratory',
]);

// Inspect subscription & 30-day trial status
$subscription = $nexora->organizations()->getSubscription('org_12345');

// Manage custom white-label hostnames
$domains = $nexora->organizations()->getDomains('org_12345');
$newDomain = $nexora->organizations()->addDomain('org_12345', 'portal.apexmedical.org', isPrimary: true);
$verification = $nexora->organizations()->verifyDomain('org_12345', $newDomain['id']);

// Provision a staff doctor with an invitation token
$user = $nexora->users()->create('org_12345', [
    'firstName' => 'John',
    'lastName' => 'Watson',
    'email' => '[email protected]',
    'role' => 'doctor',
    'phone' => '+2348098765432',
]);

// List active user memberships in an organization
$doctors = $nexora->users()->list('org_12345', [
    'role' => 'doctor',
]);

// List all extensible modules compatible with schools
$modules = $nexora->modules()->list([
    'organizationType' => 'school',
]);

// List core and active module entitlements for your developer workspace
$projectModules = $nexora->modules()->projectModules();

// Retrieve developer account credit summary
$credits = $nexora->modules()->credits();

if ($credits['unlimited'] ?? false) {
    echo "Unlimited module credits available." . PHP_EOL;
} else {
    echo "Credits: {$credits['usedCredits']} used / {$credits['remainingCredits']} remaining." . PHP_EOL;
}

// List active subscription tiers
$plans = $nexora->plans()->list([
    'organizationType' => 'hospital',
    'productContext' => 'ORGANIZATION',
]);

$sub = $nexora->subscriptions()->get('org_12345');

echo "Plan: " . $sub['planName'] . PHP_EOL;
echo "Status: " . $sub['status'] . PHP_EOL;
echo "Trial Ends: " . $sub['trialEndsAt'] . PHP_EOL;

// List connected domains
$domains = $nexora->domains()->list('org_12345');

// Connect a custom vanity domain
$domain = $nexora->domains()->create('org_12345', 'portal.apexmedical.org', isPrimary: true);

// Trigger authoritative DNS verification
$result = $nexora->domains()->verify('org_12345', $domain['id']);

// Register a new webhook listener
$endpoint = $nexora->webhooks()->create([
    'url' => 'https://api.yourdomain.com/webhooks/nexora',
    'events' => ['organization.provisioned', 'user.created'],
    'description' => 'Production billing listener',
]);

// Stash the show-once signing secret safely
$signingSecret = $endpoint['secret']; // whsec_...

// List configured endpoints
$endpoints = $nexora->webhooks()->list();

// Rotate secret
$rotated = $nexora->webhooks()->rotateSecret($endpoint['id']);

// Send a test ping event
$ping = $nexora->webhooks()->test($endpoint['id']);

// Disable endpoint
$nexora->webhooks()->disable($endpoint['id']);

// Delete endpoint
$nexora->webhooks()->delete($endpoint['id']);

use Nexora\Sdk\Nexora;

// Retrieve the raw request body and signature header
$rawPayload = file_get_contents('php://input');
$signatureHeader = $_SERVER['HTTP_X_NEXORA_SIGNATURE'] ?? '';
$secret = $_ENV['NEXORA_WEBHOOK_SECRET']; // whsec_...

// Verify the signature (default tolerance is 300 seconds)
$isValid = Nexora::verifyWebhookSignature(
    payload: $rawPayload,
    header: $signatureHeader,
    secret: $secret,
    toleranceSeconds: 300
);

if (!$isValid) {
    http_response_code(400);
    echo json_encode(['error' => 'Invalid webhook signature or expired timestamp']);
    exit;
}

// Process the authentic webhook payload
$event = json_decode($rawPayload, true);

// List failed deliveries
$failed = $nexora->deliveries()->list([
    'status' => 'FAILED',
    'page' => 1,
    'limit' => 50,
]);

// Inspect delivery error trace
$delivery = $nexora->deliveries()->get('del_12345');

// Manually trigger immediate event redelivery
$retry = $nexora->deliveries()->retry('del_12345');

// Retrieve monthly telemetry
$usage = $nexora->usage()->summary([
    'period' => '2026-09',
]);

// Retrieve authenticated developer project profile
$project = $nexora->usage()->getProject();

$nexora = new Nexora(apiKey: getenv('NEXORA_API_KEY'), organizationId: 'org_...', applicationId: '...');

$schema = $nexora->cloud()->schema();                        // entities and fields you may use
$page = $nexora->resources('members')->list(['limit' => 20]);
foreach ($nexora->resources('members')->listAll() as $member) { /* ... */ }

$created = $nexora->resources('members')->create(['first_name' => 'Ada'], [], 'signup-123');
$nexora->resources('members')->update($created['id'], ['plan' => 'gold']);
$nexora->resources('members')->archive($created['id']);      // soft delete; data is never hard-deleted

$nexora->resources('members')->events()['created'];          // 'cloud.members.created' (webhook event)

use Nexora\Sdk\Exception\AuthenticationException;
use Nexora\Sdk\Exception\PermissionException;
use Nexora\Sdk\Exception\ValidationException;
use Nexora\Sdk\Exception\RateLimitException;
use Nexora\Sdk\Exception\NetworkException;
use Nexora\Sdk\Exception\NexoraException;

try {
    $nexora->organizations()->create([...]);
} catch (AuthenticationException $e) {
    // 401: Invalid or revoked API key
    error_log("Auth error [{$e->getErrorCode()}]: {$e->getMessage()}");
} catch (PermissionException $e) {
    // 403: Missing API scope or role forbidden
    error_log("Permission denied: {$e->getMessage()} (Request ID: {$e->getRequestId()})");
} catch (ValidationException $e) {
    // 400 or 422: Invalid parameters
    error_log("Validation error: {$e->getMessage()}");
} catch (RateLimitException $e) {
    // 429: Too Many Requests (Rate limit or monthly quota)
    $retryAfter = $e->getRetryAfter(); // in seconds
    error_log("Rate limited! Retry after {$retryAfter}s");
} catch (NetworkException $e) {
    // Transport failure, timeout, or DNS failure
    error_log("Network failure: {$e->getMessage()}");
} catch (NexoraException $e) {
    // General API failure (e.g. 500 server error)
    error_log("Nexora API Error [{$e->getStatusCode()}]: {$e->getMessage()}");
}

$organization = $nexora->organizations()->create(
    data: [
        'name' => 'Apex Clinic',
        'type' => 'HOSPITAL',
        'country' => 'NG',
        'owner' => [
            'firstName' => 'Amelia',
            'lastName' => 'Pond',
            'email' => '[email protected]',
        ],
    ],
    idempotencyKey: 'order_checkout_ref_98765'
);

'nexora' => [
    'api_key' => env('NEXORA_API_KEY'),
    'webhook_secret' => env('NEXORA_WEBHOOK_SECRET'),
],

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Nexora\Sdk\Nexora;

class AppServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->app->singleton(Nexora::class, function () {
            return new Nexora(
                apiKey: config('services.nexora.api_key')
            );
        });
    }
}

namespace App\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Nexora\Sdk\Nexora;

class OrganizationController extends Controller
{
    public function store(Request $request, Nexora $nexora): JsonResponse
    {
        $validated = $request->validate([
            'name' => 'ora->organizations()->create($validated);

        return response()->json($org, 201);
    }
}

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Nexora\Sdk\Nexora;

class NexoraWebhookController extends Controller
{
    public function handle(Request $request): Response
    {
        $isValid = Nexora::verifyWebhookSignature(
            payload: $request->getContent(),
            header: $request->header('X-Nexora-Signature', ''),
            secret: config('services.nexora.webhook_secret')
        );

        if (!$isValid) {
            return response('Invalid signature', 400);
        }

        $event = $request->json()->all();
        // Dispatch job or event listener...

        return response('OK', 200);
    }
}