elliptic / elliptic-sdk
Elliptic SDK for PHP - A Guzzle wrapper for connecting to Elliptic APIs
v0.9.0
2025-01-09 14:03 UTC
Requires
- guzzlehttp/guzzle: ^7.0
- ramsey/uuid: ^4.7
Requires (Dev)
- phpunit/phpunit: ^10
README
Installation
Composer
composer require elliptic/elliptic-sdk
Usage
The SDK provides an instance of the popular Guzzle HTTP client, adding the necessary steps to authenticate each request using your Elliptic API key and secret.
use Elliptic\AML;
$aml = new AML([
'key' => 'YOUR_ELLIPTIC_API_KEY',
'secret' => 'YOUR_ELLIPTIC_API_SECRET',
]);
// $aml->client is an instance of GuzzleHttp\Client
$response = $aml->client->get('/v2/analyses');
Webhook Signature Verification
Elliptic signs the webhook events it sends to your endpoint, allowing
you to validate that they were not sent by a third-party. You can use
the WebhookRequestVerifier
class to verify the signature of a webhook
request:
<?php
use Elliptic\WebhookRequestVerifier;
require 'vendor/autoload.php';
$options = [
'trustedPublicKey' => "<This can be found from Elliptic's docs>",
'expectedEndpointId' => "<This will be provided when your webhook integration is set up by Elliptic>",
];
$verifier = new WebhookRequestVerifier($options);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
$webhookIdHeader = $_SERVER['HTTP_WEBHOOK_ID'];
$webhookTimestampHeader = $_SERVER['HTTP_WEBHOOK_TIMESTAMP'];
$webhookSignatureHeader = $_SERVER['HTTP_WEBHOOK_SIGNATURE'];
$reqBody = file_get_contents('php://input');
$params = [
'webhookIdHeader' => $webhookIdHeader,
'webhookTimestampHeader' => $webhookTimestampHeader,
'webhookSignatureHeader' => $webhookSignatureHeader,
'reqBody' => $reqBody,
];
$messageId = $verifier->verify($params);
echo("Verification successful, message ID: $messageId");
http_response_code(200);
} catch (Exception $e) {
echo "Verification failed: " . $e->getMessage();
http_response_code(401);
}
} else {
http_response_code(405);
echo "Only POST requests are allowed.";
}
API Documentation
Documentation for Elliptic APIs can be found at the Elliptic Developer Center
License
This SDK is distributed under the Apache License, Version 2.0, see LICENSE and NOTICE for more information.