forked from LiveCarta/PayPal-PHP-SDK
More Webhook API Changes
- Updated API Models with Fixes - Updated Samples - Additional Functional Tests
This commit is contained in:
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}, {
|
||||
|
||||
@@ -5,15 +5,16 @@ API used: GET /v1/notifications/webhooks-events</p></div></div></div><div class=
|
||||
<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">$webhook</span> = <span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.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">$params</span> = <span class="hljs-keyword">array</span>(</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>'start_time'=>'2014-12-06T11:00:00Z',
|
||||
'end_time'=>'2014-12-12T11:00:00Z'</p></div></div><div class="code"><div class="wrapper">);</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>);
|
||||
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-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">"Search Webhook events"</span>, <span class="hljs-string">"WebhookEventList"</span>, <span class="hljs-variable">$webhook</span>->getId(), <span class="hljs-variable">$params</span>, <span class="hljs-variable">$output</span>);
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Search Webhook events"</span>, <span class="hljs-string">"WebhookEventList"</span>, <span class="hljs-keyword">null</span>, <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>
|
||||
@@ -1,4 +1,4 @@
|
||||
<!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"><?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="create-webhook-sample">Create Webhook Sample</h1>
|
||||
<!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"><?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>
|
||||
|
||||
@@ -54,7 +54,7 @@ payment approval/ cancellation.</p></div></div><div class="code"><div class="wra
|
||||
->setCancelUrl(<span class="hljs-string">"$baseUrl/ExecutePayment.php?success=false"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payment">Payment</h3>
|
||||
<p>A Payment Resource; create one using
|
||||
the above types and intent set to 'sale'</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payment</span> = <span class="hljs-keyword">new</span> Payment();
|
||||
<span class="hljs-variable">$payment</span>->setIntent(<span class="hljs-string">"sale"</span>)
|
||||
<span class="hljs-variable">$payment</span>->setIntent(<span class="hljs-string">"authorize"</span>)
|
||||
->setPayer(<span class="hljs-variable">$payer</span>)
|
||||
->setRedirectUrls(<span class="hljs-variable">$redirectUrls</span>)
|
||||
->setTransactions(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$transaction</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">$payment</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||
|
||||
114
sample/index.php
114
sample/index.php
@@ -137,7 +137,7 @@ if (PHP_SAPI == 'cli') {
|
||||
<![endif]-->
|
||||
</head>
|
||||
|
||||
<body data-spy="scroll" data-target="#leftNavigation" data-offset="0" class="scrollspy-example">
|
||||
<body data-spy="scroll" data-target="#leftNavigation" data-offset="10" class="scrollspy-example">
|
||||
<!-- Main component for a primary marketing message or call to action -->
|
||||
<div class="jumbotron">
|
||||
<div class="container-fluid">
|
||||
@@ -188,6 +188,7 @@ if (PHP_SAPI == 'cli') {
|
||||
<li><a href="#billing">Billing Plan & Agreements</a></li>
|
||||
<li><a href="#vault">Vault</a></li>
|
||||
<li><a href="#experience">Payment Experience</a></li>
|
||||
<li><a href="#notifications">Notifications</a></li>
|
||||
<li><a href="#invoice">Invoice</a></li>
|
||||
<li><a href="#identity">Identity (LIPP)</a></li>
|
||||
</ul>
|
||||
@@ -249,7 +250,7 @@ if (PHP_SAPI == 'cli') {
|
||||
<a href="payments/CreatePaymentUsingSavedCard.php"
|
||||
class="btn btn-primary pull-left execute">
|
||||
Try It <i class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/payments/CreatePayment.html" class="btn btn-default pull-right">Source <i
|
||||
<a href="doc/payments/CreatePaymentUsingSavedCard.html" class="btn btn-default pull-right">Source <i
|
||||
class="fa fa-file-code-o"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -275,7 +276,7 @@ if (PHP_SAPI == 'cli') {
|
||||
<div class="col-md-4">
|
||||
<a href="payments/GetPayment.php" class="btn btn-primary pull-left execute"> Try It <i
|
||||
class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/payments/CreatePayment.html" class="btn btn-default pull-right">Source <i
|
||||
<a href="doc/payments/GetPayment.html" class="btn btn-default pull-right">Source <i
|
||||
class="fa fa-file-code-o"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -286,7 +287,7 @@ if (PHP_SAPI == 'cli') {
|
||||
<div class="col-md-4">
|
||||
<a href="payments/ListPayments.php" class="btn btn-primary pull-left execute"> Try It <i
|
||||
class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/payments/CreatePayment.html" class="btn btn-default pull-right">Source <i
|
||||
<a href="doc/payments/ListPayments.html" class="btn btn-default pull-right">Source <i
|
||||
class="fa fa-file-code-o"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -754,6 +755,111 @@ if (PHP_SAPI == 'cli') {
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 id="notifications" class="panel-title"><a
|
||||
href="https://developer.paypal.com/webapps/developer/docs/api/#notifications"
|
||||
target="_blank">Notifications</a></h3>
|
||||
</div>
|
||||
<!-- List group -->
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-8"><h5>Get a reference list of webhook event types</h5></div>
|
||||
<div class="col-md-4">
|
||||
<a href="notifications/WebhookEventTypesList.php" class="btn btn-primary pull-left execute"> Try It
|
||||
<i
|
||||
class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/notifications/WebhookEventTypesList.html" class="btn btn-default pull-right">Source <i
|
||||
class="fa fa-file-code-o"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-8"><h5>Create a webhook</h5></div>
|
||||
<div class="col-md-4">
|
||||
<a href="notifications/CreateWebhook.php" class="btn btn-primary pull-left execute"> Try It
|
||||
<i
|
||||
class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/notifications/CreateWebhook.html" class="btn btn-default pull-right">Source <i
|
||||
class="fa fa-file-code-o"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-8"><h5>Get a webhook</h5></div>
|
||||
<div class="col-md-4">
|
||||
<a href="notifications/GetWebhook.php" class="btn btn-primary pull-left execute"> Try It
|
||||
<i
|
||||
class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/payments/GetAuthorization.html" class="btn btn-default pull-right">Source <i
|
||||
class="fa fa-file-code-o"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-8"><h5>List subscribed webhook event types</h5></div>
|
||||
<div class="col-md-4">
|
||||
<a href="notifications/ListSubscribedWebhookEventTypes.php" class="btn btn-primary pull-left execute"> Try It <i
|
||||
class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/payments/GetCapture.html" class="btn btn-default pull-right">Source <i
|
||||
class="fa fa-file-code-o"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-8"><h5>List all webhooks</h5></div>
|
||||
<div class="col-md-4">
|
||||
<a href="notifications/ListWebhooks.php" class="btn btn-primary pull-left execute">
|
||||
Try It <i
|
||||
class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/payments/AuthorizationCapture.html" class="btn btn-default pull-right">Source
|
||||
<i
|
||||
class="fa fa-file-code-o"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-8"><h5>Update a webhook</h5></div>
|
||||
<div class="col-md-4">
|
||||
<a href="notifications/UpdateWebhook.php" class="btn btn-primary pull-left execute"> Try It
|
||||
<i
|
||||
class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/payments/VoidAuthorization.html" class="btn btn-default pull-right">Source <i
|
||||
class="fa fa-file-code-o"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-8"><h5>Delete a webhook</h5></div>
|
||||
<div class="col-md-4">
|
||||
<a href="notifications/DeleteWebhook.php" class="btn btn-primary pull-left execute"> Try It <i
|
||||
class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/payments/Reauthorization.html" class="btn btn-default pull-right">Source <i
|
||||
class="fa fa-file-code-o"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-8"><h5>Search webhook events</h5></div>
|
||||
<div class="col-md-4">
|
||||
<a href="notifications/SearchWebhookEvents.php" class="btn btn-primary pull-left execute"> Try It <i
|
||||
class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/payments/RefundCapture.html" class="btn btn-default pull-right">Source <i
|
||||
class="fa fa-file-code-o"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 id="invoice" class="panel-title"><a
|
||||
|
||||
24
sample/notifications/DeleteAllWebhooks.php
Normal file
24
sample/notifications/DeleteAllWebhooks.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?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;
|
||||
25
sample/notifications/DeleteWebhook.php
Normal file
25
sample/notifications/DeleteWebhook.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?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/<Webhook-Id>
|
||||
|
||||
// ## 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;
|
||||
26
sample/notifications/GetWebhook.php
Normal file
26
sample/notifications/GetWebhook.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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/<Webhook-Id>
|
||||
|
||||
// ## 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;
|
||||
26
sample/notifications/ListSubscribedWebhookEventTypes.php
Normal file
26
sample/notifications/ListSubscribedWebhookEventTypes.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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/<Webhook-Id>
|
||||
|
||||
// ## 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;
|
||||
27
sample/notifications/ListWebhooks.php
Normal file
27
sample/notifications/ListWebhooks.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?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;
|
||||
31
sample/notifications/SearchWebhookEvents.php
Normal file
31
sample/notifications/SearchWebhookEvents.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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 __DIR__ . '/../bootstrap.php';
|
||||
|
||||
$params = array(
|
||||
// 'start_time'=>'2014-12-06T11:00:00Z',
|
||||
// 'end_time'=>'2014-12-12T11:00:00Z'
|
||||
);
|
||||
|
||||
// ### Search Webhook events
|
||||
try {
|
||||
$output = \PayPal\Api\WebhookEvent::all($params, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Search Webhook events", "WebhookEventList", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Search Webhook events", "WebhookEventList", null, $params, $output);
|
||||
|
||||
return $output;
|
||||
55
sample/notifications/UpdateWebhook.php
Normal file
55
sample/notifications/UpdateWebhook.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?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/<Webhook-Id>
|
||||
|
||||
// ## 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;
|
||||
21
sample/notifications/WebhookEventTypesList.php
Normal file
21
sample/notifications/WebhookEventTypesList.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?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;
|
||||
77
sample/notifications/createWebhook.php
Normal file
77
sample/notifications/createWebhook.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?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
|
||||
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;
|
||||
@@ -79,7 +79,7 @@ $redirectUrls->setReturnUrl("$baseUrl/ExecutePayment.php?success=true")
|
||||
// A Payment Resource; create one using
|
||||
// the above types and intent set to 'sale'
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("sale")
|
||||
$payment->setIntent("authorize")
|
||||
->setPayer($payer)
|
||||
->setRedirectUrls($redirectUrls)
|
||||
->setTransactions(array($transaction));
|
||||
|
||||
@@ -39,6 +39,18 @@ if (isset($_GET['success']) && $_GET['success'] == 'true') {
|
||||
|
||||
ResultPrinter::printResult("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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user