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;
|
||||
}
|
||||
|
||||
}
|
||||
372
lib/PayPal/Api/WebhookEvent.php
Normal file
372
lib/PayPal/Api/WebhookEvent.php
Normal file
@@ -0,0 +1,372 @@
|
||||
<?php
|
||||
|
||||
namespace PayPal\Api;
|
||||
|
||||
use PayPal\Common\ResourceModel;
|
||||
use PayPal\Validation\ArgumentValidator;
|
||||
use PayPal\Api\WebhookEventList;
|
||||
use PayPal\Rest\ApiContext;
|
||||
use PayPal\Transport\PPRestCall;
|
||||
|
||||
/**
|
||||
* Class WebhookEvent
|
||||
*
|
||||
* Represents a Webhooks event
|
||||
*
|
||||
* @package PayPal\Api
|
||||
*
|
||||
* @property string id
|
||||
* @property string create_time
|
||||
* @property string resource_type
|
||||
* @property string event_type
|
||||
* @property string summary
|
||||
* @property mixed resource
|
||||
* @property \PayPal\Api\Links[] links
|
||||
*/
|
||||
class WebhookEvent extends ResourceModel
|
||||
{
|
||||
/**
|
||||
* Identifier of the Webhooks event resource.
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifier of the Webhooks event resource.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time the resource was created.
|
||||
*
|
||||
* @param string $create_time
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCreateTime($create_time)
|
||||
{
|
||||
$this->create_time = $create_time;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time the resource was created.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCreateTime()
|
||||
{
|
||||
return $this->create_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time the resource was created.
|
||||
*
|
||||
* @deprecated Instead use setCreateTime
|
||||
*
|
||||
* @param string $create_time
|
||||
* @return $this
|
||||
*/
|
||||
public function setCreate_time($create_time)
|
||||
{
|
||||
$this->create_time = $create_time;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time the resource was created.
|
||||
* @deprecated Instead use getCreateTime
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCreate_time()
|
||||
{
|
||||
return $this->create_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the resource contained in resource element.
|
||||
*
|
||||
* @param string $resource_type
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setResourceType($resource_type)
|
||||
{
|
||||
$this->resource_type = $resource_type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the resource contained in resource element.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResourceType()
|
||||
{
|
||||
return $this->resource_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the resource contained in resource element.
|
||||
*
|
||||
* @deprecated Instead use setResourceType
|
||||
*
|
||||
* @param string $resource_type
|
||||
* @return $this
|
||||
*/
|
||||
public function setResource_type($resource_type)
|
||||
{
|
||||
$this->resource_type = $resource_type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the resource contained in resource element.
|
||||
* @deprecated Instead use getResourceType
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResource_type()
|
||||
{
|
||||
return $this->resource_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the event type that occurred on resource, identified by data_resource element, to trigger the Webhooks event.
|
||||
*
|
||||
* @param string $event_type
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEventType($event_type)
|
||||
{
|
||||
$this->event_type = $event_type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the event type that occurred on resource, identified by data_resource element, to trigger the Webhooks event.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEventType()
|
||||
{
|
||||
return $this->event_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the event type that occurred on resource, identified by data_resource element, to trigger the Webhooks event.
|
||||
*
|
||||
* @deprecated Instead use setEventType
|
||||
*
|
||||
* @param string $event_type
|
||||
* @return $this
|
||||
*/
|
||||
public function setEvent_type($event_type)
|
||||
{
|
||||
$this->event_type = $event_type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the event type that occurred on resource, identified by data_resource element, to trigger the Webhooks event.
|
||||
* @deprecated Instead use getEventType
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEvent_type()
|
||||
{
|
||||
return $this->event_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* A summary description of the event. E.g. A successful payment authorization was created for $$
|
||||
*
|
||||
* @param string $summary
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSummary($summary)
|
||||
{
|
||||
$this->summary = $summary;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* A summary description of the event. E.g. A successful payment authorization was created for $$
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSummary()
|
||||
{
|
||||
return $this->summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* This contains the resource that is identified by resource_type element.
|
||||
*
|
||||
* @param mixed $resource
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setResource($resource)
|
||||
{
|
||||
$this->resource = $resource;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This contains the resource that is identified by resource_type element.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResource()
|
||||
{
|
||||
return $this->resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the Webhooks event resource identified by event_id. Can be used to retrieve the payload for an event.
|
||||
*
|
||||
* @param string $eventId
|
||||
* @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 WebhookEvent
|
||||
*/
|
||||
public static function get($eventId, $apiContext = null, $restCall = null)
|
||||
{
|
||||
ArgumentValidator::validate($eventId, 'eventId');
|
||||
$payLoad = "";
|
||||
$json = self::executeCall(
|
||||
"/v1/notifications/webhooks-events/$eventId",
|
||||
"GET",
|
||||
$payLoad,
|
||||
null,
|
||||
$apiContext,
|
||||
$restCall
|
||||
);
|
||||
$ret = new WebhookEvent();
|
||||
$ret->fromJson($json);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resends the Webhooks event resource identified by event_id.
|
||||
*
|
||||
* @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 WebhookEvent
|
||||
*/
|
||||
public function resend($apiContext = null, $restCall = null)
|
||||
{
|
||||
ArgumentValidator::validate($this->getId(), "Id");
|
||||
$payLoad = "";
|
||||
$json = self::executeCall(
|
||||
"/v1/notifications/webhooks-events/{$this->getId()}/resend",
|
||||
"POST",
|
||||
$payLoad,
|
||||
null,
|
||||
$apiContext,
|
||||
$restCall
|
||||
);
|
||||
$this->fromJson($json);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the list of Webhooks events resources for the application associated with token. The developers can use it to see list of past webhooks events.
|
||||
*
|
||||
* @param array $params
|
||||
* @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 WebhookEventList
|
||||
*/
|
||||
public static function all($params, $apiContext = null, $restCall = null)
|
||||
{
|
||||
ArgumentValidator::validate($params, 'params');
|
||||
$payLoad = "";
|
||||
$allowedParams = array(
|
||||
'page_size' => 1,
|
||||
'start_time' => 1,
|
||||
'end_time' => 1,
|
||||
);
|
||||
$json = self::executeCall(
|
||||
"/v1/notifications/webhooks-events" . "?" . http_build_query(array_intersect_key($params, $allowedParams)),
|
||||
"GET",
|
||||
$payLoad,
|
||||
null,
|
||||
$apiContext,
|
||||
$restCall
|
||||
);
|
||||
$ret = new WebhookEventList();
|
||||
$ret->fromJson($json);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
}
|
||||
149
lib/PayPal/Api/WebhookEventList.php
Normal file
149
lib/PayPal/Api/WebhookEventList.php
Normal file
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace PayPal\Api;
|
||||
|
||||
use PayPal\Common\PPModel;
|
||||
|
||||
/**
|
||||
* Class WebhookEventList
|
||||
*
|
||||
* List of Webhooks event resources
|
||||
*
|
||||
* @package PayPal\Api
|
||||
*
|
||||
* @property \PayPal\Api\WebhookEvent[] events
|
||||
* @property int count
|
||||
* @property \PayPal\Api\Links[] links
|
||||
*/
|
||||
class WebhookEventList extends PPModel
|
||||
{
|
||||
/**
|
||||
* A list of Webhooks event resources
|
||||
*
|
||||
* @param \PayPal\Api\WebhookEvent[] $events
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEvents($events)
|
||||
{
|
||||
$this->events = $events;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of Webhooks event resources
|
||||
*
|
||||
* @return \PayPal\Api\WebhookEvent[]
|
||||
*/
|
||||
public function getEvents()
|
||||
{
|
||||
return $this->events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append Events to the list.
|
||||
*
|
||||
* @param \PayPal\Api\WebhookEvent $webhookEvent
|
||||
* @return $this
|
||||
*/
|
||||
public function addEvent($webhookEvent)
|
||||
{
|
||||
if (!$this->getEvents()) {
|
||||
return $this->setEvents(array($webhookEvent));
|
||||
} else {
|
||||
return $this->setEvents(
|
||||
array_merge($this->getEvents(), array($webhookEvent))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Events from the list.
|
||||
*
|
||||
* @param \PayPal\Api\WebhookEvent $webhookEvent
|
||||
* @return $this
|
||||
*/
|
||||
public function removeEvent($webhookEvent)
|
||||
{
|
||||
return $this->setEvents(
|
||||
array_diff($this->getEvents(), array($webhookEvent))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of items returned in each range of results. Note that the last results range could have fewer items than the requested number of items.
|
||||
*
|
||||
* @param int $count
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCount($count)
|
||||
{
|
||||
$this->count = $count;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of items returned in each range of results. Note that the last results range could have fewer items than the requested number of items.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCount()
|
||||
{
|
||||
return $this->count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
117
lib/PayPal/Api/WebhookEventType.php
Normal file
117
lib/PayPal/Api/WebhookEventType.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace PayPal\Api;
|
||||
|
||||
use PayPal\Common\ResourceModel;
|
||||
use PayPal\Validation\ArgumentValidator;
|
||||
use PayPal\Api\WebhookEventList;
|
||||
use PayPal\Rest\ApiContext;
|
||||
use PayPal\Transport\PPRestCall;
|
||||
|
||||
/**
|
||||
* Class WebhookEventType
|
||||
*
|
||||
* Contains the information for a Webhooks event-type
|
||||
*
|
||||
* @package PayPal\Api
|
||||
*
|
||||
* @property string name
|
||||
* @property string description
|
||||
*/
|
||||
class WebhookEventType extends ResourceModel
|
||||
{
|
||||
/**
|
||||
* Unique event-type name.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unique event-type name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Human readable description of the event-type
|
||||
*
|
||||
* @param string $description
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Human readable description of the event-type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the list of events-types subscribed by the given Webhook.
|
||||
*
|
||||
* @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 WebhookEventList
|
||||
*/
|
||||
public static function subscribedEventTypes($webhookId, $apiContext = null, $restCall = null)
|
||||
{
|
||||
ArgumentValidator::validate($webhookId, 'webhookId');
|
||||
$payLoad = "";
|
||||
$json = self::executeCall(
|
||||
"/v1/notifications/webhooks/$webhookId/event-types",
|
||||
"GET",
|
||||
$payLoad,
|
||||
null,
|
||||
$apiContext,
|
||||
$restCall
|
||||
);
|
||||
$ret = new WebhookEventList();
|
||||
$ret->fromJson($json);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the master list of available Webhooks events-types resources for any webhook to subscribe to.
|
||||
*
|
||||
* @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 WebhookEventList
|
||||
*/
|
||||
public static function availableEventTypes($apiContext = null, $restCall = null)
|
||||
{
|
||||
$payLoad = "";
|
||||
$json = self::executeCall(
|
||||
"/v1/notifications/webhooks-event-types",
|
||||
"GET",
|
||||
$payLoad,
|
||||
null,
|
||||
$apiContext,
|
||||
$restCall
|
||||
);
|
||||
$ret = new WebhookEventList();
|
||||
$ret->fromJson($json);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
}
|
||||
96
lib/PayPal/Api/WebhookEventTypeList.php
Normal file
96
lib/PayPal/Api/WebhookEventTypeList.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace PayPal\Api;
|
||||
|
||||
use PayPal\Common\PPModel;
|
||||
|
||||
/**
|
||||
* Class WebhookEventTypeList
|
||||
*
|
||||
* List of Webhooks event-types
|
||||
*
|
||||
* @package PayPal\Api
|
||||
*
|
||||
* @property \PayPal\Api\WebhookEventType[] event_types
|
||||
*/
|
||||
class WebhookEventTypeList extends PPModel
|
||||
{
|
||||
/**
|
||||
* A 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* A 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))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of Webhooks event-types
|
||||
* @deprecated Instead use getEventTypes
|
||||
*
|
||||
* @return \PayPal\Api\WebhookEventType
|
||||
*/
|
||||
public function getEvent_types()
|
||||
{
|
||||
return $this->event_types;
|
||||
}
|
||||
|
||||
}
|
||||
71
lib/PayPal/Api/WebhookList.php
Normal file
71
lib/PayPal/Api/WebhookList.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace PayPal\Api;
|
||||
|
||||
use PayPal\Common\PPModel;
|
||||
|
||||
/**
|
||||
* Class WebhookList
|
||||
*
|
||||
* List of Webhooks
|
||||
*
|
||||
* @package PayPal\Api
|
||||
*
|
||||
* @property \PayPal\Api\Webhook[] webhooks
|
||||
*/
|
||||
class WebhookList extends PPModel
|
||||
{
|
||||
/**
|
||||
* A list of Webhooks
|
||||
*
|
||||
* @param \PayPal\Api\Webhook[] $webhooks
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setWebhooks($webhooks)
|
||||
{
|
||||
$this->webhooks = $webhooks;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of Webhooks
|
||||
*
|
||||
* @return \PayPal\Api\Webhook[]
|
||||
*/
|
||||
public function getWebhooks()
|
||||
{
|
||||
return $this->webhooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append Webhooks to the list.
|
||||
*
|
||||
* @param \PayPal\Api\Webhook $webhook
|
||||
* @return $this
|
||||
*/
|
||||
public function addWebhook($webhook)
|
||||
{
|
||||
if (!$this->getWebhooks()) {
|
||||
return $this->setWebhooks(array($webhook));
|
||||
} else {
|
||||
return $this->setWebhooks(
|
||||
array_merge($this->getWebhooks(), array($webhook))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Webhooks from the list.
|
||||
*
|
||||
* @param \PayPal\Api\Webhook $webhook
|
||||
* @return $this
|
||||
*/
|
||||
public function removeWebhook($webhook)
|
||||
{
|
||||
return $this->setWebhooks(
|
||||
array_diff($this->getWebhooks(), array($webhook))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user