From d6575b49aec2bcb6a7ccebe0baf9d7947825b4d9 Mon Sep 17 00:00:00 2001 From: japatel Date: Fri, 12 Dec 2014 16:32:16 -0600 Subject: [PATCH] Functional Tests Improvements and Refactoring - Updated Functional Tests to refactor common code in one file - Re-sets the credentials to make sure previous tests doesnt change it for testing --- sample/doc/assets/behavior.js | 471 ++++++++++++++++++ .../doc/notifications/DeleteAllWebhooks.html | 15 + sample/doc/notifications/DeleteWebhook.html | 14 + sample/doc/notifications/GetWebhook.html | 17 + .../ListSubscribedWebhookEventTypes.html | 16 + sample/doc/notifications/ListWebhooks.html | 16 + .../notifications/SearchWebhookEvents.html | 19 + sample/doc/notifications/UpdateWebhook.html | 43 ++ .../notifications/WebhookEventTypesList.html | 13 + sample/doc/notifications/createWebhook.html | 54 ++ sample/doc/payments/ExecutePayment.html | 12 + .../PayPal/Test/Api/WebhookEventTypeTest.php | 4 +- .../Api/BillingAgreementsFunctionalTest.php | 21 +- .../Api/BillingPlansFunctionalTest.php | 20 +- .../Functional/Api/InvoiceFunctionalTest.php | 18 +- .../Functional/Api/PaymentsFunctionalTest.php | 21 +- .../Api/WebProfileFunctionalTest.php | 18 +- tests/PayPal/Test/Functional/Setup.php | 49 ++ 18 files changed, 757 insertions(+), 84 deletions(-) create mode 100644 sample/doc/notifications/DeleteAllWebhooks.html create mode 100644 sample/doc/notifications/DeleteWebhook.html create mode 100644 sample/doc/notifications/GetWebhook.html create mode 100644 sample/doc/notifications/ListSubscribedWebhookEventTypes.html create mode 100644 sample/doc/notifications/ListWebhooks.html create mode 100644 sample/doc/notifications/SearchWebhookEvents.html create mode 100644 sample/doc/notifications/UpdateWebhook.html create mode 100644 sample/doc/notifications/WebhookEventTypesList.html create mode 100644 sample/doc/notifications/createWebhook.html create mode 100644 tests/PayPal/Test/Functional/Setup.php diff --git a/sample/doc/assets/behavior.js b/sample/doc/assets/behavior.js index 1047527..b5c5960 100644 --- a/sample/doc/assets/behavior.js +++ b/sample/doc/assets/behavior.js @@ -1226,6 +1226,477 @@ 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": "folder", + "data": { + "path": "notifications", + "title": "notifications" + }, + "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/DeleteAllWebhooks.php", + "projectPath": "notifications/DeleteAllWebhooks.php", + "targetPath": "notifications/DeleteAllWebhooks", + "pageTitle": "notifications/DeleteAllWebhooks", + "title": "DeleteAllWebhooks" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Delete All Webhook Sample", + "slug": "delete-all-webhook-sample" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 2, + "title": "Get Webhook Instance", + "slug": "get-webhook-instance" + }, + "depth": 2, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Delete Webhook", + "slug": "delete-webhook" + }, + "depth": 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/DeleteWebhook.php", + "projectPath": "notifications/DeleteWebhook.php", + "targetPath": "notifications/DeleteWebhook", + "pageTitle": "notifications/DeleteWebhook", + "title": "DeleteWebhook" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Delete Webhook Sample", + "slug": "delete-webhook-sample" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 2, + "title": "Get Webhook Instance", + "slug": "get-webhook-instance" + }, + "depth": 2, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Delete Webhook", + "slug": "delete-webhook" + }, + "depth": 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/GetWebhook.php", + "projectPath": "notifications/GetWebhook.php", + "targetPath": "notifications/GetWebhook", + "pageTitle": "notifications/GetWebhook", + "title": "GetWebhook" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Get Webhook Sample", + "slug": "get-webhook-sample" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 2, + "title": "Get Webhook ID.", + "slug": "get-webhook-id" + }, + "depth": 2, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Get Webhook", + "slug": "get-webhook" + }, + "depth": 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/ListSubscribedWebhookEventTypes.php", + "projectPath": "notifications/ListSubscribedWebhookEventTypes.php", + "targetPath": "notifications/ListSubscribedWebhookEventTypes", + "pageTitle": "notifications/ListSubscribedWebhookEventTypes", + "title": "ListSubscribedWebhookEventTypes" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Get Webhook Sample", + "slug": "get-webhook-sample" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 2, + "title": "List Subscribed Event Types", + "slug": "list-subscribed-event-types" + }, + "depth": 2, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Get List of Subscribed Event Types", + "slug": "get-list-of-subscribed-event-types" + }, + "depth": 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/ListWebhooks.php", + "projectPath": "notifications/ListWebhooks.php", + "targetPath": "notifications/ListWebhooks", + "pageTitle": "notifications/ListWebhooks", + "title": "ListWebhooks" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Get All Webhooks Sample", + "slug": "get-all-webhooks-sample" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 2, + "title": "List Webhooks", + "slug": "list-webhooks" + }, + "depth": 2, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Get List of All Webhooks", + "slug": "get-list-of-all-webhooks" + }, + "depth": 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/SearchWebhookEvents.php", + "projectPath": "notifications/SearchWebhookEvents.php", + "targetPath": "notifications/SearchWebhookEvents", + "pageTitle": "notifications/SearchWebhookEvents", + "title": "SearchWebhookEvents" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Search Webhook Events Sample", + "slug": "search-webhook-events-sample" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 2, + "title": "Get Webhook Instance", + "slug": "get-webhook-instance" + }, + "depth": 2 + }, { + "type": "heading", + "data": { + "level": 2, + "title": "PLEASE NOTE:", + "slug": "please-note" + }, + "depth": 2, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Search Webhook events", + "slug": "search-webhook-events" + }, + "depth": 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/UpdateWebhook.php", + "projectPath": "notifications/UpdateWebhook.php", + "targetPath": "notifications/UpdateWebhook", + "pageTitle": "notifications/UpdateWebhook", + "title": "UpdateWebhook" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Update Webhook Sample", + "slug": "update-webhook-sample" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 2, + "title": "Get Webhook ID.", + "slug": "get-webhook-id" + }, + "depth": 2, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Get Webhook", + "slug": "get-webhook" + }, + "depth": 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/WebhookEventTypesList.php", + "projectPath": "notifications/WebhookEventTypesList.php", + "targetPath": "notifications/WebhookEventTypesList", + "pageTitle": "notifications/WebhookEventTypesList", + "title": "WebhookEventTypesList" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Get Reference List of all Webhook Event Types", + "slug": "get-reference-list-of-all-webhook-event-types" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Get List of all Webhook event types", + "slug": "get-list-of-all-webhook-event-types" + }, + "depth": 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 + } + ] + } + ] + } + ] }, { "type": "folder", "data": { diff --git a/sample/doc/notifications/DeleteAllWebhooks.html b/sample/doc/notifications/DeleteAllWebhooks.html new file mode 100644 index 0000000..ae3732c --- /dev/null +++ b/sample/doc/notifications/DeleteAllWebhooks.html @@ -0,0 +1,15 @@ +notifications/DeleteAllWebhooks
notifications/DeleteAllWebhooks.php
<?php

Delete All Webhook Sample

+

This is a sample helper method, to delete all existing webhooks, because of limited number of webhooks that are allowed per app. +To properly use the sample, change the clientId and Secret from bootstrap.php file with your own app ClientId and Secret.

Get Webhook Instance

/** @var \PayPal\Api\WebhookList $webhookList */ +$webhookList = require 'ListWebhooks.php';

Delete Webhook

try { + foreach ($webhookList->getWebhooks() as $webhook) { + $webhook->delete($apiContext); + } +} catch (Exception $ex) { + ResultPrinter::printError("Deleted all Webhooks", "WebhookList", null, null, $ex); + exit(1); +} + +ResultPrinter::printResult("Delete all Webhook, as it may have exceed the maximum count.", "WebhookList", null, null, null); + +return $output;
\ No newline at end of file diff --git a/sample/doc/notifications/DeleteWebhook.html b/sample/doc/notifications/DeleteWebhook.html new file mode 100644 index 0000000..58a5568 --- /dev/null +++ b/sample/doc/notifications/DeleteWebhook.html @@ -0,0 +1,14 @@ +notifications/DeleteWebhook
notifications/DeleteWebhook.php
<?php

Delete Webhook Sample

+

This sample code demonstrate how to use this call to search for all webhook events., as documented here at: +https://developer.paypal.com/docs/api/#delete-a-webhook +API used: DELETE v1/notifications/webhooks/

Get Webhook Instance

/** @var \PayPal\Api\Webhook $webhook */ +$webhook = require 'CreateWebhook.php';

Delete Webhook

try { + $output = $webhook->delete($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Delete a Webhook", "Webhook", null, $webhookId, $ex); + exit(1); +} + +ResultPrinter::printResult("Delete a Webhook", "Webhook", $webhook->getId(), null, null); + +return $output;
\ No newline at end of file diff --git a/sample/doc/notifications/GetWebhook.html b/sample/doc/notifications/GetWebhook.html new file mode 100644 index 0000000..effe762 --- /dev/null +++ b/sample/doc/notifications/GetWebhook.html @@ -0,0 +1,17 @@ +notifications/GetWebhook
notifications/GetWebhook.php
<?php

Get Webhook Sample

+

This sample code demonstrate how you can get a webhook, as documented here at: +https://developer.paypal.com/webapps/developer/docs/api/#get-a-webhook +API used: GET /v1/notifications/webhooks/

Get Webhook ID.

+

In samples we are using CreateWebhook.php sample to get the created instance of webhook. +However, in real case scenario, we could use just the ID from database or retrieved from the form.

/** @var \PayPal\Api\Webhook $webhook */ +$webhook = require 'CreateWebhook.php'; +$webhookId = $webhook->getId();

Get Webhook

try { + $output = \PayPal\Api\Webhook::get($webhookId, $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Get a Webhook", "Webhook", null, $webhookId, $ex); + exit(1); +} + +ResultPrinter::printResult("Get a Webhook", "Webhook", $output->getId(), null, $output); + +return $output;
\ No newline at end of file diff --git a/sample/doc/notifications/ListSubscribedWebhookEventTypes.html b/sample/doc/notifications/ListSubscribedWebhookEventTypes.html new file mode 100644 index 0000000..85262c9 --- /dev/null +++ b/sample/doc/notifications/ListSubscribedWebhookEventTypes.html @@ -0,0 +1,16 @@ +notifications/ListSubscribedWebhookEventTypes
notifications/ListSubscribedWebhookEventTypes.php
<?php

Get Webhook Sample

+

This sample code demonstrate how you can get a webhook, as documented here at: +https://developer.paypal.com/webapps/developer/docs/api/#get-a-webhook +API used: GET /v1/notifications/webhooks/

List Subscribed Event Types

+

Use this call to retrieve the list of events types that are subscribed to a webhook.

/** @var \PayPal\Api\Webhook $webhook */ +$webhook = require 'CreateWebhook.php'; +$webhookId = $webhook->getId();

Get List of Subscribed Event Types

try { + $output = \PayPal\Api\WebhookEventType::subscribedEventTypes($webhookId, $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("List subscribed webhook event types", "WebhookEventTypeList", null, $webhookId, $ex); + exit(1); +} + +ResultPrinter::printResult("List subscribed webhook event types", "WebhookEventTypeList",null, null, $output); + +return $output;
\ No newline at end of file diff --git a/sample/doc/notifications/ListWebhooks.html b/sample/doc/notifications/ListWebhooks.html new file mode 100644 index 0000000..a001b39 --- /dev/null +++ b/sample/doc/notifications/ListWebhooks.html @@ -0,0 +1,16 @@ +notifications/ListWebhooks
notifications/ListWebhooks.php
<?php

Get All Webhooks Sample

+

Use this call to list all the webhooks, as documented here at: +https://developer.paypal.com/webapps/developer/docs/api/#list-all-webhooks +API used: GET /v1/notifications/webhooks

List Webhooks

This step is not necessarily required. We are creating a webhook for sample purpose only, so that we would not +get an empty list at any point. +In real case, you dont need to create any webhook to make this API call.

/** @var \PayPal\Api\Webhook $webhook */ +$webhook = require_once __DIR__ . '/../bootstrap.php';

Get List of All Webhooks

try { + $output = \PayPal\Api\Webhook::getAll($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("List all webhooks", "WebhookList", null, $webhookId, $ex); + exit(1); +} + +ResultPrinter::printResult("List all webhooks", "WebhookList",null, null, $output); + +return $output;
\ No newline at end of file diff --git a/sample/doc/notifications/SearchWebhookEvents.html b/sample/doc/notifications/SearchWebhookEvents.html new file mode 100644 index 0000000..e446d18 --- /dev/null +++ b/sample/doc/notifications/SearchWebhookEvents.html @@ -0,0 +1,19 @@ +notifications/SearchWebhookEvents
notifications/SearchWebhookEvents.php
<?php

Search Webhook Events Sample

+

This sample code demonstrate how to use this call to search for all webhook events., as documented here at: +https://developer.paypal.com/docs/api/#search-webhook-events +API used: GET /v1/notifications/webhooks-events

Get Webhook Instance

+

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.

/** @var \PayPal\Api\Webhook $webhook */ +$webhook = require 'CreateWebhook.php'; + +$params = array();

Search Webhook events

try { + $output = \PayPal\Api\WebhookEvent::all($params, $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Search Webhook events", "WebhookEventList", null, $webhookId, $ex); + exit(1); +} + +ResultPrinter::printResult("Search Webhook events", "WebhookEventList", $webhook->getId(), $params, $output); + +return $output;
\ No newline at end of file diff --git a/sample/doc/notifications/UpdateWebhook.html b/sample/doc/notifications/UpdateWebhook.html new file mode 100644 index 0000000..cd52035 --- /dev/null +++ b/sample/doc/notifications/UpdateWebhook.html @@ -0,0 +1,43 @@ +notifications/UpdateWebhook
notifications/UpdateWebhook.php
<?php

Update Webhook Sample

+

This sample code demonstrate how to use this call to update a webhook; supports the replace operation only, as documented here at: +https://developer.paypal.com/webapps/developer/docs/api/#update-a-webhook +API used: PATCH v1/notifications/webhooks/

Get Webhook ID.

+

In samples we are using CreateWebhook.php sample to get the created instance of webhook. +However, in real case scenario, we could use just the ID from database or use an already existing webhook.

/** @var \PayPal\Api\Webhook $webhook */ +$webhook = require 'CreateWebhook.php';

Updating the webhook as per given request + [ + { + "op":"replace", + "path":"/url", + "value":"https://requestb.in/10ujt3c1" + }, + { + "op":"replace", + "path":"/event_types", + "value":[ + { + "name":"PAYMENT.SALE.REFUNDED" + } + ] + } + ]

$patch = new \PayPal\Api\Patch(); +$patch->setOp("replace") + ->setPath("/url") + ->setValue("https://requestb.in/10ujt3c1?uniqid=". uniqid()); + +$patch2 = new \PayPal\Api\Patch(); +$patch2->setOp("replace") + ->setPath("/event_types") + ->setValue(json_decode('[{"name":"PAYMENT.SALE.REFUNDED"}]')); + +$patchRequest = new \PayPal\Api\PatchRequest(); +$patchRequest->addPatch($patch)->addPatch($patch2);

Get Webhook

try { + $output = $webhook->update($patchRequest, $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Updated a Webhook", "Webhook", null, $patchRequest, $ex); + exit(1); +} + +ResultPrinter::printResult("Updated a Webhook", "Webhook", $output->getId(), $patchRequest, $output); + +return $output;
\ No newline at end of file diff --git a/sample/doc/notifications/WebhookEventTypesList.html b/sample/doc/notifications/WebhookEventTypesList.html new file mode 100644 index 0000000..554a027 --- /dev/null +++ b/sample/doc/notifications/WebhookEventTypesList.html @@ -0,0 +1,13 @@ +notifications/WebhookEventTypesList
notifications/WebhookEventTypesList.php
<?php

Get Reference List of all Webhook Event Types

+

This sample code demonstrate how you can get reference list of all webhook event types, as documented here at: +https://developer.paypal.com/webapps/developer/docs/api/#get-a-reference-list-of-webhook-event-types +API used: GET /v1/notifications/webhooks-event-types

$apiContext = require __DIR__ . '/../bootstrap.php';

Get List of all Webhook event types

try { + $output = \PayPal\Api\WebhookEventType::availableEventTypes($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Get List of All Webhook Event Types", "WebhookEventTypeList", null, null, $ex); + exit(1); +} + +ResultPrinter::printResult("Get List of All Webhook Event Types", "WebhookEventTypeList", null, null, $output); + +return $output;
\ No newline at end of file diff --git a/sample/doc/notifications/createWebhook.html b/sample/doc/notifications/createWebhook.html new file mode 100644 index 0000000..16fcb90 --- /dev/null +++ b/sample/doc/notifications/createWebhook.html @@ -0,0 +1,54 @@ +notifications/createWebhook
notifications/createWebhook.php
<?php

Create Webhook Sample

+

This sample code demonstrate how you can create a webhook, as documented here at: +https://developer.paypal.com/webapps/developer/docs/api/#create-a-webhook +API used: POST /v1/notifications/webhooks

require __DIR__ . '/../bootstrap.php';

Create a new instance of Webhook object

$webhook = new \PayPal\Api\Webhook();

Basic Information

+
{
+    "url":"https://requestb.in/10ujt3c1",
+    "event_types":[
+       {
+           "name":"PAYMENT.AUTHORIZATION.CREATED"
+       },
+       {
+           "name":"PAYMENT.AUTHORIZATION.VOIDED"
+       }
+    ]
+ }
+

Fill up the basic information that is required for the webhook +The URL should be actually accessible over the internet. Having a localhost here would not work.

$webhook->setUrl("https://requestb.in/10ujt3c1?uniqid=" . uniqid());

Event Types

+

Event types correspond to what kind of notifications you want to receive on the given URL.

$webhookEventTypes = array(); +$webhookEventTypes[] = new \PayPal\Api\WebhookEventType( + '{ + "name":"PAYMENT.AUTHORIZATION.CREATED" + }' +); +$webhookEventTypes[] = new \PayPal\Api\WebhookEventType( + '{ + "name":"PAYMENT.AUTHORIZATION.VOIDED" + }' +); +$webhook->setEventTypes($webhookEventTypes);

For Sample Purposes Only.

$request = clone $webhook;

Create Webhook

try { + $output = $webhook->create($apiContext); +} catch (Exception $ex) {
// Ignore workflow code segment
// Ignore workflow code segment + if ($ex instanceof \PayPal\Exception\PPConnectionException) { + $data = $ex->getData(); + ResultPrinter::printError("Created Webhook Failed. Checking if it is Webhook Number Limit Exceeded. Trying to delete all existing webhooks", "Webhook", "Please Use <a style='color: red;' href='DeleteAllWebhooks.php' >Delete All Webhooks</a> Sample to delete all existing webhooks in sample", $request, $ex); + if (strpos($data,'WEBHOOK_NUMBER_LIMIT_EXCEEDED') !== false) { + require 'DeleteAllWebhooks.php'; + try { + $output = $webhook->create($apiContext); + } catch (Exception $ex) { + ResultPrinter::printError("Created Webhook", "Webhook", null, $request, $ex); + exit(1); + } + } else { + ResultPrinter::printError("Created Webhook", "Webhook", null, $request, $ex); + exit(1); + } + } else { + ResultPrinter::printError("Created Webhook", "Webhook", null, $request, $ex); + exit(1); + }

Print Success Result

} + +ResultPrinter::printResult("Created Webhook", "Webhook", $output->getId(), $request, $output); + +return $output;
\ No newline at end of file diff --git a/sample/doc/payments/ExecutePayment.html b/sample/doc/payments/ExecutePayment.html index 9693d74..ba7c7e5 100644 --- a/sample/doc/payments/ExecutePayment.html +++ b/sample/doc/payments/ExecutePayment.html @@ -24,6 +24,18 @@ when the user is redirected from paypal back to your site

"Executed Payment", "Payment", $payment->getId(), $execution, $result); + try { + $payment = Payment::get($paymentId, $apiContext); + } catch (Exception $ex) { + ResultPrinter::printError("Get Payment", "Payment", null, null, $ex); + exit(1); + } + + ResultPrinter::printResult("Get Payment", "Payment", $payment->getId(), null, $payment); + + return $payment; + + } else { ResultPrinter::printResult("User Cancelled the Approval", null); }
\ No newline at end of file diff --git a/tests/PayPal/Test/Api/WebhookEventTypeTest.php b/tests/PayPal/Test/Api/WebhookEventTypeTest.php index 8144df7..c311f48 100644 --- a/tests/PayPal/Test/Api/WebhookEventTypeTest.php +++ b/tests/PayPal/Test/Api/WebhookEventTypeTest.php @@ -93,7 +93,7 @@ class WebhookEventTypeTest extends \PHPUnit_Framework_TestCase $mockPPRestCall->expects($this->any()) ->method('execute') ->will($this->returnValue( - WebhookEventListTest::getJson() + WebhookEventTypeListTest::getJson() )); $result = $obj->subscribedEventTypes("webhookId", $mockApiContext, $mockPPRestCall); @@ -112,7 +112,7 @@ class WebhookEventTypeTest extends \PHPUnit_Framework_TestCase $mockPPRestCall->expects($this->any()) ->method('execute') ->will($this->returnValue( - WebhookEventListTest::getJson() + WebhookEventTypeListTest::getJson() )); $result = $obj->availableEventTypes($mockApiContext, $mockPPRestCall); diff --git a/tests/PayPal/Test/Functional/Api/BillingAgreementsFunctionalTest.php b/tests/PayPal/Test/Functional/Api/BillingAgreementsFunctionalTest.php index 42fb0b6..15a1106 100644 --- a/tests/PayPal/Test/Functional/Api/BillingAgreementsFunctionalTest.php +++ b/tests/PayPal/Test/Functional/Api/BillingAgreementsFunctionalTest.php @@ -12,6 +12,7 @@ use PayPal\Common\PPModel; use PayPal\Rest\ApiContext; use PayPal\Rest\IResource; use PayPal\Api\CreateProfileResponse; +use PayPal\Test\Functional\Setup; use PayPal\Transport\PPRestCall; use PayPal\Api\WebProfile; @@ -27,8 +28,6 @@ class BillingAgreementsFunctionalTest extends \PHPUnit_Framework_TestCase public $response; - public $mode = 'mock'; - public $mockPPRestCall; public function setUp() @@ -46,21 +45,7 @@ class BillingAgreementsFunctionalTest extends \PHPUnit_Framework_TestCase if (array_key_exists('body', $this->operation['response'])) { $this->response = json_encode($this->operation['response']['body']); } - - $this->mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock'; - if ($this->mode != 'sandbox') { - - // Mock PPRest Caller if mode set to mock - $this->mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') - ->disableOriginalConstructor() - ->getMock(); - - $this->mockPPRestCall->expects($this->any()) - ->method('execute') - ->will($this->returnValue( - $this->response - )); - } + Setup::SetUpForFunctionalTests($this); } /** @@ -94,7 +79,7 @@ class BillingAgreementsFunctionalTest extends \PHPUnit_Framework_TestCase */ public function testExecute($agreement) { - if ($this->mode == 'sandbox') { + if (Setup::$mode == 'sandbox') { $this->markTestSkipped('Not executable on sandbox environment. Needs human interaction'); } $links = $agreement->getLinks(); diff --git a/tests/PayPal/Test/Functional/Api/BillingPlansFunctionalTest.php b/tests/PayPal/Test/Functional/Api/BillingPlansFunctionalTest.php index 0accf6f..a3276f0 100644 --- a/tests/PayPal/Test/Functional/Api/BillingPlansFunctionalTest.php +++ b/tests/PayPal/Test/Functional/Api/BillingPlansFunctionalTest.php @@ -5,10 +5,13 @@ namespace PayPal\Test\Functional\Api; use PayPal\Api\Patch; use PayPal\Api\PatchRequest; use PayPal\Api\Plan; +use PayPal\Auth\OAuthTokenCredential; use PayPal\Common\PPModel; +use PayPal\Core\PPCredentialManager; use PayPal\Rest\ApiContext; use PayPal\Rest\IResource; use PayPal\Api\CreateProfileResponse; +use PayPal\Test\Functional\Setup; use PayPal\Transport\PPRestCall; use PayPal\Api\WebProfile; @@ -30,6 +33,8 @@ class BillingPlansFunctionalTest extends \PHPUnit_Framework_TestCase public $mockPPRestCall; + public $context; + public function setUp() { $className = $this->getClassName(); @@ -46,20 +51,7 @@ class BillingPlansFunctionalTest extends \PHPUnit_Framework_TestCase $this->response = json_encode($this->operation['response']['body']); } - $this->mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock'; - if ($this->mode != 'sandbox') { - - // Mock PPRest Caller if mode set to mock - $this->mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') - ->disableOriginalConstructor() - ->getMock(); - - $this->mockPPRestCall->expects($this->any()) - ->method('execute') - ->will($this->returnValue( - $this->response - )); - } + Setup::SetUpForFunctionalTests($this); } /** diff --git a/tests/PayPal/Test/Functional/Api/InvoiceFunctionalTest.php b/tests/PayPal/Test/Functional/Api/InvoiceFunctionalTest.php index 27df9d5..05fd99d 100644 --- a/tests/PayPal/Test/Functional/Api/InvoiceFunctionalTest.php +++ b/tests/PayPal/Test/Functional/Api/InvoiceFunctionalTest.php @@ -7,6 +7,7 @@ use PayPal\Api\Notification; use PayPal\Api\PaymentDetail; use PayPal\Api\RefundDetail; use PayPal\Api\Search; +use PayPal\Test\Functional\Setup; /** * Class Invoice @@ -22,8 +23,6 @@ class InvoiceFunctionalTest extends \PHPUnit_Framework_TestCase public $response; - public $mode = 'mock'; - public $mockPPRestCall; public function setUp() @@ -42,20 +41,7 @@ class InvoiceFunctionalTest extends \PHPUnit_Framework_TestCase $this->response = json_encode($this->operation['response']['body']); } - $this->mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock'; - if ($this->mode != 'sandbox') { - - // Mock PPRest Caller if mode set to mock - $this->mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') - ->disableOriginalConstructor() - ->getMock(); - - $this->mockPPRestCall->expects($this->any()) - ->method('execute') - ->will($this->returnValue( - $this->response - )); - } + Setup::SetUpForFunctionalTests($this); } diff --git a/tests/PayPal/Test/Functional/Api/PaymentsFunctionalTest.php b/tests/PayPal/Test/Functional/Api/PaymentsFunctionalTest.php index ef82c23..09abb58 100644 --- a/tests/PayPal/Test/Functional/Api/PaymentsFunctionalTest.php +++ b/tests/PayPal/Test/Functional/Api/PaymentsFunctionalTest.php @@ -13,6 +13,7 @@ use PayPal\Common\PPModel; use PayPal\Rest\ApiContext; use PayPal\Rest\IResource; use PayPal\Api\CreateProfileResponse; +use PayPal\Test\Functional\Setup; use PayPal\Transport\PPRestCall; use PayPal\Api\WebProfile; @@ -28,8 +29,6 @@ class PaymentsFunctionalTest extends \PHPUnit_Framework_TestCase public $response; - public $mode = 'mock'; - public $mockPPRestCall; public function setUp() @@ -42,21 +41,7 @@ class PaymentsFunctionalTest extends \PHPUnit_Framework_TestCase if (array_key_exists('body', $this->operation['response'])) { $this->response = json_encode($this->operation['response']['body']); } - - $this->mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock'; - if ($this->mode != 'sandbox') { - - // Mock PPRest Caller if mode set to mock - $this->mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') - ->disableOriginalConstructor() - ->getMock(); - - $this->mockPPRestCall->expects($this->any()) - ->method('execute') - ->will($this->returnValue( - $this->response - )); - } + Setup::SetUpForFunctionalTests($this); } /** @@ -139,7 +124,7 @@ class PaymentsFunctionalTest extends \PHPUnit_Framework_TestCase */ public function testExecute($payment) { - if ($this->mode == 'sandbox') { + if (Setup::$mode == 'sandbox') { $this->markTestSkipped('Not executable on sandbox environment. Needs human interaction'); } } diff --git a/tests/PayPal/Test/Functional/Api/WebProfileFunctionalTest.php b/tests/PayPal/Test/Functional/Api/WebProfileFunctionalTest.php index 6424fc6..c19ce5a 100644 --- a/tests/PayPal/Test/Functional/Api/WebProfileFunctionalTest.php +++ b/tests/PayPal/Test/Functional/Api/WebProfileFunctionalTest.php @@ -7,6 +7,7 @@ use PayPal\Common\PPModel; use PayPal\Rest\ApiContext; use PayPal\Rest\IResource; use PayPal\Api\CreateProfileResponse; +use PayPal\Test\Functional\Setup; use PayPal\Transport\PPRestCall; use PayPal\Api\WebProfile; @@ -22,8 +23,6 @@ class WebProfileFunctionalTest extends \PHPUnit_Framework_TestCase public $response; - public $mode = 'mock'; - public $mockPPRestCall; public function setUp() @@ -37,20 +36,7 @@ class WebProfileFunctionalTest extends \PHPUnit_Framework_TestCase $this->response = json_encode($this->operation['response']['body']); } - $this->mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock'; - if ($this->mode != 'sandbox') { - - // Mock PPRest Caller if mode set to mock - $this->mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') - ->disableOriginalConstructor() - ->getMock(); - - $this->mockPPRestCall->expects($this->any()) - ->method('execute') - ->will($this->returnValue( - $this->response - )); - } + Setup::SetUpForFunctionalTests($this); } /** diff --git a/tests/PayPal/Test/Functional/Setup.php b/tests/PayPal/Test/Functional/Setup.php new file mode 100644 index 0000000..1dd21ad --- /dev/null +++ b/tests/PayPal/Test/Functional/Setup.php @@ -0,0 +1,49 @@ +setConfig(array( + 'mode' => 'sandbox', + 'acct1.ClientId' => 'AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS', + 'acct1.ClientSecret' => 'EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL', + 'http.ConnectionTimeOut' => 30, + 'log.LogEnabled' => true, + 'log.FileName' => '../PayPal.log', + 'log.LogLevel' => 'FINE', + 'validation.level' => 'warning' + )); + PPCredentialManager::getInstance()->setCredentialObject( + new OAuthTokenCredential( + "AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS", + "EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL" + ) + ); + + self::$mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock'; + if (self::$mode != 'sandbox') { + + // Mock PPRest Caller if mode set to mock + $test->mockPPRestCall = $test->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $test->mockPPRestCall->expects($test->any()) + ->method('execute') + ->will($test->returnValue( + $test->response + )); + } + } +}