forked from LiveCarta/PayPal-PHP-SDK
Auto-generated code for Webhooks API
This commit is contained in:
321
lib/PayPal/Api/Webhook.php
Normal file
321
lib/PayPal/Api/Webhook.php
Normal file
@@ -0,0 +1,321 @@
|
||||
<?php
|
||||
|
||||
namespace PayPal\Api;
|
||||
|
||||
use PayPal\Common\ResourceModel;
|
||||
use PayPal\Validation\ArgumentValidator;
|
||||
use PayPal\Api\WebhookList;
|
||||
use PayPal\Rest\ApiContext;
|
||||
use PayPal\Transport\PPRestCall;
|
||||
use PayPal\Validation\UrlValidator;
|
||||
|
||||
/**
|
||||
* Class Webhook
|
||||
*
|
||||
* Represents Webhook resource.
|
||||
*
|
||||
* @package PayPal\Api
|
||||
*
|
||||
* @property string id
|
||||
* @property string url
|
||||
* @property \PayPal\Api\WebhookEventType[] event_types
|
||||
* @property \PayPal\Api\Links[] links
|
||||
*/
|
||||
class Webhook extends ResourceModel
|
||||
{
|
||||
/**
|
||||
* Identifier of the webhook resource.
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifier of the webhook resource.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Webhook notification endpoint url.
|
||||
*
|
||||
* @param string $url
|
||||
* @throws \InvalidArgumentException
|
||||
* @return $this
|
||||
*/
|
||||
public function setUrl($url)
|
||||
{
|
||||
UrlValidator::validate($url, "Url");
|
||||
$this->url = $url;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Webhook notification endpoint url.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* List of Webhooks event-types.
|
||||
*
|
||||
* @param \PayPal\Api\WebhookEventType[] $event_types
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEventTypes($event_types)
|
||||
{
|
||||
$this->event_types = $event_types;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* List of Webhooks event-types.
|
||||
*
|
||||
* @return \PayPal\Api\WebhookEventType[]
|
||||
*/
|
||||
public function getEventTypes()
|
||||
{
|
||||
return $this->event_types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append EventTypes to the list.
|
||||
*
|
||||
* @param \PayPal\Api\WebhookEventType $webhookEventType
|
||||
* @return $this
|
||||
*/
|
||||
public function addEventType($webhookEventType)
|
||||
{
|
||||
if (!$this->getEventTypes()) {
|
||||
return $this->setEventTypes(array($webhookEventType));
|
||||
} else {
|
||||
return $this->setEventTypes(
|
||||
array_merge($this->getEventTypes(), array($webhookEventType))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove EventTypes from the list.
|
||||
*
|
||||
* @param \PayPal\Api\WebhookEventType $webhookEventType
|
||||
* @return $this
|
||||
*/
|
||||
public function removeEventType($webhookEventType)
|
||||
{
|
||||
return $this->setEventTypes(
|
||||
array_diff($this->getEventTypes(), array($webhookEventType))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* List of Webhooks event-types.
|
||||
*
|
||||
* @deprecated Instead use setEventTypes
|
||||
*
|
||||
* @param \PayPal\Api\WebhookEventType $event_types
|
||||
* @return $this
|
||||
*/
|
||||
public function setEvent_types($event_types)
|
||||
{
|
||||
$this->event_types = $event_types;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* List of Webhooks event-types.
|
||||
* @deprecated Instead use getEventTypes
|
||||
*
|
||||
* @return \PayPal\Api\WebhookEventType
|
||||
*/
|
||||
public function getEvent_types()
|
||||
{
|
||||
return $this->event_types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Links
|
||||
*
|
||||
* @param \PayPal\Api\Links[] $links
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLinks($links)
|
||||
{
|
||||
$this->links = $links;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets Links
|
||||
*
|
||||
* @return \PayPal\Api\Links[]
|
||||
*/
|
||||
public function getLinks()
|
||||
{
|
||||
return $this->links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append Links to the list.
|
||||
*
|
||||
* @param \PayPal\Api\Links $links
|
||||
* @return $this
|
||||
*/
|
||||
public function addLink($links)
|
||||
{
|
||||
if (!$this->getLinks()) {
|
||||
return $this->setLinks(array($links));
|
||||
} else {
|
||||
return $this->setLinks(
|
||||
array_merge($this->getLinks(), array($links))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Links from the list.
|
||||
*
|
||||
* @param \PayPal\Api\Links $links
|
||||
* @return $this
|
||||
*/
|
||||
public function removeLink($links)
|
||||
{
|
||||
return $this->setLinks(
|
||||
array_diff($this->getLinks(), array($links))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the Webhook for the application associated with the access token.
|
||||
*
|
||||
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
|
||||
* @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls
|
||||
* @return Webhook
|
||||
*/
|
||||
public function create($apiContext = null, $restCall = null)
|
||||
{
|
||||
$payLoad = $this->toJSON();
|
||||
$json = self::executeCall(
|
||||
"/v1/notifications/webhooks",
|
||||
"POST",
|
||||
$payLoad,
|
||||
null,
|
||||
$apiContext,
|
||||
$restCall
|
||||
);
|
||||
$this->fromJson($json);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the Webhook identified by webhook_id for the application associated with access token.
|
||||
*
|
||||
* @param string $webhookId
|
||||
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
|
||||
* @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls
|
||||
* @return Webhook
|
||||
*/
|
||||
public static function get($webhookId, $apiContext = null, $restCall = null)
|
||||
{
|
||||
ArgumentValidator::validate($webhookId, 'webhookId');
|
||||
$payLoad = "";
|
||||
$json = self::executeCall(
|
||||
"/v1/notifications/webhooks/$webhookId",
|
||||
"GET",
|
||||
$payLoad,
|
||||
null,
|
||||
$apiContext,
|
||||
$restCall
|
||||
);
|
||||
$ret = new Webhook();
|
||||
$ret->fromJson($json);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all Webhooks for the application associated with access token.
|
||||
*
|
||||
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
|
||||
* @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls
|
||||
* @return WebhookList
|
||||
*/
|
||||
public static function getAll($apiContext = null, $restCall = null)
|
||||
{
|
||||
$payLoad = "";
|
||||
$json = self::executeCall(
|
||||
"/v1/notifications/webhooks",
|
||||
"GET",
|
||||
$payLoad,
|
||||
null,
|
||||
$apiContext,
|
||||
$restCall
|
||||
);
|
||||
$ret = new WebhookList();
|
||||
$ret->fromJson($json);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the Webhook identified by webhook_id for the application associated with access token.
|
||||
*
|
||||
* @param PatchRequest $patchRequest
|
||||
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
|
||||
* @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls
|
||||
* @return Webhook
|
||||
*/
|
||||
public function update($patchRequest, $apiContext = null, $restCall = null)
|
||||
{
|
||||
ArgumentValidator::validate($this->getId(), "Id");
|
||||
ArgumentValidator::validate($patchRequest, 'patchRequest');
|
||||
$payLoad = $patchRequest->toJSON();
|
||||
$json = self::executeCall(
|
||||
"/v1/notifications/webhooks/{$this->getId()}",
|
||||
"PATCH",
|
||||
$payLoad,
|
||||
null,
|
||||
$apiContext,
|
||||
$restCall
|
||||
);
|
||||
$this->fromJson($json);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the Webhook identified by webhook_id for the application associated with access token.
|
||||
*
|
||||
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
|
||||
* @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($apiContext = null, $restCall = null)
|
||||
{
|
||||
ArgumentValidator::validate($this->getId(), "Id");
|
||||
$payLoad = "";
|
||||
self::executeCall(
|
||||
"/v1/notifications/webhooks/{$this->getId()}",
|
||||
"DELETE",
|
||||
$payLoad,
|
||||
null,
|
||||
$apiContext,
|
||||
$restCall
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user