Auto-generated code for Webhooks API

This commit is contained in:
japatel
2014-12-04 20:18:34 -06:00
parent 660070e3df
commit 95c097bc7b
12 changed files with 1909 additions and 0 deletions

321
lib/PayPal/Api/Webhook.php Normal file
View 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;
}
}

View 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;
}
}

View 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))
);
}
}

View 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;
}
}

View 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;
}
}

View 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))
);
}
}

View File

@@ -0,0 +1,82 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Common\PPModel;
use PayPal\Api\WebhookEventList;
/**
* Class WebhookEventList
*
* @package PayPal\Test\Api
*/
class WebhookEventListTest extends \PHPUnit_Framework_TestCase
{
/**
* Gets Json String of Object WebhookEventList
* @return string
*/
public static function getJson()
{
return '{"events":' .WebhookEventTest::getJson() . ',"count":123,"links":' .LinksTest::getJson() . '}';
}
/**
* Gets Object Instance with Json data filled in
* @return WebhookEventList
*/
public static function getObject()
{
return new WebhookEventList(self::getJson());
}
/**
* Tests for Serialization and Deserialization Issues
* @return WebhookEventList
*/
public function testSerializationDeserialization()
{
$obj = new WebhookEventList(self::getJson());
$this->assertNotNull($obj);
$this->assertNotNull($obj->getEvents());
$this->assertNotNull($obj->getCount());
$this->assertNotNull($obj->getLinks());
$this->assertEquals(self::getJson(), $obj->toJson());
return $obj;
}
/**
* @depends testSerializationDeserialization
* @param WebhookEventList $obj
*/
public function testGetters($obj)
{
$this->assertEquals($obj->getEvents(), WebhookEventTest::getObject());
$this->assertEquals($obj->getCount(), 123);
$this->assertEquals($obj->getLinks(), LinksTest::getObject());
}
/**
* @depends testSerializationDeserialization
* @param WebhookEventList $obj
*/
public function testDeprecatedGetters($obj)
{
}
/**
* @depends testSerializationDeserialization
* @param WebhookEventList $obj
*/
public function testDeprecatedSetterNormalGetter($obj)
{
//Test All Deprecated Getters and Normal Getters
$this->testDeprecatedGetters($obj);
$this->testGetters($obj);
}
}

View File

@@ -0,0 +1,190 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Common\ResourceModel;
use PayPal\Validation\ArgumentValidator;
use PayPal\Api\WebhookEventList;
use PayPal\Rest\ApiContext;
use PayPal\Transport\PPRestCall;
use PayPal\Api\WebhookEvent;
/**
* Class WebhookEvent
*
* @package PayPal\Test\Api
*/
class WebhookEventTest extends \PHPUnit_Framework_TestCase
{
/**
* Gets Json String of Object WebhookEvent
* @return string
*/
public static function getJson()
{
return '{"id":"TestSample","create_time":"TestSample","resource_type":"TestSample","event_type":"TestSample","summary":"TestSample","resource":"TestSampleObject","links":' .LinksTest::getJson() . '}';
}
/**
* Gets Object Instance with Json data filled in
* @return WebhookEvent
*/
public static function getObject()
{
return new WebhookEvent(self::getJson());
}
/**
* Tests for Serialization and Deserialization Issues
* @return WebhookEvent
*/
public function testSerializationDeserialization()
{
$obj = new WebhookEvent(self::getJson());
$this->assertNotNull($obj);
$this->assertNotNull($obj->getId());
$this->assertNotNull($obj->getCreateTime());
$this->assertNotNull($obj->getResourceType());
$this->assertNotNull($obj->getEventType());
$this->assertNotNull($obj->getSummary());
$this->assertNotNull($obj->getResource());
$this->assertNotNull($obj->getLinks());
$this->assertEquals(self::getJson(), $obj->toJson());
return $obj;
}
/**
* @depends testSerializationDeserialization
* @param WebhookEvent $obj
*/
public function testGetters($obj)
{
$this->assertEquals($obj->getId(), "TestSample");
$this->assertEquals($obj->getCreateTime(), "TestSample");
$this->assertEquals($obj->getResourceType(), "TestSample");
$this->assertEquals($obj->getEventType(), "TestSample");
$this->assertEquals($obj->getSummary(), "TestSample");
$this->assertEquals($obj->getResource(), "TestSampleObject");
$this->assertEquals($obj->getLinks(), LinksTest::getObject());
}
/**
* @depends testSerializationDeserialization
* @param WebhookEvent $obj
*/
public function testDeprecatedGetters($obj)
{
$this->assertEquals($obj->getCreate_time(), "TestSample");
$this->assertEquals($obj->getResource_type(), "TestSample");
$this->assertEquals($obj->getEvent_type(), "TestSample");
}
/**
* @depends testSerializationDeserialization
* @param WebhookEvent $obj
*/
public function testDeprecatedSetterNormalGetter($obj)
{
// Check for Create_time
$obj->setCreateTime(null);
$this->assertNull($obj->getCreate_time());
$this->assertNull($obj->getCreateTime());
$this->assertSame($obj->getCreateTime(), $obj->getCreate_time());
$obj->setCreate_time("TestSample");
$this->assertEquals($obj->getCreate_time(), "TestSample");
// Check for Resource_type
$obj->setResourceType(null);
$this->assertNull($obj->getResource_type());
$this->assertNull($obj->getResourceType());
$this->assertSame($obj->getResourceType(), $obj->getResource_type());
$obj->setResource_type("TestSample");
$this->assertEquals($obj->getResource_type(), "TestSample");
// Check for Event_type
$obj->setEventType(null);
$this->assertNull($obj->getEvent_type());
$this->assertNull($obj->getEventType());
$this->assertSame($obj->getEventType(), $obj->getEvent_type());
$obj->setEvent_type("TestSample");
$this->assertEquals($obj->getEvent_type(), "TestSample");
//Test All Deprecated Getters and Normal Getters
$this->testDeprecatedGetters($obj);
$this->testGetters($obj);
}
/**
* @dataProvider mockProvider
* @param WebhookEvent $obj
*/
public function testGet($obj, $mockApiContext)
{
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
WebhookEventTest::getJson()
));
$result = $obj->get("eventId", $mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
* @dataProvider mockProvider
* @param WebhookEvent $obj
*/
public function testResend($obj, $mockApiContext)
{
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
self::getJson()
));
$result = $obj->resend($mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
* @dataProvider mockProvider
* @param WebhookEvent $obj
*/
public function testList($obj, $mockApiContext)
{
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
WebhookEventListTest::getJson()
));
$params = array();
$result = $obj->all($params, $mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
public function mockProvider()
{
$obj = self::getObject();
$mockApiContext = $this->getMockBuilder('ApiContext')
->disableOriginalConstructor()
->getMock();
return array(
array($obj, $mockApiContext),
array($obj, null)
);
}
}

View File

@@ -0,0 +1,87 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Common\PPModel;
use PayPal\Api\WebhookEventTypeList;
/**
* Class WebhookEventTypeList
*
* @package PayPal\Test\Api
*/
class WebhookEventTypeListTest extends \PHPUnit_Framework_TestCase
{
/**
* Gets Json String of Object WebhookEventTypeList
* @return string
*/
public static function getJson()
{
return '{"event_types":' .WebhookEventTypeTest::getJson() . '}';
}
/**
* Gets Object Instance with Json data filled in
* @return WebhookEventTypeList
*/
public static function getObject()
{
return new WebhookEventTypeList(self::getJson());
}
/**
* Tests for Serialization and Deserialization Issues
* @return WebhookEventTypeList
*/
public function testSerializationDeserialization()
{
$obj = new WebhookEventTypeList(self::getJson());
$this->assertNotNull($obj);
$this->assertNotNull($obj->getEventTypes());
$this->assertEquals(self::getJson(), $obj->toJson());
return $obj;
}
/**
* @depends testSerializationDeserialization
* @param WebhookEventTypeList $obj
*/
public function testGetters($obj)
{
$this->assertEquals($obj->getEventTypes(), WebhookEventTypeTest::getObject());
}
/**
* @depends testSerializationDeserialization
* @param WebhookEventTypeList $obj
*/
public function testDeprecatedGetters($obj)
{
$this->assertEquals($obj->getEvent_types(), WebhookEventTypeTest::getObject());
}
/**
* @depends testSerializationDeserialization
* @param WebhookEventTypeList $obj
*/
public function testDeprecatedSetterNormalGetter($obj)
{
// Check for Event_types
$obj->setEventTypes(null);
$this->assertNull($obj->getEvent_types());
$this->assertNull($obj->getEventTypes());
$this->assertSame($obj->getEventTypes(), $obj->getEvent_types());
$obj->setEvent_types(WebhookEventTypeTest::getObject());
$this->assertEquals($obj->getEvent_types(), WebhookEventTypeTest::getObject());
//Test All Deprecated Getters and Normal Getters
$this->testDeprecatedGetters($obj);
$this->testGetters($obj);
}
}

View File

@@ -0,0 +1,133 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Common\ResourceModel;
use PayPal\Validation\ArgumentValidator;
use PayPal\Api\WebhookEventList;
use PayPal\Rest\ApiContext;
use PayPal\Transport\PPRestCall;
use PayPal\Api\WebhookEventType;
/**
* Class WebhookEventType
*
* @package PayPal\Test\Api
*/
class WebhookEventTypeTest extends \PHPUnit_Framework_TestCase
{
/**
* Gets Json String of Object WebhookEventType
* @return string
*/
public static function getJson()
{
return '{"name":"TestSample","description":"TestSample"}';
}
/**
* Gets Object Instance with Json data filled in
* @return WebhookEventType
*/
public static function getObject()
{
return new WebhookEventType(self::getJson());
}
/**
* Tests for Serialization and Deserialization Issues
* @return WebhookEventType
*/
public function testSerializationDeserialization()
{
$obj = new WebhookEventType(self::getJson());
$this->assertNotNull($obj);
$this->assertNotNull($obj->getName());
$this->assertNotNull($obj->getDescription());
$this->assertEquals(self::getJson(), $obj->toJson());
return $obj;
}
/**
* @depends testSerializationDeserialization
* @param WebhookEventType $obj
*/
public function testGetters($obj)
{
$this->assertEquals($obj->getName(), "TestSample");
$this->assertEquals($obj->getDescription(), "TestSample");
}
/**
* @depends testSerializationDeserialization
* @param WebhookEventType $obj
*/
public function testDeprecatedGetters($obj)
{
}
/**
* @depends testSerializationDeserialization
* @param WebhookEventType $obj
*/
public function testDeprecatedSetterNormalGetter($obj)
{
//Test All Deprecated Getters and Normal Getters
$this->testDeprecatedGetters($obj);
$this->testGetters($obj);
}
/**
* @dataProvider mockProvider
* @param WebhookEventType $obj
*/
public function testSubscribedEventTypes($obj, $mockApiContext)
{
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
WebhookEventListTest::getJson()
));
$result = $obj->subscribedEventTypes("webhookId", $mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
* @dataProvider mockProvider
* @param WebhookEventType $obj
*/
public function testAvailableEventTypes($obj, $mockApiContext)
{
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
WebhookEventListTest::getJson()
));
$result = $obj->availableEventTypes($mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
public function mockProvider()
{
$obj = self::getObject();
$mockApiContext = $this->getMockBuilder('ApiContext')
->disableOriginalConstructor()
->getMock();
return array(
array($obj, $mockApiContext),
array($obj, null)
);
}
}

View File

@@ -0,0 +1,78 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Common\PPModel;
use PayPal\Api\WebhookList;
/**
* Class WebhookList
*
* @package PayPal\Test\Api
*/
class WebhookListTest extends \PHPUnit_Framework_TestCase
{
/**
* Gets Json String of Object WebhookList
* @return string
*/
public static function getJson()
{
return '{"webhooks":' .WebhookTest::getJson() . '}';
}
/**
* Gets Object Instance with Json data filled in
* @return WebhookList
*/
public static function getObject()
{
return new WebhookList(self::getJson());
}
/**
* Tests for Serialization and Deserialization Issues
* @return WebhookList
*/
public function testSerializationDeserialization()
{
$obj = new WebhookList(self::getJson());
$this->assertNotNull($obj);
$this->assertNotNull($obj->getWebhooks());
$this->assertEquals(self::getJson(), $obj->toJson());
return $obj;
}
/**
* @depends testSerializationDeserialization
* @param WebhookList $obj
*/
public function testGetters($obj)
{
$this->assertEquals($obj->getWebhooks(), WebhookTest::getObject());
}
/**
* @depends testSerializationDeserialization
* @param WebhookList $obj
*/
public function testDeprecatedGetters($obj)
{
}
/**
* @depends testSerializationDeserialization
* @param WebhookList $obj
*/
public function testDeprecatedSetterNormalGetter($obj)
{
//Test All Deprecated Getters and Normal Getters
$this->testDeprecatedGetters($obj);
$this->testGetters($obj);
}
}

View File

@@ -0,0 +1,213 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Common\ResourceModel;
use PayPal\Validation\ArgumentValidator;
use PayPal\Api\WebhookList;
use PayPal\Rest\ApiContext;
use PayPal\Transport\PPRestCall;
use PayPal\Api\Webhook;
/**
* Class Webhook
*
* @package PayPal\Test\Api
*/
class WebhookTest extends \PHPUnit_Framework_TestCase
{
/**
* Gets Json String of Object Webhook
* @return string
*/
public static function getJson()
{
return '{"id":"TestSample","url":"http://www.google.com","event_types":' .WebhookEventTypeTest::getJson() . ',"links":' .LinksTest::getJson() . '}';
}
/**
* Gets Object Instance with Json data filled in
* @return Webhook
*/
public static function getObject()
{
return new Webhook(self::getJson());
}
/**
* Tests for Serialization and Deserialization Issues
* @return Webhook
*/
public function testSerializationDeserialization()
{
$obj = new Webhook(self::getJson());
$this->assertNotNull($obj);
$this->assertNotNull($obj->getId());
$this->assertNotNull($obj->getUrl());
$this->assertNotNull($obj->getEventTypes());
$this->assertNotNull($obj->getLinks());
$this->assertEquals(self::getJson(), $obj->toJson());
return $obj;
}
/**
* @depends testSerializationDeserialization
* @param Webhook $obj
*/
public function testGetters($obj)
{
$this->assertEquals($obj->getId(), "TestSample");
$this->assertEquals($obj->getUrl(), "http://www.google.com");
$this->assertEquals($obj->getEventTypes(), WebhookEventTypeTest::getObject());
$this->assertEquals($obj->getLinks(), LinksTest::getObject());
}
/**
* @depends testSerializationDeserialization
* @param Webhook $obj
*/
public function testDeprecatedGetters($obj)
{
$this->assertEquals($obj->getEvent_types(), WebhookEventTypeTest::getObject());
}
/**
* @depends testSerializationDeserialization
* @param Webhook $obj
*/
public function testDeprecatedSetterNormalGetter($obj)
{
// Check for Event_types
$obj->setEventTypes(null);
$this->assertNull($obj->getEvent_types());
$this->assertNull($obj->getEventTypes());
$this->assertSame($obj->getEventTypes(), $obj->getEvent_types());
$obj->setEvent_types(WebhookEventTypeTest::getObject());
$this->assertEquals($obj->getEvent_types(), WebhookEventTypeTest::getObject());
//Test All Deprecated Getters and Normal Getters
$this->testDeprecatedGetters($obj);
$this->testGetters($obj);
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Url is not a fully qualified URL
*/
public function testUrlValidationForUrl()
{
$obj = new Webhook();
$obj->setUrl(null);
}
/**
* @dataProvider mockProvider
* @param Webhook $obj
*/
public function testCreate($obj, $mockApiContext)
{
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
self::getJson()
));
$result = $obj->create($mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
* @dataProvider mockProvider
* @param Webhook $obj
*/
public function testGet($obj, $mockApiContext)
{
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
WebhookTest::getJson()
));
$result = $obj->get("webhookId", $mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
* @dataProvider mockProvider
* @param Webhook $obj
*/
public function testGetAll($obj, $mockApiContext)
{
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
WebhookListTest::getJson()
));
$result = $obj->getAll($mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
* @dataProvider mockProvider
* @param Webhook $obj
*/
public function testUpdate($obj, $mockApiContext)
{
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
self::getJson()
));
$patchRequest = PatchRequestTest::getObject();
$result = $obj->update($patchRequest, $mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
* @dataProvider mockProvider
* @param Webhook $obj
*/
public function testDelete($obj, $mockApiContext)
{
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
true
));
$result = $obj->delete($mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
public function mockProvider()
{
$obj = self::getObject();
$mockApiContext = $this->getMockBuilder('ApiContext')
->disableOriginalConstructor()
->getMock();
return array(
array($obj, $mockApiContext),
array($obj, null)
);
}
}