Update Webhooks API

This commit is contained in:
jaypatel512 and sdcoffey
2016-09-20 14:01:47 -07:00
parent a1039ae38a
commit af4648bdfd
16 changed files with 611 additions and 173 deletions

View File

@@ -0,0 +1,213 @@
<?php
namespace PayPal\Api;
use PayPal\Common\PayPalResourceModel;
use PayPal\Validation\ArgumentValidator;
use PayPal\Api\VerifyWebhookSignatureResponse;
use PayPal\Rest\ApiContext;
use PayPal\Validation\UrlValidator;
/**
* Class VerifyWebhookSignature
*
* Verify webhook signature.
*
* @package PayPal\Api
*
* @property string auth_algo
* @property string cert_url
* @property string transmission_id
* @property string transmission_sig
* @property string transmission_time
* @property string webhook_id
* @property \PayPal\Api\WebhookEvent webhook_event
*/
class VerifyWebhookSignature extends PayPalResourceModel
{
/**
* The algorithm that PayPal uses to generate the signature and that you can use to verify the signature. Extract this value from the `PAYPAL-AUTH-ALGO` response header, which is received with the webhook notification.
*
* @param string $auth_algo
*
* @return $this
*/
public function setAuthAlgo($auth_algo)
{
$this->auth_algo = $auth_algo;
return $this;
}
/**
* The algorithm that PayPal uses to generate the signature and that you can use to verify the signature. Extract this value from the `PAYPAL-AUTH-ALGO` response header, which is received with the webhook notification.
*
* @return string
*/
public function getAuthAlgo()
{
return $this->auth_algo;
}
/**
* The X.509 public key certificate. Download the certificate from this URL and use it to verify the signature. Extract this value from the `PAYPAL-CERT-URL` response header, which is received with the webhook notification.
*
* @param string $cert_url
* @throws \InvalidArgumentException
* @return $this
*/
public function setCertUrl($cert_url)
{
UrlValidator::validate($cert_url, "CertUrl");
$this->cert_url = $cert_url;
return $this;
}
/**
* The X.509 public key certificate. Download the certificate from this URL and use it to verify the signature. Extract this value from the `PAYPAL-CERT-URL` response header, which is received with the webhook notification.
*
* @return string
*/
public function getCertUrl()
{
return $this->cert_url;
}
/**
* The ID of the HTTP transmission. Contained in the `PAYPAL-TRANSMISSION-ID` header of the notification message.
*
* @param string $transmission_id
*
* @return $this
*/
public function setTransmissionId($transmission_id)
{
$this->transmission_id = $transmission_id;
return $this;
}
/**
* The ID of the HTTP transmission. Contained in the `PAYPAL-TRANSMISSION-ID` header of the notification message.
*
* @return string
*/
public function getTransmissionId()
{
return $this->transmission_id;
}
/**
* The PayPal-generated asymmetric signature. Extract this value from the `PAYPAL-TRANSMISSION-SIG` response header, which is received with the webhook notification.
*
* @param string $transmission_sig
*
* @return $this
*/
public function setTransmissionSig($transmission_sig)
{
$this->transmission_sig = $transmission_sig;
return $this;
}
/**
* The PayPal-generated asymmetric signature. Extract this value from the `PAYPAL-TRANSMISSION-SIG` response header, which is received with the webhook notification.
*
* @return string
*/
public function getTransmissionSig()
{
return $this->transmission_sig;
}
/**
* The date and time of the HTTP transmission. Contained in the `PAYPAL-TRANSMISSION-TIME` header of the notification message.
*
* @param string $transmission_time
*
* @return $this
*/
public function setTransmissionTime($transmission_time)
{
$this->transmission_time = $transmission_time;
return $this;
}
/**
* The date and time of the HTTP transmission. Contained in the `PAYPAL-TRANSMISSION-TIME` header of the notification message.
*
* @return string
*/
public function getTransmissionTime()
{
return $this->transmission_time;
}
/**
* The ID of the webhook as configured in your Developer Portal account.
*
* @param string $webhook_id
*
* @return $this
*/
public function setWebhookId($webhook_id)
{
$this->webhook_id = $webhook_id;
return $this;
}
/**
* The ID of the webhook as configured in your Developer Portal account.
*
* @return string
*/
public function getWebhookId()
{
return $this->webhook_id;
}
/**
* The webhook notification, which is the content of the HTTP `POST` request body.
*
* @param \PayPal\Api\WebhookEvent $webhook_event
*
* @return $this
*/
public function setWebhookEvent($webhook_event)
{
$this->webhook_event = $webhook_event;
return $this;
}
/**
* The webhook notification, which is the content of the HTTP `POST` request body.
*
* @return \PayPal\Api\WebhookEvent
*/
public function getWebhookEvent()
{
return $this->webhook_event;
}
/**
* Verifies a webhook signature.
*
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return VerifyWebhookSignatureResponse
*/
public function post($apiContext = null, $restCall = null)
{
$payLoad = $this->toJSON();
$json = self::executeCall(
"/v1/notifications/verify-webhook-signature",
"POST",
$payLoad,
null,
$apiContext,
$restCall
);
$ret = new VerifyWebhookSignatureResponse();
$ret->fromJson($json);
return $ret;
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace PayPal\Api;
use PayPal\Common\PayPalModel;
/**
* Class VerifyWebhookSignatureResponse
*
* The verify webhook signature response.
*
* @package PayPal\Api
*
* @property string verification_status
*/
class VerifyWebhookSignatureResponse extends PayPalModel
{
/**
* The status of the signature verification. Value is `SUCCESS` or `FAILURE`.
* Valid Values: ["SUCCESS", "FAILURE"]
*
* @param string $verification_status
*
* @return $this
*/
public function setVerificationStatus($verification_status)
{
$this->verification_status = $verification_status;
return $this;
}
/**
* The status of the signature verification. Value is `SUCCESS` or `FAILURE`.
*
* @return string
*/
public function getVerificationStatus()
{
return $this->verification_status;
}
}

View File

@@ -3,15 +3,15 @@
namespace PayPal\Api;
use PayPal\Common\PayPalResourceModel;
use PayPal\Rest\ApiContext;
use PayPal\Transport\PayPalRestCall;
use PayPal\Validation\ArgumentValidator;
use PayPal\Api\WebhookList;
use PayPal\Rest\ApiContext;
use PayPal\Validation\UrlValidator;
/**
* Class Webhook
*
* Represents Webhook resource.
* One or more webhook objects.
*
* @package PayPal\Api
*
@@ -22,7 +22,7 @@ use PayPal\Validation\UrlValidator;
class Webhook extends PayPalResourceModel
{
/**
* Identifier of the webhook resource.
* The ID of the webhook.
*
* @param string $id
*
@@ -35,7 +35,7 @@ class Webhook extends PayPalResourceModel
}
/**
* Identifier of the webhook resource.
* The ID of the webhook.
*
* @return string
*/
@@ -45,7 +45,7 @@ class Webhook extends PayPalResourceModel
}
/**
* Webhook notification endpoint url.
* The URL that is configured to listen on `localhost` for incoming `POST` notification messages that contain event information.
*
* @param string $url
* @throws \InvalidArgumentException
@@ -59,7 +59,7 @@ class Webhook extends PayPalResourceModel
}
/**
* Webhook notification endpoint url.
* The URL that is configured to listen on `localhost` for incoming `POST` notification messages that contain event information.
*
* @return string
*/
@@ -69,7 +69,7 @@ class Webhook extends PayPalResourceModel
}
/**
* List of Webhooks event-types.
* A list of up to ten events to which to subscribe your webhook. To subscribe to all events including new events as they are added, specify the asterisk (`*`) wildcard. To replace the `event_types` array, specify the `*` wildcard. To see all supported events, [list available events](#available-event-type.list).
*
* @param \PayPal\Api\WebhookEventType[] $event_types
*
@@ -82,7 +82,7 @@ class Webhook extends PayPalResourceModel
}
/**
* List of Webhooks event-types.
* A list of up to ten events to which to subscribe your webhook. To subscribe to all events including new events as they are added, specify the asterisk (`*`) wildcard. To replace the `event_types` array, specify the `*` wildcard. To see all supported events, [list available events](#available-event-type.list).
*
* @return \PayPal\Api\WebhookEventType[]
*/
@@ -122,7 +122,7 @@ class Webhook extends PayPalResourceModel
}
/**
* Creates the Webhook for the application associated with the access token.
* Subscribes your webhook listener to events. A successful call returns a [`webhook`](/docs/api/webhooks/#definition-webhook) object, which includes the webhook ID for later use.
*
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
@@ -144,7 +144,7 @@ class Webhook extends PayPalResourceModel
}
/**
* Retrieves the Webhook identified by webhook_id for the application associated with access token.
* Shows details for a webhook, by ID.
*
* @param string $webhookId
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
@@ -171,15 +171,34 @@ class Webhook extends PayPalResourceModel
/**
* Retrieves all Webhooks for the application associated with access token.
*
* @deprecated Please use Webhook#getAllWithParams instead.
*
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return WebhookList
*/
public static function getAll($apiContext = null, $restCall = null)
{
return self::getAllWithParams(array(), $apiContext, $restCall);
}
/**
* Lists all webhooks for an app.
*
* @param array $params
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return WebhookList
*/
public static function getAllWithParams($params = array(), $apiContext = null, $restCall = null)
{
ArgumentValidator::validate($params, 'params');
$payLoad = "";
$allowedParams = array(
'anchor_type' => 1,
);
$json = self::executeCall(
"/v1/notifications/webhooks",
"/v1/notifications/webhooks?" . http_build_query(array_intersect_key($params, $allowedParams)),
"GET",
$payLoad,
null,
@@ -192,7 +211,7 @@ class Webhook extends PayPalResourceModel
}
/**
* Updates the Webhook identified by webhook_id for the application associated with access token.
* Replaces webhook fields with new values. Pass a `json_patch` object with `replace` operation and `path`, which is `/url` for a URL or `/event_types` for events. The `value` is either the URL or a list of events.
*
* @param PatchRequest $patchRequest
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
@@ -217,7 +236,7 @@ class Webhook extends PayPalResourceModel
}
/**
* Deletes the Webhook identified by webhook_id for the application associated with access token.
* Deletes a webhook, by ID.
*
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls

View File

@@ -3,30 +3,31 @@
namespace PayPal\Api;
use PayPal\Common\PayPalResourceModel;
use PayPal\Exception\PayPalConnectionException;
use PayPal\Rest\ApiContext;
use PayPal\Transport\PayPalRestCall;
use PayPal\Validation\ArgumentValidator;
use PayPal\Validation\JsonValidator;
use PayPal\Api\WebhookEventList;
use PayPal\Rest\ApiContext;
/**
* Class WebhookEvent
*
* Represents a Webhooks event
* A webhook event notification.
*
* @package PayPal\Api
*
* @property string id
* @property string create_time
* @property string resource_type
* @property string event_version
* @property string event_type
* @property string summary
* @property mixed resource
* @property \PayPal\Common\PayPalModel resource
* @property string status
* @property mixed[] transmissions
*/
class WebhookEvent extends PayPalResourceModel
{
/**
* Identifier of the Webhooks event resource.
* The ID of the webhook event notification.
*
* @param string $id
*
@@ -39,7 +40,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* Identifier of the Webhooks event resource.
* The ID of the webhook event notification.
*
* @return string
*/
@@ -49,7 +50,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* Time the resource was created.
* The date and time when the webhook event notification was created.
*
* @param string $create_time
*
@@ -62,7 +63,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* Time the resource was created.
* The date and time when the webhook event notification was created.
*
* @return string
*/
@@ -72,7 +73,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* Name of the resource contained in resource element.
* The name of the resource related to the webhook notification event.
*
* @param string $resource_type
*
@@ -85,7 +86,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* Name of the resource contained in resource element.
* The name of the resource related to the webhook notification event.
*
* @return string
*/
@@ -95,7 +96,30 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* Name of the event type that occurred on resource, identified by data_resource element, to trigger the Webhooks event.
* The version of the event.
*
* @param string $event_version
*
* @return $this
*/
public function setEventVersion($event_version)
{
$this->event_version = $event_version;
return $this;
}
/**
* The version of the event.
*
* @return string
*/
public function getEventVersion()
{
return $this->event_version;
}
/**
* The event that triggered the webhook event notification.
*
* @param string $event_type
*
@@ -108,7 +132,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* Name of the event type that occurred on resource, identified by data_resource element, to trigger the Webhooks event.
* The event that triggered the webhook event notification.
*
* @return string
*/
@@ -118,7 +142,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* A summary description of the event. E.g. A successful payment authorization was created for $$
* A summary description for the event notification. For example, `A payment authorization was created.`
*
* @param string $summary
*
@@ -131,7 +155,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* A summary description of the event. E.g. A successful payment authorization was created for $$
* A summary description for the event notification. For example, `A payment authorization was created.`
*
* @return string
*/
@@ -141,7 +165,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* This contains the resource that is identified by resource_type element.
* The resource that triggered the webhook event notification.
*
* @param \PayPal\Common\PayPalModel $resource
*
@@ -154,7 +178,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* This contains the resource that is identified by resource_type element.
* The resource that triggered the webhook event notification.
*
* @return \PayPal\Common\PayPalModel
*/
@@ -171,6 +195,8 @@ class WebhookEvent extends PayPalResourceModel
*
* NOTE: PLEASE DO NOT USE THE DATA PROVIDED IN WEBHOOK DIRECTLY, AS HACKER COULD PASS IN FAKE DATA. IT IS VERY IMPORTANT THAT YOU RETRIEVE THE ID AND MAKE A SEPARATE CALL TO PAYPAL API.
*
* @deprecated todo: add refrence to correct method
*
* @param string $body
* @param ApiContext $apiContext
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
@@ -227,7 +253,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* Resends the Webhooks event resource identified by event_id.
* Resends a webhook event notification, by ID. Any pending notifications are not resent.
*
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
@@ -250,7 +276,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* 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.
* Lists webhook event notifications. Use query parameters to filter the response.
*
* @param array $params
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
@@ -265,6 +291,8 @@ class WebhookEvent extends PayPalResourceModel
'page_size' => 1,
'start_time' => 1,
'end_time' => 1,
'transaction_id' => 1,
'event_type' => 1,
);
$json = self::executeCall(
"/v1/notifications/webhooks-events" . "?" . http_build_query(array_intersect_key($params, $allowedParams)),

View File

@@ -7,7 +7,7 @@ use PayPal\Common\PayPalModel;
/**
* Class WebhookEventList
*
* List of Webhooks event resources
* List of webhooks events.
*
* @package PayPal\Api
*
@@ -18,7 +18,7 @@ use PayPal\Common\PayPalModel;
class WebhookEventList extends PayPalModel
{
/**
* A list of Webhooks event resources
* A list of webhooks events.
*
* @param \PayPal\Api\WebhookEvent[] $events
*
@@ -31,7 +31,7 @@ class WebhookEventList extends PayPalModel
}
/**
* A list of Webhooks event resources
* A list of webhooks events.
*
* @return \PayPal\Api\WebhookEvent[]
*/
@@ -71,7 +71,7 @@ class WebhookEventList extends PayPalModel
}
/**
* 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.
* The number of items in each range of results. Note that the response might have fewer items than the requested `page_size` value.
*
* @param int $count
*
@@ -84,7 +84,7 @@ class WebhookEventList extends PayPalModel
}
/**
* 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.
* The number of items in each range of results. Note that the response might have fewer items than the requested `page_size` value.
*
* @return int
*/

View File

@@ -3,24 +3,25 @@
namespace PayPal\Api;
use PayPal\Common\PayPalResourceModel;
use PayPal\Rest\ApiContext;
use PayPal\Transport\PayPalRestCall;
use PayPal\Validation\ArgumentValidator;
use PayPal\Api\WebhookEventTypeList;
use PayPal\Rest\ApiContext;
/**
* Class WebhookEventType
*
* Contains the information for a Webhooks event-type
* A list of events.
*
* @package PayPal\Api
*
* @property string name
* @property string description
* @property string status
*/
class WebhookEventType extends PayPalResourceModel
{
/**
* Unique event-type name.
* The unique event name.
*
* @param string $name
*
@@ -33,7 +34,7 @@ class WebhookEventType extends PayPalResourceModel
}
/**
* Unique event-type name.
* The unique event name.
*
* @return string
*/
@@ -43,7 +44,7 @@ class WebhookEventType extends PayPalResourceModel
}
/**
* Human readable description of the event-type
* A human-readable description of the event.
*
* @param string $description
*
@@ -56,7 +57,7 @@ class WebhookEventType extends PayPalResourceModel
}
/**
* Human readable description of the event-type
* A human-readable description of the event.
*
* @return string
*/
@@ -66,7 +67,30 @@ class WebhookEventType extends PayPalResourceModel
}
/**
* Retrieves the list of events-types subscribed by the given Webhook.
* The status of a webhook event.
*
* @param string $status
*
* @return $this
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* The status of a webhook event.
*
* @return string
*/
public function getStatus()
{
return $this->status;
}
/**
* Lists event subscriptions for a webhook, by ID.
*
* @param string $webhookId
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
@@ -91,7 +115,7 @@ class WebhookEventType extends PayPalResourceModel
}
/**
* Retrieves the master list of available Webhooks events-types resources for any webhook to subscribe to.
* Lists available events to which any webhook can subscribe. For a list of supported events, see [Webhook events](/docs/integration/direct/rest/webhooks/webhook-events/).
*
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls

View File

@@ -7,7 +7,7 @@ use PayPal\Common\PayPalModel;
/**
* Class WebhookEventTypeList
*
* List of Webhooks event-types
* List of webhook events.
*
* @package PayPal\Api
*
@@ -16,7 +16,7 @@ use PayPal\Common\PayPalModel;
class WebhookEventTypeList extends PayPalModel
{
/**
* A list of Webhooks event-types
* A list of webhook events.
*
* @param \PayPal\Api\WebhookEventType[] $event_types
*
@@ -29,7 +29,7 @@ class WebhookEventTypeList extends PayPalModel
}
/**
* A list of Webhooks event-types
* A list of webhook events.
*
* @return \PayPal\Api\WebhookEventType[]
*/

View File

@@ -7,7 +7,7 @@ use PayPal\Common\PayPalModel;
/**
* Class WebhookList
*
* List of Webhooks
* List of webhooks.
*
* @package PayPal\Api
*
@@ -16,7 +16,7 @@ use PayPal\Common\PayPalModel;
class WebhookList extends PayPalModel
{
/**
* A list of Webhooks
* A list of webhooks.
*
* @param \PayPal\Api\Webhook[] $webhooks
*
@@ -29,7 +29,7 @@ class WebhookList extends PayPalModel
}
/**
* A list of Webhooks
* A list of webhooks.
*
* @return \PayPal\Api\Webhook[]
*/

View File

@@ -0,0 +1,56 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Common\PayPalModel;
use PayPal\Api\VerifyWebhookSignatureResponse;
/**
* Class VerifyWebhookSignatureResponse
*
* @package PayPal\Test\Api
*/
class VerifyWebhookSignatureResponseTest extends \PHPUnit_Framework_TestCase
{
/**
* Gets Json String of Object VerifyWebhookSignatureResponse
* @return string
*/
public static function getJson()
{
return '{"verification_status":"TestSample"}';
}
/**
* Gets Object Instance with Json data filled in
* @return VerifyWebhookSignatureResponse
*/
public static function getObject()
{
return new VerifyWebhookSignatureResponse(self::getJson());
}
/**
* Tests for Serialization and Deserialization Issues
* @return VerifyWebhookSignatureResponse
*/
public function testSerializationDeserialization()
{
$obj = new VerifyWebhookSignatureResponse(self::getJson());
$this->assertNotNull($obj);
$this->assertNotNull($obj->getVerificationStatus());
$this->assertEquals(self::getJson(), $obj->toJson());
return $obj;
}
/**
* @depends testSerializationDeserialization
* @param VerifyWebhookSignatureResponse $obj
*/
public function testGetters($obj)
{
$this->assertEquals($obj->getVerificationStatus(), "TestSample");
}
}

View File

@@ -0,0 +1,111 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Common\PayPalResourceModel;
use PayPal\Validation\ArgumentValidator;
use PayPal\Api\VerifyWebhookSignatureResponse;
use PayPal\Rest\ApiContext;
use PayPal\Api\VerifyWebhookSignature;
/**
* Class VerifyWebhookSignature
*
* @package PayPal\Test\Api
*/
class VerifyWebhookSignatureTest extends \PHPUnit_Framework_TestCase
{
/**
* Gets Json String of Object VerifyWebhookSignature
* @return string
*/
public static function getJson()
{
return '{"auth_algo":"TestSample","cert_url":"http://www.google.com","transmission_id":"TestSample","transmission_sig":"TestSample","transmission_time":"TestSample","webhook_id":"TestSample","webhook_event":' .WebhookEventTest::getJson() . '}';
}
/**
* Gets Object Instance with Json data filled in
* @return VerifyWebhookSignature
*/
public static function getObject()
{
return new VerifyWebhookSignature(self::getJson());
}
/**
* Tests for Serialization and Deserialization Issues
* @return VerifyWebhookSignature
*/
public function testSerializationDeserialization()
{
$obj = new VerifyWebhookSignature(self::getJson());
$this->assertNotNull($obj);
$this->assertNotNull($obj->getAuthAlgo());
$this->assertNotNull($obj->getCertUrl());
$this->assertNotNull($obj->getTransmissionId());
$this->assertNotNull($obj->getTransmissionSig());
$this->assertNotNull($obj->getTransmissionTime());
$this->assertNotNull($obj->getWebhookId());
$this->assertNotNull($obj->getWebhookEvent());
$this->assertEquals(self::getJson(), $obj->toJson());
return $obj;
}
/**
* @depends testSerializationDeserialization
* @param VerifyWebhookSignature $obj
*/
public function testGetters($obj)
{
$this->assertEquals($obj->getAuthAlgo(), "TestSample");
$this->assertEquals($obj->getCertUrl(), "http://www.google.com");
$this->assertEquals($obj->getTransmissionId(), "TestSample");
$this->assertEquals($obj->getTransmissionSig(), "TestSample");
$this->assertEquals($obj->getTransmissionTime(), "TestSample");
$this->assertEquals($obj->getWebhookId(), "TestSample");
$this->assertEquals($obj->getWebhookEvent(), WebhookEventTest::getObject());
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage CertUrl is not a fully qualified URL
*/
public function testUrlValidationForCertUrl()
{
$obj = new VerifyWebhookSignature();
$obj->setCertUrl(null);
}
/**
* @dataProvider mockProvider
* @param VerifyWebhookSignature $obj
*/
public function testPost($obj, $mockApiContext)
{
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
VerifyWebhookSignatureResponseTest::getJson()
));
$result = $obj->post($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

@@ -2,6 +2,7 @@
namespace PayPal\Test\Api;
use PayPal\Common\PayPalModel;
use PayPal\Api\WebhookEventList;
/**
@@ -55,4 +56,6 @@ class WebhookEventListTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($obj->getCount(), 123);
$this->assertEquals($obj->getLinks(), LinksTest::getObject());
}
}

View File

@@ -2,9 +2,11 @@
namespace PayPal\Test\Api;
use PayPal\Api\WebhookEvent;
use PayPal\Exception\PayPalConnectionException;
use PayPal\Common\PayPalResourceModel;
use PayPal\Validation\ArgumentValidator;
use PayPal\Api\WebhookEventList;
use PayPal\Rest\ApiContext;
use PayPal\Api\WebhookEvent;
/**
* Class WebhookEvent
@@ -19,7 +21,7 @@ class WebhookEventTest extends \PHPUnit_Framework_TestCase
*/
public static function getJson()
{
return '{"id":"TestSample","create_time":"TestSample","resource_type":"TestSample","event_type":"TestSample","summary":"TestSample","resource":"TestSampleObject","links":' .LinksTest::getJson() . '}';
return '{"id":"TestSample","create_time":"TestSample","resource_type":"TestSample","event_version":"TestSample","event_type":"TestSample","summary":"TestSample","resource":"TestSampleObject","status":"TestSample","transmissions":"TestSampleObject","links":' .LinksTest::getJson() . '}';
}
/**
@@ -43,9 +45,12 @@ class WebhookEventTest extends \PHPUnit_Framework_TestCase
$this->assertNotNull($obj->getId());
$this->assertNotNull($obj->getCreateTime());
$this->assertNotNull($obj->getResourceType());
$this->assertNotNull($obj->getEventVersion());
$this->assertNotNull($obj->getEventType());
$this->assertNotNull($obj->getSummary());
$this->assertNotNull($obj->getResource());
$this->assertNotNull($obj->getStatus());
$this->assertNotNull($obj->getTransmissions());
$this->assertNotNull($obj->getLinks());
$this->assertEquals(self::getJson(), $obj->toJson());
return $obj;
@@ -60,9 +65,12 @@ class WebhookEventTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($obj->getId(), "TestSample");
$this->assertEquals($obj->getCreateTime(), "TestSample");
$this->assertEquals($obj->getResourceType(), "TestSample");
$this->assertEquals($obj->getEventVersion(), "TestSample");
$this->assertEquals($obj->getEventType(), "TestSample");
$this->assertEquals($obj->getSummary(), "TestSample");
$this->assertEquals($obj->getResource(), "TestSampleObject");
$this->assertEquals($obj->getStatus(), "TestSample");
$this->assertEquals($obj->getTransmissions(), "TestSampleObject");
$this->assertEquals($obj->getLinks(), LinksTest::getObject());
}
@@ -72,17 +80,17 @@ class WebhookEventTest extends \PHPUnit_Framework_TestCase
*/
public function testGet($obj, $mockApiContext)
{
$mockPayPalRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
->disableOriginalConstructor()
->getMock();
$mockPayPalRestCall->expects($this->any())
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
WebhookEventTest::getJson()
));
$result = $obj->get("eventId", $mockApiContext, $mockPayPalRestCall);
$result = $obj->get("eventId", $mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
@@ -91,17 +99,18 @@ class WebhookEventTest extends \PHPUnit_Framework_TestCase
*/
public function testResend($obj, $mockApiContext)
{
$mockPayPalRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
->disableOriginalConstructor()
->getMock();
$mockPayPalRestCall->expects($this->any())
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
self::getJson()
));
$eventResend = EventResendTest::getObject();
$result = $obj->resend($mockApiContext, $mockPayPalRestCall);
$result = $obj->resend($eventResend, $mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
@@ -110,60 +119,18 @@ class WebhookEventTest extends \PHPUnit_Framework_TestCase
*/
public function testList($obj, $mockApiContext)
{
$mockPayPalRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
->disableOriginalConstructor()
->getMock();
$mockPayPalRestCall->expects($this->any())
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
WebhookEventListTest::getJson()
));
$params = array();
$result = $obj->all($params, $mockApiContext, $mockPayPalRestCall);
$this->assertNotNull($result);
}
/**
* @dataProvider mockProvider
* @param WebhookEvent $obj
*/
public function testValidateWebhook($obj, $mockApiContext)
{
$mockPayPalRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
->disableOriginalConstructor()
->getMock();
$mockPayPalRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
WebhookEventTest::getJson()
));
$result = WebhookEvent::validateAndGetReceivedEvent('{"id":"123"}', $mockApiContext, $mockPayPalRestCall);
//$result = $obj->get("eventId", $mockApiContext, $mockPayPalRestCall);
$this->assertNotNull($result);
}
/**
* @dataProvider mockProvider
* @param WebhookEvent $obj
* @param ApiContext $mockApiContext
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Webhook Event Id provided in the data is incorrect. This could happen if anyone other than PayPal is faking the incoming webhook data.
*/
public function testValidateWebhook404($obj, $mockApiContext)
{
$mockPayPalRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
->disableOriginalConstructor()
->getMock();
$mockPayPalRestCall->expects($this->any())
->method('execute')
->will($this->throwException(new PayPalConnectionException(null, "404 not found", 404)));
$result = WebhookEvent::validateAndGetReceivedEvent('{"id":"123"}', $mockApiContext, $mockPayPalRestCall);
$result = $obj->all($params, $mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
@@ -178,45 +145,4 @@ class WebhookEventTest extends \PHPUnit_Framework_TestCase
array($obj, null)
);
}
/**
* @dataProvider mockProvider
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Body cannot be null or empty
*/
public function testValidateWebhookNull($mockApiContext)
{
WebhookEvent::validateAndGetReceivedEvent(null, $mockApiContext);
}
/**
* @dataProvider mockProvider
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Body cannot be null or empty
*/
public function testValidateWebhookEmpty($mockApiContext)
{
WebhookEvent::validateAndGetReceivedEvent('', $mockApiContext);
}
/**
* @dataProvider mockProvider
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Request Body is not a valid JSON.
*/
public function testValidateWebhookInvalid($mockApiContext)
{
WebhookEvent::validateAndGetReceivedEvent('something-invalid', $mockApiContext);
}
/**
* @dataProvider mockProvider
* @param $mockApiContext ApiContext
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Id attribute not found in JSON. Possible reason could be invalid JSON Object
*/
public function testValidateWebhookValidJSONWithoutId($obj, $mockApiContext)
{
WebhookEvent::validateAndGetReceivedEvent('{"summary":"json"}', $mockApiContext);
}
}

View File

@@ -2,6 +2,7 @@
namespace PayPal\Test\Api;
use PayPal\Common\PayPalModel;
use PayPal\Api\WebhookEventTypeList;
/**
@@ -51,4 +52,6 @@ class WebhookEventTypeListTest extends \PHPUnit_Framework_TestCase
{
$this->assertEquals($obj->getEventTypes(), WebhookEventTypeTest::getObject());
}
}

View File

@@ -2,6 +2,10 @@
namespace PayPal\Test\Api;
use PayPal\Common\PayPalResourceModel;
use PayPal\Validation\ArgumentValidator;
use PayPal\Api\WebhookEventTypeList;
use PayPal\Rest\ApiContext;
use PayPal\Api\WebhookEventType;
/**
@@ -17,7 +21,7 @@ class WebhookEventTypeTest extends \PHPUnit_Framework_TestCase
*/
public static function getJson()
{
return '{"name":"TestSample","description":"TestSample"}';
return '{"name":"TestSample","description":"TestSample","status":"TestSample"}';
}
/**
@@ -40,6 +44,7 @@ class WebhookEventTypeTest extends \PHPUnit_Framework_TestCase
$this->assertNotNull($obj);
$this->assertNotNull($obj->getName());
$this->assertNotNull($obj->getDescription());
$this->assertNotNull($obj->getStatus());
$this->assertEquals(self::getJson(), $obj->toJson());
return $obj;
}
@@ -52,6 +57,7 @@ class WebhookEventTypeTest extends \PHPUnit_Framework_TestCase
{
$this->assertEquals($obj->getName(), "TestSample");
$this->assertEquals($obj->getDescription(), "TestSample");
$this->assertEquals($obj->getStatus(), "TestSample");
}
/**
@@ -60,17 +66,17 @@ class WebhookEventTypeTest extends \PHPUnit_Framework_TestCase
*/
public function testSubscribedEventTypes($obj, $mockApiContext)
{
$mockPayPalRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
->disableOriginalConstructor()
->getMock();
$mockPayPalRestCall->expects($this->any())
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
WebhookEventTypeListTest::getJson()
));
$result = $obj->subscribedEventTypes("webhookId", $mockApiContext, $mockPayPalRestCall);
$result = $obj->subscribedEventTypes("webhookId", $mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
@@ -79,17 +85,17 @@ class WebhookEventTypeTest extends \PHPUnit_Framework_TestCase
*/
public function testAvailableEventTypes($obj, $mockApiContext)
{
$mockPayPalRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
->disableOriginalConstructor()
->getMock();
$mockPayPalRestCall->expects($this->any())
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
WebhookEventTypeListTest::getJson()
));
$result = $obj->availableEventTypes($mockApiContext, $mockPayPalRestCall);
$result = $obj->availableEventTypes($mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}

View File

@@ -2,6 +2,7 @@
namespace PayPal\Test\Api;
use PayPal\Common\PayPalModel;
use PayPal\Api\WebhookList;
/**
@@ -51,4 +52,6 @@ class WebhookListTest extends \PHPUnit_Framework_TestCase
{
$this->assertEquals($obj->getWebhooks(), WebhookTest::getObject());
}
}

View File

@@ -2,6 +2,10 @@
namespace PayPal\Test\Api;
use PayPal\Common\PayPalResourceModel;
use PayPal\Validation\ArgumentValidator;
use PayPal\Api\WebhookList;
use PayPal\Rest\ApiContext;
use PayPal\Api\Webhook;
/**
@@ -67,24 +71,23 @@ class WebhookTest extends \PHPUnit_Framework_TestCase
$obj = new Webhook();
$obj->setUrl(null);
}
/**
* @dataProvider mockProvider
* @param Webhook $obj
*/
public function testCreate($obj, $mockApiContext)
{
$mockPayPalRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
->disableOriginalConstructor()
->getMock();
$mockPayPalRestCall->expects($this->any())
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
self::getJson()
));
$result = $obj->create($mockApiContext, $mockPayPalRestCall);
$result = $obj->create($mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
@@ -93,17 +96,17 @@ class WebhookTest extends \PHPUnit_Framework_TestCase
*/
public function testGet($obj, $mockApiContext)
{
$mockPayPalRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
->disableOriginalConstructor()
->getMock();
$mockPayPalRestCall->expects($this->any())
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
WebhookTest::getJson()
));
$result = $obj->get("webhookId", $mockApiContext, $mockPayPalRestCall);
$result = $obj->get("webhookId", $mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
@@ -112,17 +115,18 @@ class WebhookTest extends \PHPUnit_Framework_TestCase
*/
public function testGetAll($obj, $mockApiContext)
{
$mockPayPalRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
->disableOriginalConstructor()
->getMock();
$mockPayPalRestCall->expects($this->any())
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
WebhookListTest::getJson()
));
$params = array();
$result = $obj->getAll($mockApiContext, $mockPayPalRestCall);
$result = $obj->getAllWithParams($params, $mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
@@ -131,18 +135,18 @@ class WebhookTest extends \PHPUnit_Framework_TestCase
*/
public function testUpdate($obj, $mockApiContext)
{
$mockPayPalRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
->disableOriginalConstructor()
->getMock();
$mockPayPalRestCall->expects($this->any())
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
self::getJson()
));
$patchRequest = PatchRequestTest::getObject();
$result = $obj->update($patchRequest, $mockApiContext, $mockPayPalRestCall);
$result = $obj->update($patchRequest, $mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
@@ -151,17 +155,17 @@ class WebhookTest extends \PHPUnit_Framework_TestCase
*/
public function testDelete($obj, $mockApiContext)
{
$mockPayPalRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
->disableOriginalConstructor()
->getMock();
$mockPayPalRestCall->expects($this->any())
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
true
));
$result = $obj->delete($mockApiContext, $mockPayPalRestCall);
$result = $obj->delete($mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}