PHP code example of pliic / pliic-php
1. Go to this page and download the library: Download pliic/pliic-php 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/ */
pliic / pliic-php example snippets
use Pliic\PliicClient;
$pliic = new PliicClient('sk_live_...'); // secret key, from your app settings
// Acting on behalf of one of YOUR users: pass a `user` identity and Pliic
// creates or reuses the matching app user (email-first identity rule).
$user = ['id' => 'u_123', 'name' => 'Ana', 'email' => '[email protected] '];
$suggestion = $pliic->suggestions->create([
'user' => $user,
'title' => 'Dark mode',
'description' => 'It would be easier on the eyes.',
]);
$pliic->suggestions->vote($suggestion['data']['id'], ['user' => $user]);
$pliic->suggestions->list(['status' => 'planned', 'search' => 'dark', 'user_id' => 'u_123']);
$pliic->suggestions->get(42, ['user_id' => 'u_123']); // adds user_has_voted
$pliic->suggestions->create(['user' => $user, 'title' => '...']);
$pliic->suggestions->vote(42, ['user' => $user]); // toggles
$pliic->suggestions->comments(42, ['page' => 1]);
$pliic->suggestions->addComment(42, ['user' => $user, 'body' => 'Great idea!']);
$pliic->tickets->list(['user_id' => 'u_123']); // that user's tickets
$pliic->tickets->create(['user' => $user, 'subject' => 'Checkout error', 'body' => '...', 'type' => 'bug']);
$pliic->tickets->get(7, ['user_id' => 'u_123']); // 404s if the ticket isn't u_123's
$pliic->tickets->reply(7, ['user' => $user, 'body' => 'More detail here...']);
$pliic->surveys->list();
$pliic->surveys->results(3);
$pliic->analytics->get();
$pliic->privacy->export($appUserId); // GDPR/LGPD export
$pliic->privacy->erase($appUserId); // GDPR/LGPD erasure
use Pliic\UserToken;
$token = UserToken::mint($secretKey, [
'id' => 'u_123',
'name' => 'Ana',
'email' => '[email protected] ',
], ttlSeconds: 3600);
use Pliic\Webhook;
use Pliic\Exceptions\SignatureVerificationException;
try {
$event = Webhook::constructEvent(
$request->getContent(), // raw body, not the parsed array
$request->header('X-Pliic-Signature'),
$endpointSecret, // whsec_..., from the endpoint settings
);
} catch (SignatureVerificationException $e) {
abort(400);
}
match ($event->type) {
'suggestion.created' => handleNewSuggestion($event->data),
'ticket.created' => handleNewTicket($event->data),
default => null,
};
use Pliic\Exceptions\InsufficientScopeException;
try {
$pliic->tickets->create(['user' => $user, 'subject' => 'Cannot log in']);
} catch (InsufficientScopeException $e) {
$e->ps://docs.pliic.com/integrations/api-keys/
$e->getMessage(); // already a full, actionable sentence
}
use Pliic\PliicClient;
use Pliic\Testing\FakeHttpClient;
$fake = new FakeHttpClient();
$pliic = new PliicClient('sk_test_fake', 'https://pliic.com', $fake);
$pliic->suggestions->list(); // realistic default list, zero configuration
$fake->seedSuggestion(['id' => 42, 'title' => 'Dark mode', 'vote_count' => 12]);
$pliic->suggestions->get(42); // returns the seeded suggestion
$fake->seedError(422, 'Invalid', ['title' => ['Título já existe.']]);
$pliic->suggestions->create(['user' => $user, 'title' => 'Duplicada']); // throws ValidationException
$fake->seedInsufficientScope('tickets:write');
$pliic->tickets->create(['user' => $user, 'subject' => 'Oi']); // throws InsufficientScopeException
$fake->assertRequested('POST', '/suggestions/42/vote');
$fake->assertRequestCount(2);
expect($fake->lastRequestBody())->toBe(['user' => $user, 'title' => 'Dark mode']);
use Pliic\PliicClient;
$pliic = app(PliicClient::class);
use Pliic\Laravel\Pliic;
Pliic::webhooks('/webhooks/pliic'); // POST /webhooks/pliic
use Illuminate\Support\Facades\Event;
use Pliic\Laravel\Events\WebhookReceived;
Event::listen(WebhookReceived::class, function (WebhookReceived $received): void {
match ($received->event->type) {
'suggestion.created' => notifyTeamOfNewSuggestion($received->event->data),
default => null,
};
});
protected $except = [
'webhooks/pliic',
];
use Illuminate\Support\Facades\Event;
use Pliic\Laravel\Events\WebhookReceived;
Event::listen(WebhookReceived::class, function (WebhookReceived $received): void {
if ($received->event->type !== 'suggestion.commented') {
return;
}
$author = $received->event->data['author']; // ['external_id' => ..., 'name' => ...]
$sender = $received->event->data['sender']; // ['type' => 'app_user'|'member', 'external_id' => ..., 'name' => ...]
if ($sender['external_id'] === $author['external_id']) {
return; // the author commented on their own suggestion — nothing to notify
}
notify($author, "{$sender['name']} commented on your suggestion.");
});
bash
composer bash
composer bash
php artisan vendor:publish --tag=pliic-config