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,
);
// 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());
}
}