vvvinceocam/svix-php

Unofficial PHP SDK for Svix

dev-master 2024-02-12 09:58 UTC

This package is not auto-updated.

Last update: 2024-04-23 00:44:36 UTC


README

Unofficial PHP SDK for Svix.

Basic usage

<?php

use Svix\Svix;
use Svix\Internal\Model\ApplicationIn;
use Svix\Internal\Model\EndpointIn;
use Svix\Internal\Model\MessageIn;

$client = new Svix('auth token');

// Create an application for a customer
$app = new ApplicationIn();
$app->setName('Super Customer');
$app->setUid('id-from-our-application');
$app = $client->applications->create($app);

// Bind an endpoint
$endpoint = new EndpointIn();
$endpoint->setUrl('https://example.com/customer/endpoint');
$endpoint = $client->endpoints->create($app->getId(), $endpoint);

// Get the secret that customer must use to validate webhook calls
$secret = $client->endpoints->getSecret($app->getId(), $endpoint->getId());

// Send a message to our freshly enrolled customer
$message = new MessageIn();
$message->setEventType('billing.started');
$message->setPayload([
    'some' => 'data',
    'with' => [
        'arbitrary' => 'depth',
    ],
]);
$client->messages->create($app->getId(), $message);