From fb9584ba66535b15f3648380c2441f3eef38c021 Mon Sep 17 00:00:00 2001
From: japatel
Date: Fri, 12 Dec 2014 17:00:33 -0600
Subject: [PATCH] More Webhook API Changes
- Updated API Models with Fixes
- Updated Samples
- Additional Functional Tests
---
lib/PayPal/Api/WebhookEvent.php | 5 +-
lib/PayPal/Api/WebhookEventType.php | 8 +-
lib/PayPal/Common/PPReflectionUtil.php | 4 +
sample/doc/assets/behavior.js | 112 ++++++------
.../notifications/SearchWebhookEvents.html | 9 +-
sample/doc/notifications/createWebhook.html | 2 +-
.../payments/CreatePaymentUsingPayPal.html | 2 +-
sample/index.php | 114 +++++++++++-
sample/notifications/DeleteAllWebhooks.php | 24 +++
sample/notifications/DeleteWebhook.php | 25 +++
sample/notifications/GetWebhook.php | 26 +++
.../ListSubscribedWebhookEventTypes.php | 26 +++
sample/notifications/ListWebhooks.php | 27 +++
sample/notifications/SearchWebhookEvents.php | 31 ++++
sample/notifications/UpdateWebhook.php | 55 ++++++
.../notifications/WebhookEventTypesList.php | 21 +++
sample/notifications/createWebhook.php | 77 +++++++++
sample/payments/CreatePaymentUsingPayPal.php | 2 +-
sample/payments/ExecutePayment.php | 12 ++
.../Functional/Api/WebhookFunctionalTest.php | 157 +++++++++++++++++
.../WebhookFunctionalTest/testCreate.json | 75 ++++++++
.../WebhookFunctionalTest/testDelete.json | 33 ++++
.../testEventResend.json | 89 ++++++++++
.../testEventSearch.json | 162 ++++++++++++++++++
.../WebhookFunctionalTest/testGet.json | 64 +++++++
.../WebhookFunctionalTest/testGetAll.json | 99 +++++++++++
.../WebhookFunctionalTest/testGetEvent.json | 89 ++++++++++
.../WebhookFunctionalTest/testUpdate.json | 76 ++++++++
.../webhook_get_available_event_types.json | 56 ++++++
.../webhook_get_subscribed_event_types.json | 45 +++++
30 files changed, 1454 insertions(+), 73 deletions(-)
create mode 100644 sample/notifications/DeleteAllWebhooks.php
create mode 100644 sample/notifications/DeleteWebhook.php
create mode 100644 sample/notifications/GetWebhook.php
create mode 100644 sample/notifications/ListSubscribedWebhookEventTypes.php
create mode 100644 sample/notifications/ListWebhooks.php
create mode 100644 sample/notifications/SearchWebhookEvents.php
create mode 100644 sample/notifications/UpdateWebhook.php
create mode 100644 sample/notifications/WebhookEventTypesList.php
create mode 100644 sample/notifications/createWebhook.php
create mode 100644 tests/PayPal/Test/Functional/Api/WebhookFunctionalTest.php
create mode 100644 tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testCreate.json
create mode 100644 tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testDelete.json
create mode 100644 tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testEventResend.json
create mode 100644 tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testEventSearch.json
create mode 100644 tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testGet.json
create mode 100644 tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testGetAll.json
create mode 100644 tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testGetEvent.json
create mode 100644 tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testUpdate.json
create mode 100644 tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/webhook_get_available_event_types.json
create mode 100644 tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/webhook_get_subscribed_event_types.json
diff --git a/lib/PayPal/Api/WebhookEvent.php b/lib/PayPal/Api/WebhookEvent.php
index 44babde..cc69209 100644
--- a/lib/PayPal/Api/WebhookEvent.php
+++ b/lib/PayPal/Api/WebhookEvent.php
@@ -2,6 +2,7 @@
namespace PayPal\Api;
+use PayPal\Common\PPModel;
use PayPal\Common\ResourceModel;
use PayPal\Validation\ArgumentValidator;
use PayPal\Api\WebhookEventList;
@@ -218,7 +219,7 @@ class WebhookEvent extends ResourceModel
/**
* This contains the resource that is identified by resource_type element.
*
- * @param mixed $resource
+ * @param \PayPal\Common\PPModel $resource
*
* @return $this
*/
@@ -231,7 +232,7 @@ class WebhookEvent extends ResourceModel
/**
* This contains the resource that is identified by resource_type element.
*
- * @return mixed
+ * @return \PayPal\Common\PPModel
*/
public function getResource()
{
diff --git a/lib/PayPal/Api/WebhookEventType.php b/lib/PayPal/Api/WebhookEventType.php
index a3bf71a..c0287ff 100644
--- a/lib/PayPal/Api/WebhookEventType.php
+++ b/lib/PayPal/Api/WebhookEventType.php
@@ -72,7 +72,7 @@ class WebhookEventType extends ResourceModel
* @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
+ * @return WebhookEventTypeList
*/
public static function subscribedEventTypes($webhookId, $apiContext = null, $restCall = null)
{
@@ -86,7 +86,7 @@ class WebhookEventType extends ResourceModel
$apiContext,
$restCall
);
- $ret = new WebhookEventList();
+ $ret = new WebhookEventTypeList();
$ret->fromJson($json);
return $ret;
}
@@ -96,7 +96,7 @@ class WebhookEventType extends ResourceModel
*
* @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
+ * @return WebhookEventTypeList
*/
public static function availableEventTypes($apiContext = null, $restCall = null)
{
@@ -109,7 +109,7 @@ class WebhookEventType extends ResourceModel
$apiContext,
$restCall
);
- $ret = new WebhookEventList();
+ $ret = new WebhookEventTypeList();
$ret->fromJson($json);
return $ret;
}
diff --git a/lib/PayPal/Common/PPReflectionUtil.php b/lib/PayPal/Common/PPReflectionUtil.php
index 40c10ce..9222bf6 100644
--- a/lib/PayPal/Common/PPReflectionUtil.php
+++ b/lib/PayPal/Common/PPReflectionUtil.php
@@ -34,6 +34,10 @@ class PPReflectionUtil
*/
public static function getPropertyClass($class, $propertyName)
{
+ if ($class == get_class(new PPModel())) {
+ // Make it generic if PPModel is used for generating this
+ return get_class(new PPModel());
+ }
if (($annotations = self::propertyAnnotations($class, $propertyName)) && isset($annotations['return'])) {
$param = $annotations['return'];
diff --git a/sample/doc/assets/behavior.js b/sample/doc/assets/behavior.js
index b5c5960..7bad080 100644
--- a/sample/doc/assets/behavior.js
+++ b/sample/doc/assets/behavior.js
@@ -1235,6 +1235,62 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
"depth": 1,
"children": [
{
+ "type": "file",
+ "data": {
+ "language": {
+ "nameMatchers": [{}, ".fbp"],
+ "pygmentsLexer": "php",
+ "singleLineComment": ["//"],
+ "ignorePrefix": "}",
+ "foldPrefix": "^",
+ "name": "PHP"
+ },
+ "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/PayPal-PHP-SDK/sample/notifications/CreateWebhook.php",
+ "projectPath": "notifications/CreateWebhook.php",
+ "targetPath": "notifications/CreateWebhook",
+ "pageTitle": "notifications/CreateWebhook",
+ "title": "CreateWebhook"
+ },
+ "depth": 2,
+ "outline": [
+ {
+ "type": "heading",
+ "data": {
+ "level": 1,
+ "title": "Create Webhook Sample",
+ "slug": "create-webhook-sample"
+ },
+ "depth": 1
+ }, {
+ "type": "heading",
+ "data": {
+ "level": 1,
+ "title": "Basic Information",
+ "slug": "basic-information"
+ },
+ "depth": 1
+ }, {
+ "type": "heading",
+ "data": {
+ "level": 1,
+ "title": "Event Types",
+ "slug": "event-types"
+ },
+ "depth": 1,
+ "children": [
+ {
+ "type": "heading",
+ "data": {
+ "level": 3,
+ "title": "Create Webhook",
+ "slug": "create-webhook"
+ },
+ "depth": 3
+ }
+ ]
+ }
+ ]
+ }, {
"type": "file",
"data": {
"language": {
@@ -1639,62 +1695,6 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
]
}
]
- }, {
- "type": "file",
- "data": {
- "language": {
- "nameMatchers": [{}, ".fbp"],
- "pygmentsLexer": "php",
- "singleLineComment": ["//"],
- "ignorePrefix": "}",
- "foldPrefix": "^",
- "name": "PHP"
- },
- "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/PayPal-PHP-SDK/sample/notifications/createWebhook.php",
- "projectPath": "notifications/createWebhook.php",
- "targetPath": "notifications/createWebhook",
- "pageTitle": "notifications/createWebhook",
- "title": "createWebhook"
- },
- "depth": 2,
- "outline": [
- {
- "type": "heading",
- "data": {
- "level": 1,
- "title": "Create Webhook Sample",
- "slug": "create-webhook-sample"
- },
- "depth": 1
- }, {
- "type": "heading",
- "data": {
- "level": 1,
- "title": "Basic Information",
- "slug": "basic-information"
- },
- "depth": 1
- }, {
- "type": "heading",
- "data": {
- "level": 1,
- "title": "Event Types",
- "slug": "event-types"
- },
- "depth": 1,
- "children": [
- {
- "type": "heading",
- "data": {
- "level": 3,
- "title": "Create Webhook",
- "slug": "create-webhook"
- },
- "depth": 3
- }
- ]
- }
- ]
}
]
}, {
diff --git a/sample/doc/notifications/SearchWebhookEvents.html b/sample/doc/notifications/SearchWebhookEvents.html
index e446d18..6fafcca 100644
--- a/sample/doc/notifications/SearchWebhookEvents.html
+++ b/sample/doc/notifications/SearchWebhookEvents.html
@@ -5,15 +5,16 @@ API used: GET /v1/notifications/webhooks-events
PLEASE NOTE:
Creating webhook is sample purposes only. In real scenario, you dont need to create a new webhook everytime you want to search
for a webhook events. This is made in a sample just to make sure there is minimum of one webhook to listen to.
-$webhook = require 'CreateWebhook.php';
+$webhook = require __DIR__ . '/../bootstrap.php';
-$params = array();
try {
$output = \PayPal\Api\WebhookEvent::all($params, $apiContext);
} catch (Exception $ex) {
- ResultPrinter::printError("Search Webhook events", "WebhookEventList", null, $webhookId, $ex);
+ ResultPrinter::printError("Search Webhook events", "WebhookEventList", null, null, $ex);
exit(1);
}
-ResultPrinter::printResult("Search Webhook events", "WebhookEventList", $webhook->getId(), $params, $output);
+ResultPrinter::printResult("Search Webhook events", "WebhookEventList", null, $params, $output);
return $output;
Search Webhook events