PHP code example of vihaya / events

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

    

vihaya / events example snippets






ihaya\Events\Vihaya;
use Vihaya\Events\Models\RegisterData;
use Vihaya\Events\Exceptions\VihayaException;

$vihaya = new Vihaya(getenv('VIHAYA_API_KEY'));

try {
    // List events on the authenticated account
    foreach ($vihaya->events()->list() as $event) {
        echo "{$event->title} — {$event->date} @ {$event->location}\n";
    }

    // Fetch full details for one event
    $event = $vihaya->events()->get('evt_8x42j9');

    // Register an attendee
    $result = $vihaya->events()->register(
        $event->id,
        new RegisterData(
            name:  'Anjali Mehta',
            email: '[email protected]',
            phone: '+919820012345',
            customFields: [
                'T-Shirt Size' => 'L',
                'College'      => 'Vihaya Institute',
            ],
        ),
    );

    // For paid events, $result['orderId'] is a Razorpay order ID
    if (isset($result['orderId'])) {
        $vihaya->payments()->verify(
            paymentId: 'pay_O8K2...',
            orderId:   $result['orderId'],
            signature: 'signature_from_razorpay',
        );
    }
} catch (VihayaException $e) {
    fprintf(STDERR, "Vihaya error (%s): %s\n", $e->getStatus() ?? 'n/a', $e->getMessage());
}

use Vihaya\Events\Vihaya;

$vihaya = new Vihaya(
    apiKey:  getenv('VIHAYA_API_KEY'),
    baseUrl: 'https://events.vihaya.app',  // override for staging
    headers: [
        'X-Trace-Id'       => 'abc123',
        'X-Request-Source' => 'backend',
    ],
    timeout: 60.0,
);

$event = $vihaya->events()->get('evt_8x42j9');

echo "{$event->title}\n";
echo "Mode: {$event->eventMode}  Timezone: {$event->timezone}\n";
echo "Location: {$event->location}\n";

foreach ($event->speakerList ?? [] as $speaker) {
    echo "- {$speaker->name} ({$speaker->role}) @ {$speaker->company}\n";
}

foreach ($event->agendaList ?? [] as $item) {
    echo "[{$item->time}] {$item->title}\n";
}

foreach ($event->sponsors ?? [] as $sponsor) {
    echo "{$sponsor->name} ({$sponsor->tier})\n";
}

foreach ($event->faqs ?? [] as $faq) {
    echo "Q: {$faq->question}\nA: {$faq->answer}\n\n";
}

foreach ($event->specialPrices ?? [] as $tier) {
    echo "  {$tier->name}: ₹{$tier->amount}\n";
}

foreach ($event->customFields ?? [] as $field) {
    $req = $field->

$events = $vihaya->events()->list();

$mega = array_filter($events, fn($e) => $e->eventType === 'megaEvent');
$free = array_filter($events, fn($e) => $e->isFree);
$online = array_filter($events, fn($e) => $e->eventMode === 'online');

use Vihaya\Events\Models\RegisterData;

$result = $vihaya->events()->register('evt_conf_2026', new RegisterData(
    name:  'Priya Raj',
    email: '[email protected]',
    phone: '+919820012345',
    tier:  'Early Bird',
    promoCode: 'LAUNCH10',
    customFields: [
        'College'       => 'IIT Bombay',
        'T-Shirt Size'  => 'M',
        'Year of Study' => '3rd',
    ],
));

$result = $vihaya->events()->register('evt_hackathon_2026', [
    'name'     => 'Team Lead',
    'email'    => '[email protected]',
    'phone'    => '+919820012345',
    'teamName' => 'Byte Squad',
    'teamMembers' => [
        ['name' => 'Alice', 'email' => '[email protected]', 'phone' => '+91...'],
        ['name' => 'Bob',   'email' => '[email protected]',   'phone' => '+91...'],
        ['name' => 'Carol', 'email' => '[email protected]', 'phone' => '+91...'],
    ],
]);

// config/services.php
return [
    'vihaya' => [
        'key' => env('VIHAYA_API_KEY'),
    ],
];

// app/Providers/AppServiceProvider.php
use Vihaya\Events\Vihaya;

public function register(): void
{
    $this->app->singleton(Vihaya::class, function () {
        return new Vihaya(config('services.vihaya.key'));
    });
}

// app/Http/Controllers/EventController.php
use Vihaya\Events\Vihaya;
use Vihaya\Events\Models\RegisterData;
use Vihaya\Events\Exceptions\VihayaException;

class EventController extends Controller
{
    public function __construct(private Vihaya $vihaya) {}

    public function index()
    {
        return $this->vihaya->events()->list();
    }

    public function show(string $id)
    {
        return $this->vihaya->events()->get($id);
    }

    public function register(Request $request, string $id)
    {
        try {
            return $this->vihaya->events()->register($id, new RegisterData(
                name:  $request->input('name'),
                email: $request->input('email'),
                phone: $request->input('phone'),
                customFields: $request->input('customFields', []),
            ));
        } catch (VihayaException $e) {
            return response()->json(['error' => $e->getMessage()], $e->getStatus() ?? 500);
        }
    }
}

// src/Controller/EventController.php
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
use Vihaya\Events\Vihaya;

#[Route('/events')]
class EventController
{
    public function __construct(private Vihaya $vihaya) {}

    #[Route('', methods: ['GET'])]
    public function list(): JsonResponse
    {
        return new JsonResponse($this->vihaya->events()->list());
    }
}


/*
Plugin Name: Vihaya Events
*/

de('vihaya_events', function () {
    $vihaya = new Vihaya(get_option('vihaya_api_key'));
    $events = $vihaya->events()->list();
    ob_start();
    foreach ($events as $event) {
        echo "<h3>{$event->title}</h3><p>{$event->date} @ {$event->location}</p>";
    }
    return ob_get_clean();
});

$app->get('/events', function ($request, $response) {
    $vihaya = new Vihaya(getenv('VIHAYA_API_KEY'));
    $events = $vihaya->events()->list();
    $response->getBody()->write(json_encode($events));
    return $response->withHeader('Content-Type', 'application/json');
});

$fest = $vihaya->events()->get('evt_mega_fest_2026');

if ($fest->eventType === 'megaEvent') {
    $count = count($fest->subEvents ?? []);
    echo "{$fest->title} — {$count} sub-events\n";

    foreach ($fest->subEvents ?? [] as $sub) {
        $price = $sub->isFree ? 'Free' : "₹{$sub->price}";
        echo "  - {$sub->title} ({$price})\n";

        foreach ($sub->customFields ?? [] as $field) {
            echo "    * {$field->name} [{$field->type}]\n";
        }
    }
}

$result = $vihaya->events()->register('evt_conf_2026', new RegisterData(
    name:  'Attendee',
    email: '[email protected]',
    phone: '+91...',
));

// Frontend: Razorpay Checkout with $result['orderId'] ...

$vihaya->payments()->verify(
    paymentId: $razorpayPaymentId,
    orderId:   $razorpayOrderId,
    signature: $razorpaySignature,
);

use Vihaya\Events\Exceptions\VihayaException;

try {
    $vihaya->events()->get('evt_missing');
} catch (VihayaException $e) {
    $e->getMessage();   // human-readable error from the server
    $e->getStatus();    // HTTP status code, or null for network errors
    $e->getData();      // raw parsed JSON body, if any

    match ($e->getStatus()) {
        404      => error_log('Not found'),
        401, 403 => error_log('Auth error'),
        429      => error_log('Rate limited'),
        default  => error_log('Other'),
    };
}
bash
git clone https://github.com/Vishnu252005/vihaya-sdk-php.git
cd vihaya-sdk-php
composer install
composer test       # PHPUnit (offline, MockHandler)
composer lint       # PHPStan level 6
composer format     # php-cs-fixer