-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from partnero/webhook_updates
Webhook Updates
- Loading branch information
Showing
4 changed files
with
346 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,12 @@ Partnero PHP SDK | |
* [Transactions API](#transactions) | ||
* [Create transaction](#create-transaction) | ||
* [Delete transaction](#delete-transaction) | ||
* [Webhooks API](#webhooks) | ||
* [Get a list of webhooks](#get-a-list-of-webhooks) | ||
* [Get webhook](#get-webhook) | ||
* [Create webhook](#create-webhook) | ||
* [Update webhook](#update-webhook) | ||
* [Delete webhook](#delete-webhook) | ||
* [Support and Feedback](#support-and-feedback) | ||
|
||
# Installation | ||
|
@@ -229,11 +235,80 @@ $partnero = new Partnero('api_key'); | |
$partnero->transactions()->delete('transaction_123'); | ||
``` | ||
|
||
<a name="webhooks"></a> | ||
## Webhooks | ||
|
||
<a name="get-a-list-of-webhooks"></a> | ||
### Get a list of webhooks | ||
|
||
```php | ||
use Partnero\Partnero; | ||
|
||
$partnero = new Partnero('api_key'); | ||
|
||
$partnero->webhooks()->list(50, 1); | ||
``` | ||
|
||
<a name="get-webhook"></a> | ||
### Get webhook | ||
|
||
```php | ||
use Partnero\Partnero; | ||
|
||
$partnero = new Partnero('api_key'); | ||
|
||
$partnero->webhooks()->find('webhook-key'); | ||
``` | ||
|
||
<a name="create-webhook"></a> | ||
### Create webhook | ||
|
||
```php | ||
use Partnero\Partnero; | ||
use Partnero\Models\Webhook; | ||
|
||
$partnero = new Partnero('api_key'); | ||
|
||
$webhook = (new Webhook()) | ||
->setName('Demo') | ||
->setUrl('https://webhook.site/e68d154a-ad82') | ||
->setEvents([ | ||
'partner.created' | ||
]); | ||
|
||
$partnero->webhooks()->create($webhook); | ||
``` | ||
|
||
<a name="update-webhook"></a> | ||
### Update webhook | ||
|
||
```php | ||
use Partnero\Partnero; | ||
use Partnero\Models\Webhook; | ||
|
||
$partnero = new Partnero('api_key'); | ||
|
||
$webhook = (new Webhook())->setName('Demo 2'); | ||
|
||
$partnero->webhooks()->update('webhook-key', $webhook); | ||
``` | ||
|
||
<a name="delete-webhook"></a> | ||
### Delete webhook | ||
|
||
```php | ||
use Partnero\Partnero; | ||
|
||
$partnero = new Partnero('api_key'); | ||
|
||
$partnero->webhooks()->delete('webhook-key'); | ||
``` | ||
|
||
<a name="support-and-feedback"></a> | ||
# Support and Feedback | ||
|
||
In case you find any bugs, submit an issue directly here in GitHub. | ||
|
||
If you have any troubles using our API or SDK feel free to contact our support by email [[email protected]](mailto:[email protected]) | ||
|
||
The official documentation is at [https://developers.partnero.com](https://developers.partnero.com) | ||
The official documentation is at [https://developers.partnero.com](https://developers.partnero.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Partnero\Endpoints; | ||
|
||
use JsonException; | ||
use Partnero\Models\Webhook; | ||
use Partnero\Exceptions\RequestException; | ||
use Psr\Http\Client\ClientExceptionInterface; | ||
|
||
class Webhooks extends AbstractEndpoint | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
protected function getEndpointUri(): string | ||
{ | ||
return 'webhooks'; | ||
} | ||
|
||
/** | ||
* @param int|null $limit | ||
* @param int|null $page | ||
* @return array | ||
* @throws JsonException | ||
* @throws RequestException | ||
* @throws ClientExceptionInterface | ||
*/ | ||
public function list(int|null $limit = null, int|null $page = null): array | ||
{ | ||
$params = []; | ||
|
||
if (!is_null($limit)) { | ||
$params['limit'] = $limit; | ||
} | ||
|
||
if (!is_null($page)) { | ||
$params['page'] = $page; | ||
} | ||
|
||
return $this->call('get', $params); | ||
} | ||
|
||
/** | ||
* @param string|Webhook $key | ||
* @return array | ||
* @throws ClientExceptionInterface | ||
* @throws JsonException | ||
* @throws RequestException | ||
*/ | ||
public function find(string|Webhook $key): array | ||
{ | ||
return $this->call( | ||
'get', | ||
[], | ||
$this->getEndpointUri() . '/' . $key | ||
); | ||
} | ||
|
||
/** | ||
* @param array|Webhook $webhook | ||
* @return array | ||
* @throws ClientExceptionInterface | ||
* @throws JsonException | ||
* @throws RequestException | ||
*/ | ||
public function create(array|Webhook $webhook): array | ||
{ | ||
return $this->call('post', $this->modelData($webhook)); | ||
} | ||
|
||
/** | ||
* @param string|Webhook $key | ||
* @param array|Webhook $webhook | ||
* @return array | ||
* @throws ClientExceptionInterface | ||
* @throws JsonException | ||
* @throws RequestException | ||
*/ | ||
public function update(string|Webhook $key, array|Webhook $webhook): array | ||
{ | ||
return $this->call( | ||
'put', | ||
$this->modelData($webhook), | ||
$this->getEndpointUri() . '/' . $key | ||
); | ||
} | ||
|
||
/** | ||
* @param string|Webhook $key | ||
* @return array | ||
* @throws ClientExceptionInterface | ||
* @throws JsonException | ||
* @throws RequestException | ||
*/ | ||
public function delete(string|Webhook $key): array | ||
{ | ||
return $this->call( | ||
'delete', | ||
[], | ||
$this->getEndpointUri() . '/' . $key | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Partnero\Models; | ||
|
||
class Webhook extends AbstractModel | ||
{ | ||
/** | ||
* @var string|null | ||
*/ | ||
protected ?string $key = null; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
protected ?string $name = null; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
protected ?string $url = null; | ||
|
||
/** | ||
* @var bool|null | ||
*/ | ||
protected ?bool $isActive = null; | ||
|
||
/** | ||
* @var array|null | ||
*/ | ||
protected ?array $events = null; | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getKey(): ?string | ||
{ | ||
return $this->key; | ||
} | ||
|
||
/** | ||
* @param string|null $key | ||
* @return $this | ||
*/ | ||
public function setKey(?string $key): Webhook | ||
{ | ||
$this->key = $key; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getName(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @param string|null $name | ||
* @return $this | ||
*/ | ||
public function setName(?string $name): Webhook | ||
{ | ||
$this->name = $name; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getUrl(): ?string | ||
{ | ||
return $this->url; | ||
} | ||
|
||
/** | ||
* @param string|null $url | ||
* @return $this | ||
*/ | ||
public function setUrl(?string $url): Webhook | ||
{ | ||
$this->url = $url; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return bool|null | ||
*/ | ||
public function getIsActive(): ?bool | ||
{ | ||
return $this->isActive; | ||
} | ||
|
||
/** | ||
* @param bool|null $isActive | ||
* @return $this | ||
*/ | ||
public function setIsActive(?bool $isActive): Webhook | ||
{ | ||
$this->isActive = $isActive; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string[]|null | ||
*/ | ||
public function getEvents(): ?array | ||
{ | ||
return $this->events; | ||
} | ||
|
||
/** | ||
* @param string[]|null $events | ||
* @return $this | ||
* | ||
* @link https://developers.partnero.com/reference/webhooks.html#available-events | ||
*/ | ||
public function setEvents(?array $events): Webhook | ||
{ | ||
$this->events = $events; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function __toArray(): array | ||
{ | ||
return [ | ||
'key' => $this->getKey(), | ||
'name' => $this->getName(), | ||
'url' => $this->getUrl(), | ||
'events' => $this->getEvents(), | ||
'is_active' => $this->getIsActive(), | ||
]; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString(): string | ||
{ | ||
return (string)$this->getKey(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters