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
This commit is contained in:
japatel
2014-12-12 16:32:16 -06:00
parent 4c52592709
commit d6575b49ae
18 changed files with 757 additions and 84 deletions

View File

@@ -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": {

View File

@@ -0,0 +1,15 @@
<!DOCTYPE html><html lang="en"><head><title>notifications/DeleteAllWebhooks</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="notifications/DeleteAllWebhooks"><meta name="groc-project-path" content="notifications/DeleteAllWebhooks.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">notifications/DeleteAllWebhooks.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="delete-all-webhook-sample">Delete All Webhook Sample</h1>
<p>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.</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h2 id="get-webhook-instance">Get Webhook Instance</h2></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> \PayPal\Api\WebhookList $webhookList */</span>
<span class="hljs-variable">$webhookList</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'ListWebhooks.php'</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="delete-webhook">Delete Webhook</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
<span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$webhookList</span>-&gt;getWebhooks() <span class="hljs-keyword">as</span> <span class="hljs-variable">$webhook</span>) {
<span class="hljs-variable">$webhook</span>-&gt;delete(<span class="hljs-variable">$apiContext</span>);
}
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
ResultPrinter::printError(<span class="hljs-string">"Deleted all Webhooks"</span>, <span class="hljs-string">"WebhookList"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}
ResultPrinter::printResult(<span class="hljs-string">"Delete all Webhook, as it may have exceed the maximum count."</span>, <span class="hljs-string">"WebhookList"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$output</span>;</div></div></div></div></body></html>

View File

@@ -0,0 +1,14 @@
<!DOCTYPE html><html lang="en"><head><title>notifications/DeleteWebhook</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="notifications/DeleteWebhook"><meta name="groc-project-path" content="notifications/DeleteWebhook.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">notifications/DeleteWebhook.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="delete-webhook-sample">Delete Webhook Sample</h1>
<p>This sample code demonstrate how to use this call to search for all webhook events., as documented here at:
<a href="https://developer.paypal.com/docs/api/#delete-a-webhook">https://developer.paypal.com/docs/api/#delete-a-webhook</a>
API used: DELETE v1/notifications/webhooks/<Webhook-Id></p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h2 id="get-webhook-instance">Get Webhook Instance</h2></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> \PayPal\Api\Webhook $webhook */</span>
<span class="hljs-variable">$webhook</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateWebhook.php'</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="delete-webhook">Delete Webhook</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
<span class="hljs-variable">$output</span> = <span class="hljs-variable">$webhook</span>-&gt;delete(<span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
ResultPrinter::printError(<span class="hljs-string">"Delete a Webhook"</span>, <span class="hljs-string">"Webhook"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$webhookId</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}
ResultPrinter::printResult(<span class="hljs-string">"Delete a Webhook"</span>, <span class="hljs-string">"Webhook"</span>, <span class="hljs-variable">$webhook</span>-&gt;getId(), <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$output</span>;</div></div></div></div></body></html>

View File

@@ -0,0 +1,17 @@
<!DOCTYPE html><html lang="en"><head><title>notifications/GetWebhook</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="notifications/GetWebhook"><meta name="groc-project-path" content="notifications/GetWebhook.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">notifications/GetWebhook.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="get-webhook-sample">Get Webhook Sample</h1>
<p>This sample code demonstrate how you can get a webhook, as documented here at:
<a href="https://developer.paypal.com/webapps/developer/docs/api/#get-a-webhook">https://developer.paypal.com/webapps/developer/docs/api/#get-a-webhook</a>
API used: GET /v1/notifications/webhooks/<Webhook-Id></p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h2 id="get-webhook-id">Get Webhook ID.</h2>
<p>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.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> \PayPal\Api\Webhook $webhook */</span>
<span class="hljs-variable">$webhook</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateWebhook.php'</span>;
<span class="hljs-variable">$webhookId</span> = <span class="hljs-variable">$webhook</span>-&gt;getId();</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="get-webhook">Get Webhook</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
<span class="hljs-variable">$output</span> = \PayPal\Api\Webhook::get(<span class="hljs-variable">$webhookId</span>, <span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
ResultPrinter::printError(<span class="hljs-string">"Get a Webhook"</span>, <span class="hljs-string">"Webhook"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$webhookId</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}
ResultPrinter::printResult(<span class="hljs-string">"Get a Webhook"</span>, <span class="hljs-string">"Webhook"</span>, <span class="hljs-variable">$output</span>-&gt;getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$output</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$output</span>;</div></div></div></div></body></html>

View File

@@ -0,0 +1,16 @@
<!DOCTYPE html><html lang="en"><head><title>notifications/ListSubscribedWebhookEventTypes</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="notifications/ListSubscribedWebhookEventTypes"><meta name="groc-project-path" content="notifications/ListSubscribedWebhookEventTypes.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">notifications/ListSubscribedWebhookEventTypes.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="get-webhook-sample">Get Webhook Sample</h1>
<p>This sample code demonstrate how you can get a webhook, as documented here at:
<a href="https://developer.paypal.com/webapps/developer/docs/api/#get-a-webhook">https://developer.paypal.com/webapps/developer/docs/api/#get-a-webhook</a>
API used: GET /v1/notifications/webhooks/<Webhook-Id></p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h2 id="list-subscribed-event-types">List Subscribed Event Types</h2>
<p>Use this call to retrieve the list of events types that are subscribed to a webhook.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> \PayPal\Api\Webhook $webhook */</span>
<span class="hljs-variable">$webhook</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateWebhook.php'</span>;
<span class="hljs-variable">$webhookId</span> = <span class="hljs-variable">$webhook</span>-&gt;getId();</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="get-list-of-subscribed-event-types">Get List of Subscribed Event Types</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
<span class="hljs-variable">$output</span> = \PayPal\Api\WebhookEventType::subscribedEventTypes(<span class="hljs-variable">$webhookId</span>, <span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
ResultPrinter::printError(<span class="hljs-string">"List subscribed webhook event types"</span>, <span class="hljs-string">"WebhookEventTypeList"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$webhookId</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}
ResultPrinter::printResult(<span class="hljs-string">"List subscribed webhook event types"</span>, <span class="hljs-string">"WebhookEventTypeList"</span>,<span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$output</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$output</span>;</div></div></div></div></body></html>

View File

@@ -0,0 +1,16 @@
<!DOCTYPE html><html lang="en"><head><title>notifications/ListWebhooks</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="notifications/ListWebhooks"><meta name="groc-project-path" content="notifications/ListWebhooks.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">notifications/ListWebhooks.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="get-all-webhooks-sample">Get All Webhooks Sample</h1>
<p>Use this call to list all the webhooks, as documented here at:
<a href="https://developer.paypal.com/webapps/developer/docs/api/#list-all-webhooks">https://developer.paypal.com/webapps/developer/docs/api/#list-all-webhooks</a>
API used: GET /v1/notifications/webhooks</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h2 id="list-webhooks">List Webhooks</h2></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>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.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> \PayPal\Api\Webhook $webhook */</span>
<span class="hljs-variable">$webhook</span> = <span class="hljs-keyword">require_once</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="get-list-of-all-webhooks">Get List of All Webhooks</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
<span class="hljs-variable">$output</span> = \PayPal\Api\Webhook::getAll(<span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
ResultPrinter::printError(<span class="hljs-string">"List all webhooks"</span>, <span class="hljs-string">"WebhookList"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$webhookId</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}
ResultPrinter::printResult(<span class="hljs-string">"List all webhooks"</span>, <span class="hljs-string">"WebhookList"</span>,<span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$output</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$output</span>;</div></div></div></div></body></html>

View File

@@ -0,0 +1,19 @@
<!DOCTYPE html><html lang="en"><head><title>notifications/SearchWebhookEvents</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="notifications/SearchWebhookEvents"><meta name="groc-project-path" content="notifications/SearchWebhookEvents.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">notifications/SearchWebhookEvents.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="search-webhook-events-sample">Search Webhook Events Sample</h1>
<p>This sample code demonstrate how to use this call to search for all webhook events., as documented here at:
<a href="https://developer.paypal.com/docs/api/#search-webhook-events">https://developer.paypal.com/docs/api/#search-webhook-events</a>
API used: GET /v1/notifications/webhooks-events</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h2 id="get-webhook-instance">Get Webhook Instance</h2>
<h2 id="please-note">PLEASE NOTE:</h2>
<p>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.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> \PayPal\Api\Webhook $webhook */</span>
<span class="hljs-variable">$webhook</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateWebhook.php'</span>;
<span class="hljs-variable">$params</span> = <span class="hljs-keyword">array</span>();</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="search-webhook-events">Search Webhook events</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
<span class="hljs-variable">$output</span> = \PayPal\Api\WebhookEvent::all(<span class="hljs-variable">$params</span>, <span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
ResultPrinter::printError(<span class="hljs-string">"Search Webhook events"</span>, <span class="hljs-string">"WebhookEventList"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$webhookId</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}
ResultPrinter::printResult(<span class="hljs-string">"Search Webhook events"</span>, <span class="hljs-string">"WebhookEventList"</span>, <span class="hljs-variable">$webhook</span>-&gt;getId(), <span class="hljs-variable">$params</span>, <span class="hljs-variable">$output</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$output</span>;</div></div></div></div></body></html>

View File

@@ -0,0 +1,43 @@
<!DOCTYPE html><html lang="en"><head><title>notifications/UpdateWebhook</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="notifications/UpdateWebhook"><meta name="groc-project-path" content="notifications/UpdateWebhook.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">notifications/UpdateWebhook.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="update-webhook-sample">Update Webhook Sample</h1>
<p>This sample code demonstrate how to use this call to update a webhook; supports the replace operation only, as documented here at:
<a href="https://developer.paypal.com/webapps/developer/docs/api/#update-a-webhook">https://developer.paypal.com/webapps/developer/docs/api/#update-a-webhook</a>
API used: PATCH v1/notifications/webhooks/<Webhook-Id></p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h2 id="get-webhook-id">Get Webhook ID.</h2>
<p>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.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> \PayPal\Api\Webhook $webhook */</span>
<span class="hljs-variable">$webhook</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateWebhook.php'</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Updating the webhook as per given request
[
{
&quot;op&quot;:&quot;replace&quot;,
&quot;path&quot;:&quot;/url&quot;,
&quot;value&quot;:&quot;<a href="https://requestb.in/10ujt3c1">https://requestb.in/10ujt3c1</a>&quot;
},
{
&quot;op&quot;:&quot;replace&quot;,
&quot;path&quot;:&quot;/event_types&quot;,
&quot;value&quot;:[
{
&quot;name&quot;:&quot;PAYMENT.SALE.REFUNDED&quot;
}
]
}
]</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$patch</span> = <span class="hljs-keyword">new</span> \PayPal\Api\Patch();
<span class="hljs-variable">$patch</span>-&gt;setOp(<span class="hljs-string">"replace"</span>)
-&gt;setPath(<span class="hljs-string">"/url"</span>)
-&gt;setValue(<span class="hljs-string">"https://requestb.in/10ujt3c1?uniqid="</span>. uniqid());
<span class="hljs-variable">$patch2</span> = <span class="hljs-keyword">new</span> \PayPal\Api\Patch();
<span class="hljs-variable">$patch2</span>-&gt;setOp(<span class="hljs-string">"replace"</span>)
-&gt;setPath(<span class="hljs-string">"/event_types"</span>)
-&gt;setValue(json_decode(<span class="hljs-string">'[{"name":"PAYMENT.SALE.REFUNDED"}]'</span>));
<span class="hljs-variable">$patchRequest</span> = <span class="hljs-keyword">new</span> \PayPal\Api\PatchRequest();
<span class="hljs-variable">$patchRequest</span>-&gt;addPatch(<span class="hljs-variable">$patch</span>)-&gt;addPatch(<span class="hljs-variable">$patch2</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="get-webhook">Get Webhook</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
<span class="hljs-variable">$output</span> = <span class="hljs-variable">$webhook</span>-&gt;update(<span class="hljs-variable">$patchRequest</span>, <span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
ResultPrinter::printError(<span class="hljs-string">"Updated a Webhook"</span>, <span class="hljs-string">"Webhook"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$patchRequest</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}
ResultPrinter::printResult(<span class="hljs-string">"Updated a Webhook"</span>, <span class="hljs-string">"Webhook"</span>, <span class="hljs-variable">$output</span>-&gt;getId(), <span class="hljs-variable">$patchRequest</span>, <span class="hljs-variable">$output</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$output</span>;</div></div></div></div></body></html>

View File

@@ -0,0 +1,13 @@
<!DOCTYPE html><html lang="en"><head><title>notifications/WebhookEventTypesList</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="notifications/WebhookEventTypesList"><meta name="groc-project-path" content="notifications/WebhookEventTypesList.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">notifications/WebhookEventTypesList.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="get-reference-list-of-all-webhook-event-types">Get Reference List of all Webhook Event Types</h1>
<p>This sample code demonstrate how you can get reference list of all webhook event types, as documented here at:
<a href="https://developer.paypal.com/webapps/developer/docs/api/#get-a-reference-list-of-webhook-event-types">https://developer.paypal.com/webapps/developer/docs/api/#get-a-reference-list-of-webhook-event-types</a>
API used: GET /v1/notifications/webhooks-event-types</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$apiContext</span> = <span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="get-list-of-all-webhook-event-types">Get List of all Webhook event types</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
<span class="hljs-variable">$output</span> = \PayPal\Api\WebhookEventType::availableEventTypes(<span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
ResultPrinter::printError(<span class="hljs-string">"Get List of All Webhook Event Types"</span>, <span class="hljs-string">"WebhookEventTypeList"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}
ResultPrinter::printResult(<span class="hljs-string">"Get List of All Webhook Event Types"</span>, <span class="hljs-string">"WebhookEventTypeList"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$output</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$output</span>;</div></div></div></div></body></html>

View File

@@ -0,0 +1,54 @@
<!DOCTYPE html><html lang="en"><head><title>notifications/createWebhook</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="notifications/createWebhook"><meta name="groc-project-path" content="notifications/createWebhook.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">notifications/createWebhook.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="create-webhook-sample">Create Webhook Sample</h1>
<p>This sample code demonstrate how you can create a webhook, as documented here at:
<a href="https://developer.paypal.com/webapps/developer/docs/api/#create-a-webhook">https://developer.paypal.com/webapps/developer/docs/api/#create-a-webhook</a>
API used: POST /v1/notifications/webhooks</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a new instance of Webhook object</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$webhook</span> = <span class="hljs-keyword">new</span> \PayPal\Api\Webhook();</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="basic-information">Basic Information</h1>
<pre><code>{
&quot;url&quot;:&quot;https://requestb.in/10ujt3c1&quot;,
&quot;event_types&quot;:[
{
&quot;name&quot;:&quot;PAYMENT.AUTHORIZATION.CREATED&quot;
},
{
&quot;name&quot;:&quot;PAYMENT.AUTHORIZATION.VOIDED&quot;
}
]
}</code></pre>
<p>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.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$webhook</span>-&gt;setUrl(<span class="hljs-string">"https://requestb.in/10ujt3c1?uniqid="</span> . uniqid());</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="event-types">Event Types</h1>
<p>Event types correspond to what kind of notifications you want to receive on the given URL.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$webhookEventTypes</span> = <span class="hljs-keyword">array</span>();
<span class="hljs-variable">$webhookEventTypes</span>[] = <span class="hljs-keyword">new</span> \PayPal\Api\WebhookEventType(
<span class="hljs-string">'{
"name":"PAYMENT.AUTHORIZATION.CREATED"
}'</span>
);
<span class="hljs-variable">$webhookEventTypes</span>[] = <span class="hljs-keyword">new</span> \PayPal\Api\WebhookEventType(
<span class="hljs-string">'{
"name":"PAYMENT.AUTHORIZATION.VOIDED"
}'</span>
);
<span class="hljs-variable">$webhook</span>-&gt;setEventTypes(<span class="hljs-variable">$webhookEventTypes</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$webhook</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-webhook">Create Webhook</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
<span class="hljs-variable">$output</span> = <span class="hljs-variable">$webhook</span>-&gt;create(<span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {</div></div></div><div class="segment"><div class="code folded"><div class="wrapper marker"><span class="c1"> // Ignore workflow code segment</span></div><div class="wrapper"> <span class="hljs-comment">// Ignore workflow code segment</span>
<span class="hljs-keyword">if</span> (<span class="hljs-variable">$ex</span> <span class="hljs-keyword">instanceof</span> \PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException) {
<span class="hljs-variable">$data</span> = <span class="hljs-variable">$ex</span>-&gt;getData();
ResultPrinter::printError(<span class="hljs-string">"Created Webhook Failed. Checking if it is Webhook Number Limit Exceeded. Trying to delete all existing webhooks"</span>, <span class="hljs-string">"Webhook"</span>, <span class="hljs-string">"Please Use &lt;a style='color: red;' href='DeleteAllWebhooks.php' &gt;Delete All Webhooks&lt;/a&gt; Sample to delete all existing webhooks in sample"</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">if</span> (strpos(<span class="hljs-variable">$data</span>,<span class="hljs-string">'WEBHOOK_NUMBER_LIMIT_EXCEEDED'</span>) !== <span class="hljs-keyword">false</span>) {
<span class="hljs-keyword">require</span> <span class="hljs-string">'DeleteAllWebhooks.php'</span>;
<span class="hljs-keyword">try</span> {
<span class="hljs-variable">$output</span> = <span class="hljs-variable">$webhook</span>-&gt;create(<span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
ResultPrinter::printError(<span class="hljs-string">"Created Webhook"</span>, <span class="hljs-string">"Webhook"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}
} <span class="hljs-keyword">else</span> {
ResultPrinter::printError(<span class="hljs-string">"Created Webhook"</span>, <span class="hljs-string">"Webhook"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}
} <span class="hljs-keyword">else</span> {
ResultPrinter::printError(<span class="hljs-string">"Created Webhook"</span>, <span class="hljs-string">"Webhook"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Print Success Result</p></div></div><div class="code"><div class="wrapper">}
ResultPrinter::printResult(<span class="hljs-string">"Created Webhook"</span>, <span class="hljs-string">"Webhook"</span>, <span class="hljs-variable">$output</span>-&gt;getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$output</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$output</span>;</div></div></div></div></body></html>

View File

@@ -24,6 +24,18 @@ when the user is redirected from paypal back to your site</p></div></div><div cl
ResultPrinter::printResult(<span class="hljs-string">"Executed Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-variable">$payment</span>-&gt;getId(), <span class="hljs-variable">$execution</span>, <span class="hljs-variable">$result</span>);
<span class="hljs-keyword">try</span> {
<span class="hljs-variable">$payment</span> = Payment::get(<span class="hljs-variable">$paymentId</span>, <span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
ResultPrinter::printError(<span class="hljs-string">"Get Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}
ResultPrinter::printResult(<span class="hljs-string">"Get Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-variable">$payment</span>-&gt;getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$payment</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$payment</span>;
} <span class="hljs-keyword">else</span> {
ResultPrinter::printResult(<span class="hljs-string">"User Cancelled the Approval"</span>, <span class="hljs-keyword">null</span>);
}</div></div></div></div></body></html>

View File

@@ -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);

View File

@@ -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();

View File

@@ -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);
}
/**

View File

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

View File

@@ -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');
}
}

View File

@@ -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);
}
/**

View File

@@ -0,0 +1,49 @@
<?php
namespace PayPal\Test\Functional;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Core\PPCredentialManager;
use PayPal\Rest\ApiContext;
class Setup
{
public static $mode = 'mock';
public static function SetUpForFunctionalTests(\PHPUnit_Framework_TestCase &$test)
{
$context = new ApiContext();
$context->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
));
}
}
}