diff --git a/lib/PayPal/Api/WebhookEvent.php b/lib/PayPal/Api/WebhookEvent.php index 44babde..cc69209 100644 --- a/lib/PayPal/Api/WebhookEvent.php +++ b/lib/PayPal/Api/WebhookEvent.php @@ -2,6 +2,7 @@ namespace PayPal\Api; +use PayPal\Common\PPModel; use PayPal\Common\ResourceModel; use PayPal\Validation\ArgumentValidator; use PayPal\Api\WebhookEventList; @@ -218,7 +219,7 @@ class WebhookEvent extends ResourceModel /** * This contains the resource that is identified by resource_type element. * - * @param mixed $resource + * @param \PayPal\Common\PPModel $resource * * @return $this */ @@ -231,7 +232,7 @@ class WebhookEvent extends ResourceModel /** * This contains the resource that is identified by resource_type element. * - * @return mixed + * @return \PayPal\Common\PPModel */ public function getResource() { diff --git a/lib/PayPal/Api/WebhookEventType.php b/lib/PayPal/Api/WebhookEventType.php index a3bf71a..c0287ff 100644 --- a/lib/PayPal/Api/WebhookEventType.php +++ b/lib/PayPal/Api/WebhookEventType.php @@ -72,7 +72,7 @@ class WebhookEventType extends ResourceModel * @param string $webhookId * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls - * @return WebhookEventList + * @return WebhookEventTypeList */ public static function subscribedEventTypes($webhookId, $apiContext = null, $restCall = null) { @@ -86,7 +86,7 @@ class WebhookEventType extends ResourceModel $apiContext, $restCall ); - $ret = new WebhookEventList(); + $ret = new WebhookEventTypeList(); $ret->fromJson($json); return $ret; } @@ -96,7 +96,7 @@ class WebhookEventType extends ResourceModel * * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls - * @return WebhookEventList + * @return WebhookEventTypeList */ public static function availableEventTypes($apiContext = null, $restCall = null) { @@ -109,7 +109,7 @@ class WebhookEventType extends ResourceModel $apiContext, $restCall ); - $ret = new WebhookEventList(); + $ret = new WebhookEventTypeList(); $ret->fromJson($json); return $ret; } diff --git a/lib/PayPal/Common/PPReflectionUtil.php b/lib/PayPal/Common/PPReflectionUtil.php index 40c10ce..9222bf6 100644 --- a/lib/PayPal/Common/PPReflectionUtil.php +++ b/lib/PayPal/Common/PPReflectionUtil.php @@ -34,6 +34,10 @@ class PPReflectionUtil */ public static function getPropertyClass($class, $propertyName) { + if ($class == get_class(new PPModel())) { + // Make it generic if PPModel is used for generating this + return get_class(new PPModel()); + } if (($annotations = self::propertyAnnotations($class, $propertyName)) && isset($annotations['return'])) { $param = $annotations['return']; diff --git a/sample/doc/assets/behavior.js b/sample/doc/assets/behavior.js index b5c5960..7bad080 100644 --- a/sample/doc/assets/behavior.js +++ b/sample/doc/assets/behavior.js @@ -1235,6 +1235,62 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "depth": 1, "children": [ { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/PayPal-PHP-SDK/sample/notifications/CreateWebhook.php", + "projectPath": "notifications/CreateWebhook.php", + "targetPath": "notifications/CreateWebhook", + "pageTitle": "notifications/CreateWebhook", + "title": "CreateWebhook" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Create Webhook Sample", + "slug": "create-webhook-sample" + }, + "depth": 1 + }, { + "type": "heading", + "data": { + "level": 1, + "title": "Basic Information", + "slug": "basic-information" + }, + "depth": 1 + }, { + "type": "heading", + "data": { + "level": 1, + "title": "Event Types", + "slug": "event-types" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Create Webhook", + "slug": "create-webhook" + }, + "depth": 3 + } + ] + } + ] + }, { "type": "file", "data": { "language": { @@ -1639,62 +1695,6 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 ] } ] - }, { - "type": "file", - "data": { - "language": { - "nameMatchers": [{}, ".fbp"], - "pygmentsLexer": "php", - "singleLineComment": ["//"], - "ignorePrefix": "}", - "foldPrefix": "^", - "name": "PHP" - }, - "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/PayPal-PHP-SDK/sample/notifications/createWebhook.php", - "projectPath": "notifications/createWebhook.php", - "targetPath": "notifications/createWebhook", - "pageTitle": "notifications/createWebhook", - "title": "createWebhook" - }, - "depth": 2, - "outline": [ - { - "type": "heading", - "data": { - "level": 1, - "title": "Create Webhook Sample", - "slug": "create-webhook-sample" - }, - "depth": 1 - }, { - "type": "heading", - "data": { - "level": 1, - "title": "Basic Information", - "slug": "basic-information" - }, - "depth": 1 - }, { - "type": "heading", - "data": { - "level": 1, - "title": "Event Types", - "slug": "event-types" - }, - "depth": 1, - "children": [ - { - "type": "heading", - "data": { - "level": 3, - "title": "Create Webhook", - "slug": "create-webhook" - }, - "depth": 3 - } - ] - } - ] } ] }, { diff --git a/sample/doc/notifications/SearchWebhookEvents.html b/sample/doc/notifications/SearchWebhookEvents.html index e446d18..6fafcca 100644 --- a/sample/doc/notifications/SearchWebhookEvents.html +++ b/sample/doc/notifications/SearchWebhookEvents.html @@ -5,15 +5,16 @@ API used: GET /v1/notifications/webhooks-events

PLEASE NOTE:

Creating webhook is sample purposes only. In real scenario, you dont need to create a new webhook everytime you want to search for a webhook events. This is made in a sample just to make sure there is minimum of one webhook to listen to.

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

Search Webhook events

try { +$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, $webhookId, $ex); + ResultPrinter::printError("Search Webhook events", "WebhookEventList", null, null, $ex); exit(1); } -ResultPrinter::printResult("Search Webhook events", "WebhookEventList", $webhook->getId(), $params, $output); +ResultPrinter::printResult("Search Webhook events", "WebhookEventList", null, $params, $output); return $output;
\ No newline at end of file diff --git a/sample/doc/notifications/createWebhook.html b/sample/doc/notifications/createWebhook.html index 16fcb90..ddaa5cb 100644 --- a/sample/doc/notifications/createWebhook.html +++ b/sample/doc/notifications/createWebhook.html @@ -1,4 +1,4 @@ -notifications/createWebhook
notifications/createWebhook.php
<?php

Create Webhook Sample

+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

diff --git a/sample/doc/payments/CreatePaymentUsingPayPal.html b/sample/doc/payments/CreatePaymentUsingPayPal.html index 1f604b8..7815864 100644 --- a/sample/doc/payments/CreatePaymentUsingPayPal.html +++ b/sample/doc/payments/CreatePaymentUsingPayPal.html @@ -54,7 +54,7 @@ payment approval/ cancellation.

"$baseUrl/ExecutePayment.php?success=false");

Payment

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

For Sample Purposes Only.

$request = clone $payment;

Create Payment

diff --git a/sample/index.php b/sample/index.php index d785ff4..0dbe957 100644 --- a/sample/index.php +++ b/sample/index.php @@ -137,7 +137,7 @@ if (PHP_SAPI == 'cli') { - +
@@ -188,6 +188,7 @@ if (PHP_SAPI == 'cli') {
  • Billing Plan & Agreements
  • Vault
  • Payment Experience
  • +
  • Notifications
  • Invoice
  • Identity (LIPP)
  • @@ -249,7 +250,7 @@ if (PHP_SAPI == 'cli') { Try It - Source Source
    @@ -275,7 +276,7 @@ if (PHP_SAPI == 'cli') {
    @@ -286,7 +287,7 @@ if (PHP_SAPI == 'cli') {
    @@ -754,6 +755,111 @@ if (PHP_SAPI == 'cli') {
    +
    + + + +
    +

    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; diff --git a/sample/notifications/DeleteWebhook.php b/sample/notifications/DeleteWebhook.php new file mode 100644 index 0000000..f70f654 --- /dev/null +++ b/sample/notifications/DeleteWebhook.php @@ -0,0 +1,25 @@ + + +// ## 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; diff --git a/sample/notifications/GetWebhook.php b/sample/notifications/GetWebhook.php new file mode 100644 index 0000000..5a6063d --- /dev/null +++ b/sample/notifications/GetWebhook.php @@ -0,0 +1,26 @@ + + +// ## 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; diff --git a/sample/notifications/ListSubscribedWebhookEventTypes.php b/sample/notifications/ListSubscribedWebhookEventTypes.php new file mode 100644 index 0000000..a831dbb --- /dev/null +++ b/sample/notifications/ListSubscribedWebhookEventTypes.php @@ -0,0 +1,26 @@ + + +// ## 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; diff --git a/sample/notifications/ListWebhooks.php b/sample/notifications/ListWebhooks.php new file mode 100644 index 0000000..1317567 --- /dev/null +++ b/sample/notifications/ListWebhooks.php @@ -0,0 +1,27 @@ +'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; diff --git a/sample/notifications/UpdateWebhook.php b/sample/notifications/UpdateWebhook.php new file mode 100644 index 0000000..b506e55 --- /dev/null +++ b/sample/notifications/UpdateWebhook.php @@ -0,0 +1,55 @@ + + +// ## 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; diff --git a/sample/notifications/WebhookEventTypesList.php b/sample/notifications/WebhookEventTypesList.php new file mode 100644 index 0000000..c7fdf39 --- /dev/null +++ b/sample/notifications/WebhookEventTypesList.php @@ -0,0 +1,21 @@ +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 Delete All Webhooks 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; diff --git a/sample/payments/CreatePaymentUsingPayPal.php b/sample/payments/CreatePaymentUsingPayPal.php index 029f61b..5ffd62c 100644 --- a/sample/payments/CreatePaymentUsingPayPal.php +++ b/sample/payments/CreatePaymentUsingPayPal.php @@ -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)); diff --git a/sample/payments/ExecutePayment.php b/sample/payments/ExecutePayment.php index 4f6d478..9bc882a 100644 --- a/sample/payments/ExecutePayment.php +++ b/sample/payments/ExecutePayment.php @@ -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); } diff --git a/tests/PayPal/Test/Functional/Api/WebhookFunctionalTest.php b/tests/PayPal/Test/Functional/Api/WebhookFunctionalTest.php new file mode 100644 index 0000000..eef42ed --- /dev/null +++ b/tests/PayPal/Test/Functional/Api/WebhookFunctionalTest.php @@ -0,0 +1,157 @@ +getClassName(); + $testName = $this->getName(); + $operationString = file_get_contents(__DIR__ . "/../resources/$className/$testName.json"); + $this->operation = json_decode($operationString, true); + $this->response = true; + if (array_key_exists('body', $this->operation['response'])) { + $this->response = json_encode($this->operation['response']['body']); + } + Setup::SetUpForFunctionalTests($this); + } + + /** + * Returns just the classname of the test you are executing. It removes the namespaces. + * @return string + */ + public function getClassName() + { + return join('', array_slice(explode('\\', get_class($this)), -1)); + } + + public function testCreate() + { + $request = $this->operation['request']['body']; + $obj = new Webhook($request); + // Adding a random url request to make it unique + $obj->setUrl($obj->getUrl() . '?rand=' . uniqid()); + $result = $obj->create(null, $this->mockPPRestCall); + $this->assertNotNull($result); + return $result; + } + + /** + * @depends testCreate + * @param $webhook Webhook + * @return Webhook + */ + public function testGet($webhook) + { + $result = Webhook::get($webhook->getId(), null, $this->mockPPRestCall); + $this->assertNotNull($result); + $this->assertEquals($webhook->getId(), $result->getId()); + $this->assertEquals($webhook, $result, "", 0, 10, true); + return $result; + } + + /** + * @depends testGet + * @param $webhook Webhook + */ + public function testGetAll($webhook) + { + $result = Webhook::getAll(null, $this->mockPPRestCall); + $this->assertNotNull($result); + $found = false; + $foundObject = null; + foreach ($result->getWebhooks() as $webhookObject) { + if ($webhookObject->getId() == $webhook->getId()) { + $found = true; + $foundObject = $webhookObject; + break; + } + } + $this->assertTrue($found, "The Created Web Profile was not found in the get list"); + $this->assertEquals($webhook->getId(), $foundObject->getId()); + + } + + /** + * @depends testGet + * @param $webhook Webhook + */ + public function testUpdate($webhook) + { + $patches = array(); + foreach ($this->operation['request']['body'] as $request) { + /** @var Patch[] $request */ + $patch = new Patch(); + $patch->setOp($request['op']); + $patch->setPath($request['path']); + $patch->setValue($request['value']); + if ($request['path'] == "/url") { + $new_url = $request['value'] . '?rand=' .uniqid(); + $patch->setValue($new_url); + } + $patches[] = $patch; + } + + $patchRequest = new PatchRequest(); + $patchRequest->setPatches($patches); + $result = $webhook->update($patchRequest, null, $this->mockPPRestCall); + $this->assertNotNull($result); + $found = false; + $foundObject = null; + foreach ($result->getEventTypes() as $eventType) { + if ($eventType->getName() == "PAYMENT.SALE.REFUNDED") { + $found = true; + break; + } + } + $this->assertTrue($found); + } + + /** + * @depends testGet + * @param $webhook Webhook + */ + public function testDelete($webhook) + { + $result = $webhook->delete(null, $this->mockPPRestCall); + $this->assertTrue($result); + } + + public function testEventSearch() + { + $result = WebhookEvent::all(array(),null, $this->mockPPRestCall); + $this->assertNotNull($result); + return $result; + } +} diff --git a/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testCreate.json b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testCreate.json new file mode 100644 index 0000000..d03f819 --- /dev/null +++ b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testCreate.json @@ -0,0 +1,75 @@ +{ + "description":"Create a webhook", + "title":"Create a webhook", + "runnable":true, + "operationId":"webhooks.create", + "user":{ + "scopes":[ + "https://uri.paypal.com/services/applications/webhooks" + ] + }, + "credentials":{ + "oauth":{ + "path":"/v1/oauth/token", + "clientId":"", + "clientSecret":"" + } + }, + "request":{ + "path":"v1/notifications/webhooks", + "method":"POST", + "headers":{ + "Content-Type":"application/json", + "Authorization":"Bearer ECvJ_yBNz_UfMmCvWEbT_2ZWXdzbFFQZ-1Y5K2NGgeHn" + }, + "body":{ + "url":"https://requestb.in/10ujt3c1", + "event_types":[ + { + "name":"PAYMENT.AUTHORIZATION.CREATED" + }, + { + "name":"PAYMENT.AUTHORIZATION.VOIDED" + } + ] + } + }, + "response":{ + "status":"201", + "headers":{ + "Content-Type":"application/json", + "Paypal-Debug-id":"0c444abc1d12d" + }, + "body":{ + "id":"0EH40505U7160970P", + "url":"https://requestb.in/10ujt3c1", + "event_types":[ + { + "name":"PAYMENT.AUTHORIZATION.CREATED", + "description":"A payment authorization was created" + }, + { + "name":"PAYMENT.AUTHORIZATION.VOIDED", + "description":"A payment authorization was voided" + } + ], + "links":[ + { + "href":"https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel":"self", + "method":"GET" + }, + { + "href":"https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel":"update", + "method":"PATCH" + }, + { + "href":"https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel":"delete", + "method":"DELETE" + } + ] + } + } +} diff --git a/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testDelete.json b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testDelete.json new file mode 100644 index 0000000..dee626b --- /dev/null +++ b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testDelete.json @@ -0,0 +1,33 @@ +{ + "description":"Delete a webhook", + "title":"Delete a webhook", + "runnable":true, + "operationId":"webhooks.delete", + "user":{ + "scopes":[ + "https://uri.paypal.com/services/applications/webhooks" + ] + }, + "credentials":{ + "oauth":{ + "path":"/v1/oauth/token", + "clientId":"", + "clientSecret":"" + } + }, + "request":{ + "path":"v1/notifications/webhooks/5GP028458E2496506", + "method":"DELETE", + "headers":{ + "Content-Type":"application/json", + "Authorization":"Bearer ECvJ_yBNz_UfMmCvWEbT_2ZWXdzbFFQZ-1Y5K2NGgeHn" + } + }, + "response":{ + "status":"204", + "headers":{ + "Content-Type":"application/json", + "Paypal-Debug-id":"0c444abc1d12d" + } + } +} \ No newline at end of file diff --git a/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testEventResend.json b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testEventResend.json new file mode 100644 index 0000000..145e030 --- /dev/null +++ b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testEventResend.json @@ -0,0 +1,89 @@ +{ + "description":"Resend a webhook event", + "title":"Resend a webhook event", + "runnable":true, + "operationId":"event.resend", + "user":{ + "scopes":[ + "https://uri.paypal.com/services/applications/webhooks" + ] + }, + "credentials":{ + "oauth":{ + "path":"/v1/oauth/token", + "clientId":"", + "clientSecret":"" + } + }, + "request":{ + "path":"v1/notifications/webhooks-events/8PT597110X687430LKGECATA/resend", + "method":"GET", + "headers":{ + "Content-Type":"application/json", + "Authorization":"Bearer ECvJ_yBNz_UfMmCvWEbT_2ZWXdzbFFQZ-1Y5K2NGgeHn" + } + }, + "response":{ + "status":"202", + "headers":{ + "Content-Type":"application/json", + "Paypal-Debug-id":"0c444abc1d12d" + }, + "body":{ + "id":"8PT597110X687430LKGECATA", + "create_time":"2013-06-25T21:41:28Z", + "resource_type":"authorization", + "trigger_event":"PAYMENT.AUTHORIZATION.CREATED", + "summary":"A payment authorization was created", + "resource":{ + "id":"2DC87612EK520411B", + "create_time":"2013-06-25T21:39:15Z", + "update_time":"2013-06-25T21:39:17Z", + "state":"authorized", + "amount":{ + "total":"7.47", + "currency":"USD", + "details":{ + "subtotal":"7.47" + } + }, + "parent_payment":"PAY-36246664YD343335CKHFA4AY", + "valid_until":"2013-07-24T21:39:15Z", + "links":[ + { + "href":"https://api.paypal.com/v1/payments/authorization/2DC87612EK520411B", + "rel":"self", + "method":"GET" + }, + { + "href":"https://api.paypal.com/v1/payments/authorization/2DC87612EK520411B/capture", + "rel":"capture", + "method":"POST" + }, + { + "href":"https://api.paypal.com/v1/payments/authorization/2DC87612EK520411B/void", + "rel":"void", + "method":"POST" + }, + { + "href":"https://api.paypal.com/v1/payments/payment/PAY-36246664YD343335CKHFA4AY", + "rel":"parent_payment", + "method":"GET" + } + ] + }, + "links":[ + { + "href":"https://api.paypal.com/v1/notfications/webhooks-events/8PT597110X687430LKGECATA", + "rel":"self", + "method":"GET" + }, + { + "href":"https://api.paypal.com/v1/notfications/webhooks-events/8PT597110X687430LKGECATA/resend", + "rel":"resend", + "method":"POST" + } + ] + } + } +} \ No newline at end of file diff --git a/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testEventSearch.json b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testEventSearch.json new file mode 100644 index 0000000..5d26256 --- /dev/null +++ b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testEventSearch.json @@ -0,0 +1,162 @@ +{ + "description":"Get list of webhook events", + "title":"Get list of webhook events", + "runnable":true, + "operationId":"event.list", + "user":{ + "scopes":[ + "https://uri.paypal.com/services/applications/webhooks" + ] + }, + "credentials":{ + "oauth":{ + "path":"/v1/oauth/token", + "clientId":"", + "clientSecret":"" + } + }, + "request":{ + "path":"v1/notifications/webhooks-events", + "method":"GET", + "headers":{ + "Content-Type":"application/json", + "Authorization":"Bearer ECvJ_yBNz_UfMmCvWEbT_2ZWXdzbFFQZ-1Y5K2NGgeHn" + } + }, + "response":{ + "status":"200", + "headers":{ + "Content-Type":"application/json", + "Paypal-Debug-id":"0c444abc1d12d" + }, + "body":{ + "events": [ + { + "id": "8PT597110X687430LKGECATA", + "create_time": "2013-06-25T21:41:28Z", + "resource_type": "authorization", + "event_type": "PAYMENT.AUTHORIZATION.CREATED", + "summary": "A payment authorization was created", + "resource": { + "id": "2DC87612EK520411B", + "create_time": "2013-06-25T21:39:15Z", + "update_time": "2013-06-25T21:39:17Z", + "state": "authorized", + "amount": { + "total": "7.47", + "currency": "USD", + "details": { + "subtotal": "7.47" + } + }, + "parent_payment": "PAY-36246664YD343335CKHFA4AY", + "valid_until": "2013-07-24T21:39:15Z", + "links": [ + { + "href": "https://api.sandbox.paypal.com/v1/payments/authorization/2DC87612EK520411B", + "rel": "self", + "method": "GET" + }, + { + "href": "https://api.sandbox.paypal.com/v1/payments/authorization/2DC87612EK520411B/capture", + "rel": "capture", + "method": "POST" + }, + { + "href": "https://api.sandbox.paypal.com/v1/payments/authorization/2DC87612EK520411B/void", + "rel": "void", + "method": "POST" + }, + { + "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-36246664YD343335CKHFA4AY", + "rel": "parent_payment", + "method": "GET" + } + ] + }, + "links": [ + { + "href": "https://api.sandbox.paypal.com/v1/notfications/webhooks-events/8PT597110X687430LKGECATA", + "rel": "self", + "method": "GET" + }, + { + "href": "https://api.sandbox.paypal.com/v1/notfications/webhooks-events/8PT597110X687430LKGECATA/resend", + "rel": "resend", + "method": "POST" + } + ] + }, + { + "id": "HTSPGS710X687430LKGECATA", + "create_time": "2013-06-25T21:41:28Z", + "resource_type": "authorization", + "event_type": "PAYMENT.AUTHORIZATION.CREATED", + "summary": "A payment authorization was created", + "resource": { + "id": "HATH7S72EK520411B", + "create_time": "2013-06-25T21:39:15Z", + "update_time": "2013-06-25T21:39:17Z", + "state": "authorized", + "amount": { + "total": "7.47", + "currency": "USD", + "details": { + "subtotal": "7.47" + } + }, + "parent_payment": "PAY-ALDSFJ64YD343335CKHFA4AY", + "valid_until": "2013-07-24T21:39:15Z", + "links": [ + { + "href": "https://api.sandbox.paypal.com/v1/payments/authorization/HATH7S72EK520411B", + "rel": "self", + "method": "GET" + }, + { + "href": "https://api.sandbox.paypal.com/v1/payments/authorization/HATH7S72EK520411B/capture", + "rel": "capture", + "method": "POST" + }, + { + "href": "https://api.sandbox.paypal.com/v1/payments/authorization/HATH7S72EK520411B/void", + "rel": "void", + "method": "POST" + }, + { + "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-HATH7S72EK520411B", + "rel": "parent_payment", + "method": "GET" + } + ] + }, + "links": [ + { + "href": "https://api.sandbox.paypal.com/v1/notfications/webhooks-events/HTSPGS710X687430LKGECATA", + "rel": "self", + "method": "GET" + }, + { + "href": "https://api.sandbox.paypal.com/v1/notfications/webhooks-events/HTSPGS710X687430LKGECATA/resend", + "rel": "resend", + "method": "POST" + } + ] + } + ], + "count": 2, + "links": [ + { + "href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/?start_time=2014-08-04T12:46:47-07:00&amp;end_time=2014-09-18T12:46:47-07:00&amp;page_size=2&amp;move_to=next&amp;index_time=2014-09-17T23:07:35Z&amp;index_id=3", + "rel": "next", + "method": "GET" + }, + { + "href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/?start_time=2014-08-04T12:46:47-07:00&amp;end_time=2014-09-18T12:46:47-07:00&amp;page_size=2&amp;move_to=previous&amp;index_time=2014-09-17T23:07:35Z&amp;index_id=0", + "rel": "previous", + "method": "GET" + } + ] + } + } +} diff --git a/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testGet.json b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testGet.json new file mode 100644 index 0000000..d7e80f1 --- /dev/null +++ b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testGet.json @@ -0,0 +1,64 @@ +{ + "description":"Get a webhook", + "title":"Get a webhook", + "runnable":true, + "operationId":"webhooks.get", + "user":{ + "scopes":[ + "https://uri.paypal.com/services/applications/webhooks" + ] + }, + "credentials":{ + "oauth":{ + "path":"/v1/oauth/token", + "clientId":"", + "clientSecret":"" + } + }, + "request":{ + "path":"v1/notifications/webhooks/0EH40505U7160970P", + "method":"GET", + "headers":{ + "Content-Type":"application/json", + "Authorization":"Bearer ECvJ_yBNz_UfMmCvWEbT_2ZWXdzbFFQZ-1Y5K2NGgeHn" + } + }, + "response":{ + "status":"200", + "headers":{ + "Content-Type":"application/json", + "Paypal-Debug-id":"0c444abc1d12d" + }, + "body":{ + "id":"0EH40505U7160970P", + "url":"https://requestb.in/10ujt3c1", + "event_types":[ + { + "name":"PAYMENT.AUTHORIZATION.CREATED", + "description":"A payment authorization was created" + }, + { + "name":"PAYMENT.AUTHORIZATION.VOIDED", + "description":"A payment authorization was voided" + } + ], + "links":[ + { + "href":"https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel":"self", + "method":"GET" + }, + { + "href":"https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel":"update", + "method":"PATCH" + }, + { + "href":"https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel":"delete", + "method":"DELETE" + } + ] + } + } +} diff --git a/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testGetAll.json b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testGetAll.json new file mode 100644 index 0000000..ce274ef --- /dev/null +++ b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testGetAll.json @@ -0,0 +1,99 @@ +{ + "description":"Get all webhooks", + "title":"Get all webhook", + "runnable":true, + "operationId":"webhooks.get-all", + "user":{ + "scopes":[ + "https://uri.paypal.com/services/applications/webhooks" + ] + }, + "credentials":{ + "oauth":{ + "path":"/v1/oauth/token", + "clientId":"", + "clientSecret":"" + } + }, + "request":{ + "path":"v1/notifications/webhooks", + "method":"GET", + "headers":{ + "Content-Type":"application/json", + "Authorization":"Bearer ECvJ_yBNz_UfMmCvWEbT_2ZWXdzbFFQZ-1Y5K2NGgeHn" + } + }, + "response":{ + "status":"200", + "headers":{ + "Content-Type":"application/json", + "Paypal-Debug-id":"0c444abc1d12d" + }, + "body":{ + "webhooks":[ + { + "id":"40Y916089Y8324740", + "url":"http://www.ebay.com/paypal_webhook", + "event_types":[ + { + "name":"PAYMENT.AUTHORIZATION.CREATED", + "description":"A payment authorization was created" + }, + { + "name":"PAYMENT.AUTHORIZATION.VOIDED", + "description":"A payment authorization was voided" + } + ], + "links":[ + { + "href":"https://api.paypal.com/v1/notifications/webhooks/40Y916089Y8324740", + "rel":"self", + "method":"GET" + }, + { + "href":"https://api.paypal.com/v1/notifications/webhooks/40Y916089Y8324740", + "rel":"update", + "method":"PATCH" + }, + { + "href":"https://api.paypal.com/v1/notifications/webhooks/40Y916089Y8324740", + "rel":"delete", + "method":"DELETE" + } + ] + }, + { + "id":"0EH40505U7160970P", + "url":"http://www.ebay.com/another_paypal_webhook", + "event_types":[ + { + "name":"PAYMENT.AUTHORIZATION.CREATED", + "description":"A payment authorization was created" + }, + { + "name":"PAYMENT.AUTHORIZATION.VOIDED", + "description":"A payment authorization was voided" + } + ], + "links":[ + { + "href":"https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel":"self", + "method":"GET" + }, + { + "href":"https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel":"update", + "method":"PATCH" + }, + { + "href":"https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel":"delete", + "method":"DELETE" + } + ] + } + ] + } + } +} \ No newline at end of file diff --git a/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testGetEvent.json b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testGetEvent.json new file mode 100644 index 0000000..dcff480 --- /dev/null +++ b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testGetEvent.json @@ -0,0 +1,89 @@ +{ + "description":"Get a webhook event", + "title":"Get a webhook event", + "runnable":true, + "operationId":"event.get", + "user":{ + "scopes":[ + "https://uri.paypal.com/services/applications/webhooks" + ] + }, + "credentials":{ + "oauth":{ + "path":"v1/oauth/token", + "clientId":"", + "clientSecret":"" + } + }, + "request":{ + "path":"v1/notifications/webhooks-events/8PT597110X687430LKGECATA", + "method":"GET", + "headers":{ + "Content-Type":"application/json", + "Authorization":"Bearer ECvJ_yBNz_UfMmCvWEbT_2ZWXdzbFFQZ-1Y5K2NGgeHn" + } + }, + "response":{ + "status":"200", + "headers":{ + "Content-Type":"application/json", + "Paypal-Debug-id":"0c444abc1d12d" + }, + "body":{ + "id":"8PT597110X687430LKGECATA", + "create_time":"2013-06-25T21:41:28Z", + "resource_type":"authorization", + "trigger_event":"PAYMENT.AUTHORIZATION.CREATED", + "summary":"A payment authorization was created", + "resource":{ + "id":"2DC87612EK520411B", + "create_time":"2013-06-25T21:39:15Z", + "update_time":"2013-06-25T21:39:17Z", + "state":"authorized", + "amount":{ + "total":"7.47", + "currency":"USD", + "details":{ + "subtotal":"7.47" + } + }, + "parent_payment":"PAY-36246664YD343335CKHFA4AY", + "valid_until":"2013-07-24T21:39:15Z", + "links":[ + { + "href":"https://api.paypal.com/v1/payments/authorization/2DC87612EK520411B", + "rel":"self", + "method":"GET" + }, + { + "href":"https://api.paypal.com/v1/payments/authorization/2DC87612EK520411B/capture", + "rel":"capture", + "method":"POST" + }, + { + "href":"https://api.paypal.com/v1/payments/authorization/2DC87612EK520411B/void", + "rel":"void", + "method":"POST" + }, + { + "href":"https://api.paypal.com/v1/payments/payment/PAY-36246664YD343335CKHFA4AY", + "rel":"parent_payment", + "method":"GET" + } + ] + }, + "links":[ + { + "href":"https://api.paypal.com/v1/notfications/webhooks-events/8PT597110X687430LKGECATA", + "rel":"self", + "method":"GET" + }, + { + "href":"https://api.paypal.com/v1/notfications/webhooks-events/8PT597110X687430LKGECATA/resend", + "rel":"resend", + "method":"POST" + } + ] + } + } +} \ No newline at end of file diff --git a/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testUpdate.json b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testUpdate.json new file mode 100644 index 0000000..bc1a694 --- /dev/null +++ b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testUpdate.json @@ -0,0 +1,76 @@ +{ + "description":"Update a webhook", + "title":"Updated a webhook", + "runnable":true, + "operationId":"webhooks.update", + "user":{ + "scopes":[ + "https://uri.paypal.com/services/applications/webhooks" + ] + }, + "credentials":{ + "oauth":{ + "path":"/v1/oauth/token", + "clientId":"", + "clientSecret":"" + } + }, + "request":{ + "path":"v1/notifications/webhooks/0EH40505U7160970P", + "method":"PATCH", + "headers":{ + "Content-Type":"application/json", + "Authorization":"Bearer ECvJ_yBNz_UfMmCvWEbT_2ZWXdzbFFQZ-1Y5K2NGgeHn" + }, + "body":[ + { + "op":"replace", + "path":"/url", + "value":"https://requestb.in/10ujt3c1" + }, + { + "op":"replace", + "path":"/event_types", + "value":[ + { + "name":"PAYMENT.SALE.REFUNDED" + } + ] + } + ] + }, + "response":{ + "status":"200", + "headers":{ + "Content-Type":"application/json", + "Paypal-Debug-id":"0c444abc1d12d" + }, + "body":{ + "id":"0EH40505U7160970P", + "url":"https://requestb.in/10ujt3c1", + "event_types":[ + { + "name":"PAYMENT.SALE.REFUNDED", + "description":"A sale payment was refunded" + } + ], + "links":[ + { + "href":"https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel":"self", + "method":"GET" + }, + { + "href":"https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel":"update", + "method":"PATCH" + }, + { + "href":"https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel":"delete", + "method":"DELETE" + } + ] + } + } +} diff --git a/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/webhook_get_available_event_types.json b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/webhook_get_available_event_types.json new file mode 100644 index 0000000..04758d2 --- /dev/null +++ b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/webhook_get_available_event_types.json @@ -0,0 +1,56 @@ +{ + "description":"List of supported webhook events", + "title":"List of supported webhook events", + "runnable":true, + "operationId":"available-event-type.list", + "credentials":{ + "oauth":{ + "path":"/v1/oauth/token", + "clientId":"", + "clientSecret":"" + } + }, + "request":{ + "path":"v1/notifications/webhooks-event-types", + "method":"GET", + "headers":{ + "Content-Type":"application/json", + "Authorization":"Bearer ECvJ_yBNz_UfMmCvWEbT_2ZWXdzbFFQZ-1Y5K2NGgeHn" + } + }, + "response":{ + "status":"200", + "headers":{ + "Content-Type":"application/json", + "Paypal-Debug-id":"0c444abc1d12d" + }, + "body":{ + "event_types":[ + { + "name":"PAYMENT.AUTHORIZATION.CREATED", + "description":"A payment authorization was created" + }, + { + "name":"PAYMENT.AUTHORIZATION.VOIDED", + "description":"A payment authorization was voided" + }, + { + "name":"PAYMENT.CAPTURE.COMPLETED", + "description":"A capture payment was completed" + }, + { + "name":"PAYMENT.CAPTURE.REFUNDED", + "description":"A capture payment was refunded" + }, + { + "name":"PAYMENT.SALE.COMPLETED", + "description":"A sale payment was completed" + }, + { + "name":"PAYMENT.SALE.REFUNDED", + "description":"A sale payment was refunded" + } + ] + } + } +} \ No newline at end of file diff --git a/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/webhook_get_subscribed_event_types.json b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/webhook_get_subscribed_event_types.json new file mode 100644 index 0000000..eb09260 --- /dev/null +++ b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/webhook_get_subscribed_event_types.json @@ -0,0 +1,45 @@ +{ + "description":"Events subscribed for a webhook", + "title":"Events subscribed for a webhook", + "runnable":true, + "operationId":"webhook.subscribed-event-types.list", + "user":{ + "scopes":[ + "https://uri.paypal.com/services/applications/webhooks" + ] + }, + "credentials":{ + "oauth":{ + "path":"/v1/oauth/token", + "clientId":"", + "clientSecret":"" + } + }, + "request":{ + "path":"v1/notifications/webhooks/0EH40505U7160970P/event-types", + "method":"GET", + "headers":{ + "Content-Type":"application/json", + "Authorization":"Bearer ECvJ_yBNz_UfMmCvWEbT_2ZWXdzbFFQZ-1Y5K2NGgeHn" + } + }, + "response":{ + "status":"200", + "headers":{ + "Content-Type":"application/json", + "Paypal-Debug-id":"0c444abc1d12d" + }, + "body":{ + "event_types":[ + { + "name":"PAYMENT.AUTHORIZATION.CREATED", + "description":"A payment authorization was created" + }, + { + "name":"PAYMENT.AUTHORIZATION.VOIDED", + "description":"A payment authorization was voided" + } + ] + } + } +} \ No newline at end of file