https://github.com/frain-dev/convoy-php
Convoy SDK for PHP
https://github.com/frain-dev/convoy-php
Last synced: 10 months ago
JSON representation
Convoy SDK for PHP
- Host: GitHub
- URL: https://github.com/frain-dev/convoy-php
- Owner: frain-dev
- License: mit
- Created: 2022-03-04T00:38:12.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-03-16T15:40:15.000Z (almost 3 years ago)
- Last Synced: 2025-04-10T05:08:41.639Z (10 months ago)
- Language: PHP
- Size: 44.9 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Convoy SDK for PHP
[](https://packagist.org/packages/frain/convoy)
[](https://packagist.org/packages/frain/convoy)
This is the Convoy PHP SDK. This SDK contains methods for easily interacting with Convoy's API. Below are examples to get you started. For additional examples, please see our official documentation at (https://convoy.readme.io/reference)
## Installation
To install the package, you will need to be using Composer in your project.
The Convoy PHP SDK is not hard coupled to any HTTP Client such as Guzzle or any other library used to make HTTP requests. The HTTP Client implementation is based on [PSR-18](https://www.php-fig.org/psr/psr-18/). This provides you with the convenience of choosing what [PSR-7](https://packagist.org/providers/psr/http-message-implementation) and [HTTP Client](https://packagist.org/providers/psr/http-client-implementation) you want to use.
To get started quickly,
```bash
composer require frain/convoy symfony/http-client nyholm/psr7
```
### Setup Client
Next, import the `convoy` module and setup with your auth credentials.
```php
use Convoy\Convoy;
$convoy = new Convoy(["api_key" => "your_api_key", "project_id" => "your_project_id"]);
```
### Create an Endpoint
An endpoint represents a target URL to receive events.
```php
$endpointData = [
"name" => "Default Endpoint",
"url" => "https://0d87-102-89-2-172.ngrok.io",
"description" => "Default Endpoint",
"secret" => "endpoint-secret",
"events" => ["*"]
];
$response = $convoy->endpoints()->create($endpointData);
```
### Update an Endpoint
```php
$endpointId = "01GTVFSGBAH8NJTMT5Y1ENE218";
$endpointData = [
"name" => "Default Endpoint",
"url" => "https://0d87-102-89-2-172.ngrok.io",
"description" => "Default Endpoint",
"secret" => "endpoint-secret",
"events" => ["*"]
];
$response = $convoy->endpoints()->update($endpointId, $endpointData);
```
### Sending an Event
To send an event, you'll need the `uid` from the endpoint we created earlier.
```php
$eventData = [
"endpoint_id" => $endpointId,
"event_type" => "payment.success",
"data" => [
"event" => "payment.success",
"data" => [
"status" => "Completed",
"description" => "Transaction Successful",
"userID" => "test_user_id808"
]
]
];
$response = $convoy->events()->create($eventData);
```
## Testing
```bash
composer test
```
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Credits
- [Frain](https://github.com/frain-dev)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.