vihaya / events
The official PHP SDK for the Vihaya Events platform.
Requires
- php: ^8.1
- ext-json: *
- guzzlehttp/guzzle: ^7.5
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.54
- phpstan/phpstan: ^1.11
- phpunit/phpunit: ^10.5
This package is not auto-updated.
Last update: 2026-04-09 09:58:24 UTC
README
The official PHP SDK for the Vihaya Events platform. List events, register attendees, and verify Razorpay payment signatures from any PHP 8.1+ backend.
Part of the Vihaya SDK family — shipped alongside the JavaScript/TypeScript, Flutter, Python, and Go SDKs.
Requirements
- PHP 8.1 or newer
ext-json- Guzzle 7 (pulled in automatically)
Installation
composer require vihaya/events
Quickstart
<?php require __DIR__ . '/vendor/autoload.php'; use Vihaya\Events\Vihaya; use Vihaya\Events\Models\RegisterData; use Vihaya\Events\Exceptions\VihayaException; $vihaya = new Vihaya('vh_live_4xK...'); 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_abc123'); // Register an attendee $result = $vihaya->events()->register( $event->id, new RegisterData( name: 'Ada Lovelace', email: 'ada@example.com', phone: '+911234567890', ), ); // For paid events, $result['orderId'] is a Razorpay order ID. // After the frontend checkout completes, verify the signature server-side: if (isset($result['orderId'])) { $vihaya->payments()->verify( paymentId: 'pay_O8K2...', // from Razorpay frontend orderId: $result['orderId'], signature: 'signature_from_razorpay', ); } } catch (VihayaException $e) { fprintf(STDERR, "Vihaya error (%s): %s\n", $e->getStatus(), $e->getMessage()); }
API
new Vihaya(string $apiKey, ?string $baseUrl = null, array $headers = [], float $timeout = 30.0, ?ClientInterface $httpClient = null)
Construct a client. Get your API key from the developer dashboard.
| Parameter | Purpose |
|---|---|
$apiKey |
Required. Sent as the x-api-key header on every request. |
$baseUrl |
Override for staging. Defaults to https://events.vihaya.app. |
$headers |
Extra headers to attach to every request. |
$timeout |
Per-request timeout in seconds. |
$httpClient |
Inject a custom Guzzle client — useful for tests / custom middleware. |
$vihaya->events()->list(): list<Event>
Returns every event on the authenticated organiser account.
$vihaya->events()->get(string $eventId): Event
Fetches full metadata for one event — agenda, speakers, sponsors, FAQs, pricing tiers, custom fields, venue info, and sub-events for mega events.
$vihaya->events()->register(string $eventId, RegisterData|array $data): array
Registers an attendee. Pass a RegisterData object for type safety, or a plain
array if you prefer — keys must be camelCase (paymentId, teamName, etc.).
For paid events the response contains an orderId you hand off to the
Razorpay frontend checkout. For free events the registration is confirmed
immediately.
$vihaya->payments()->verify(string $paymentId, string $orderId, string $signature, ?float $amount = null): array
Server-side verification of a Razorpay payment signature. Always call this from your backend — never trust a signature that's only been checked in the browser.
Models
All models are readonly classes with a fromArray() factory. Unknown fields
are preserved on $model->raw, so the SDK is forward-compatible with new API
fields without waiting for a release.
EventSpeakerSponsorAgendaItemContactFAQItemCustomFieldSpecialPricePromoCodeRegisterData— mutable DTO for the register payload
Error handling
Every API and transport failure surfaces as
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 }
Development
composer install composer test # phpunit composer lint # phpstan (level 6) composer format # php-cs-fixer
The test suite uses Guzzle's MockHandler and makes no real network calls,
so composer test runs offline.