From d24a4afdb61b027cc344f378163f10f367adf835 Mon Sep 17 00:00:00 2001 From: japatel Date: Mon, 15 Dec 2014 13:52:00 -0600 Subject: [PATCH] Final Webhook Management API Changes - Updated Samples - Additional Functional Tests - Enabled Travis to do functional tests (with allowed failures) on each build --- .travis.yml | 4 + release_notes.md | 1 + sample/README.md | 4 +- sample/doc/assets/behavior.js | 117 ++++++++++++++++- .../notifications/SearchWebhookEvents.html | 2 + sample/doc/notifications/createWebhook.html | 6 +- .../payments/AuthorizePaymentUsingPayPal.html | 85 +++++++++++++ .../payments/CreatePaymentUsingPayPal.html | 2 +- sample/doc/payments/GetAuthorization.html | 8 +- sample/doc/payments/VoidAuthorization.html | 5 +- sample/header.html | 20 +-- sample/index.php | 37 +++++- sample/notifications/SearchWebhookEvents.php | 2 + sample/notifications/createWebhook.php | 4 + .../payments/AuthorizePaymentUsingPayPal.php | 120 ++++++++++++++++++ sample/payments/CreatePaymentUsingPayPal.php | 2 +- sample/payments/GetAuthorization.php | 8 +- sample/payments/VoidAuthorization.php | 5 +- .../Functional/Api/WebhookFunctionalTest.php | 41 +++++- .../WebhookFunctionalTest/testGetEvent.json | 4 +- ....json => testGetSubscribedEventTypes.json} | 0 21 files changed, 439 insertions(+), 38 deletions(-) create mode 100644 sample/doc/payments/AuthorizePaymentUsingPayPal.html create mode 100644 sample/payments/AuthorizePaymentUsingPayPal.php rename tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/{webhook_get_subscribed_event_types.json => testGetSubscribedEventTypes.json} (100%) diff --git a/.travis.yml b/.travis.yml index 53a172e..43fe4ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,13 @@ php: - 5.5 - 5.6 - hhvm +env: + - REST_MODE=mock + - REST_MODE=sandbox matrix: allow_failures: - php: hhvm + - env: REST_MODE=sandbox fast_finish: true before_script: - composer self-update diff --git a/release_notes.md b/release_notes.md index 8e0c99f..c9a4989 100644 --- a/release_notes.md +++ b/release_notes.md @@ -2,6 +2,7 @@ PayPal PHP SDK release notes ============================ v0.16.0 ---- +* Enabled Webhook Management Capabilities * Enabled Caching Abilities for Access Tokens v0.15.1 diff --git a/sample/README.md b/sample/README.md index 2997ce4..ce1e81a 100644 --- a/sample/README.md +++ b/sample/README.md @@ -49,8 +49,8 @@ The result would be as shown below: The sample comes pre-configured with a test account but in case you need to try them against your account, you must - * Obtain your client id and client secret from the developer portal - * Update the bootstrap.php file with your new client id and secret. + * Obtain your client id and client secret from the [developer portal](https://developer.paypal.com/webapps/developer/applications/myapps) + * Update the [bootstrap.php](https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/bootstrap.php#L29) file with your new client id and secret. #### More Help diff --git a/sample/doc/assets/behavior.js b/sample/doc/assets/behavior.js index 7bad080..1145214 100644 --- a/sample/doc/assets/behavior.js +++ b/sample/doc/assets/behavior.js @@ -1268,7 +1268,18 @@ 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 "title": "Basic Information", "slug": "basic-information" }, - "depth": 1 + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 4, + "title": "NOTE: Please note that you need an https url for paypal webhooks. You can however override the url with https, and accept", + "slug": "note-please-note-that-you-need-an-https-url-for-paypal-webhooks-you-can-however-override-the-url-with-https-and-accept" + }, + "depth": 4 + } + ] }, { "type": "heading", "data": { @@ -1988,6 +1999,110 @@ 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/payments/AuthorizePaymentUsingPayPal.php", + "projectPath": "payments/AuthorizePaymentUsingPayPal.php", + "targetPath": "payments/AuthorizePaymentUsingPayPal", + "pageTitle": "payments/AuthorizePaymentUsingPayPal", + "title": "AuthorizePaymentUsingPayPal" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Authorize Payment using PayPal as payment method", + "slug": "authorize-payment-using-paypal-as-payment-method" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Payer", + "slug": "payer" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Itemized information", + "slug": "itemized-information" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Additional payment details", + "slug": "additional-payment-details" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Amount", + "slug": "amount" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Transaction", + "slug": "transaction" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Redirect urls", + "slug": "redirect-urls" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payment", + "slug": "payment" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Create Payment", + "slug": "create-payment" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Get redirect url", + "slug": "get-redirect-url" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { diff --git a/sample/doc/notifications/SearchWebhookEvents.html b/sample/doc/notifications/SearchWebhookEvents.html index 6fafcca..558332e 100644 --- a/sample/doc/notifications/SearchWebhookEvents.html +++ b/sample/doc/notifications/SearchWebhookEvents.html @@ -6,6 +6,7 @@ API used: GET /v1/notifications/webhooks-events

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'; +use PayPal\Api\Authorization; $params = array(

'start_time'=>'2014-12-06T11:00:00Z', 'end_time'=>'2014-12-12T11:00:00Z'

);

Search Webhook events

try { @@ -17,4 +18,5 @@ for a webhook events. This is made in a sample just to make sure there is minimu 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 ddaa5cb..0199839 100644 --- a/sample/doc/notifications/createWebhook.html +++ b/sample/doc/notifications/createWebhook.html @@ -14,7 +14,11 @@ API used: POST /v1/notifications/webhooks

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

+The URL should be actually accessible over the internet. Having a localhost here would not work.

+

There is an open source tool http://requestb.in/ that allows you to receive any web requests to a url given there.

+

NOTE: Please note that you need an https url for paypal webhooks. You can however override the url with https, and accept

+

any warnings your browser might show you. Also, please note that this is entirely for demo purposes, and you should not +be using this in production

$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( '{ diff --git a/sample/doc/payments/AuthorizePaymentUsingPayPal.html b/sample/doc/payments/AuthorizePaymentUsingPayPal.html new file mode 100644 index 0000000..892d214 --- /dev/null +++ b/sample/doc/payments/AuthorizePaymentUsingPayPal.html @@ -0,0 +1,85 @@ +payments/AuthorizePaymentUsingPayPal
payments/AuthorizePaymentUsingPayPal.php
<?php

Authorize Payment using PayPal as payment method

+

This sample code demonstrates how you can process a +PayPal Account based Payment. +API used: /v1/payments/payment +As you can see, there is only one difference between creating a payment using PayPal with sale or authorize as intent. +You need to set the proper intent in the request, and the remaining data would be the same

require __DIR__ . '/../bootstrap.php'; +use PayPal\Api\Amount; +use PayPal\Api\Details; +use PayPal\Api\Item; +use PayPal\Api\ItemList; +use PayPal\Api\Payer; +use PayPal\Api\Payment; +use PayPal\Api\RedirectUrls; +use PayPal\Api\Transaction;

Payer

+

A resource representing a Payer that funds a payment +For paypal account payments, set payment method +to 'paypal'.

$payer = new Payer(); +$payer->setPaymentMethod("paypal");

Itemized information

+

(Optional) Lets you specify item wise +information

$item1 = new Item(); +$item1->setName('Ground Coffee 40 oz') + ->setCurrency('USD') + ->setQuantity(1) + ->setPrice(7.5); +$item2 = new Item(); +$item2->setName('Granola bars') + ->setCurrency('USD') + ->setQuantity(5) + ->setPrice(2); + +$itemList = new ItemList(); +$itemList->setItems(array($item1, $item2));

Additional payment details

+

Use this optional field to set additional +payment information such as tax, shipping +charges etc.

$details = new Details(); +$details->setShipping(1.2) + ->setTax(1.3) + ->setSubtotal(17.50);

Amount

+

Lets you specify a payment amount. +You can also specify additional details +such as shipping, tax.

$amount = new Amount(); +$amount->setCurrency("USD") + ->setTotal(20) + ->setDetails($details);

Transaction

+

A transaction defines the contract of a +payment - what is the payment for and who +is fulfilling it.

$transaction = new Transaction(); +$transaction->setAmount($amount) + ->setItemList($itemList) + ->setDescription("Payment description") + ->setInvoiceNumber(uniqid());

Redirect urls

+

Set the urls that the buyer must be redirected to after +payment approval/ cancellation.

$baseUrl = getBaseUrl(); +$redirectUrls = new RedirectUrls(); +$redirectUrls->setReturnUrl("$baseUrl/ExecutePayment.php?success=true") + ->setCancelUrl("$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("authorize") + ->setPayer($payer) + ->setRedirectUrls($redirectUrls) + ->setTransactions(array($transaction));

For Sample Purposes Only.

$request = clone $payment;

Create Payment

+

Create a payment by calling the 'create' method +passing it a valid apiContext. +(See bootstrap.php for more on ApiContext) +The return object contains the state and the +url to which the buyer must be redirected to +for payment approval

try { + $payment->create($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Created Payment Authorization Using PayPal. Please visit the URL to Authorize.", "Payment", null, $request, $ex); + exit(1); +}

Get redirect url

+

The API response provides the url that you must redirect +the buyer to. Retrieve the url from the $payment->getLinks() +method

foreach ($payment->getLinks() as $link) { + if ($link->getRel() == 'approval_url') { + $approvalUrl = $link->getHref(); + break; + } +} + +ResultPrinter::printResult("Created Payment Authorization Using PayPal. Please visit the URL to Authorize.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment); + +return $payment;
\ No newline at end of file diff --git a/sample/doc/payments/CreatePaymentUsingPayPal.html b/sample/doc/payments/CreatePaymentUsingPayPal.html index 7815864..1f604b8 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("authorize") +$payment->setIntent("sale") ->setPayer($payer) ->setRedirectUrls($redirectUrls) ->setTransactions(array($transaction));

For Sample Purposes Only.

$request = clone $payment;

Create Payment

diff --git a/sample/doc/payments/GetAuthorization.html b/sample/doc/payments/GetAuthorization.html index ae1c4ab..2121362 100644 --- a/sample/doc/payments/GetAuthorization.html +++ b/sample/doc/payments/GetAuthorization.html @@ -3,18 +3,18 @@ of an authorized payment. API used: /v1/payments/authorization/<$authorizationId>

/** @var Authorization $authorization */ $authorization = require 'AuthorizePayment.php'; - +$authorizationId = '4U805254HC285294Y'; // $authorization->getId(); use PayPal\Api\Authorization; use PayPal\Api\Payment;

GetAuthorization

You can retrieve info about an Authorization by invoking the Authorization::get method with a valid ApiContext (See bootstrap.php for more on ApiContext) -The return object contains the authorization state.

try {

Retrieve the authorization

$result = Authorization::get($authorization->getId(), $apiContext); +The return object contains the authorization state.

try {

Retrieve the authorization

$result = Authorization::get($authorizationId, $apiContext); } catch (Exception $ex) { ResultPrinter::printError("Get Authorization", "Authorization", null, null, $ex); exit(1); } -ResultPrinter::printResult("Get Authorization", "Authorization", $authorization->getId(), null, $result); +ResultPrinter::printResult("Get Authorization", "Authorization", $authorizationId, null, $result); -return $authorization;
\ No newline at end of file +return $result; \ No newline at end of file diff --git a/sample/doc/payments/VoidAuthorization.html b/sample/doc/payments/VoidAuthorization.html index 63d97c7..219f453 100644 --- a/sample/doc/payments/VoidAuthorization.html +++ b/sample/doc/payments/VoidAuthorization.html @@ -2,12 +2,11 @@

This sample code demonstrates how you can void an authorized payment. API used: /v1/payments/authorization/<{authorizationid}>/void"

/** @var Authorization $authorization */ -$authorization = require 'AuthorizePayment.php'; - +$authorization = require 'AuthorizePayment.php';

Replace $authorizationid with any static Id you might already have. It will do a void on it

$authorizationId = '1BF65516U6866543H'; // $authorization->getId(); use PayPal\Api\Authorization;

VoidAuthorization

You can void a previously authorized payment by invoking the $authorization->void method -with a valid ApiContext (See bootstrap.php for more on ApiContext)

try {

Lookup the authorization

$authorization = Authorization::get($authorization->getId(), $apiContext);

Void the authorization

$voidedAuth = $authorization->void($apiContext); +with a valid ApiContext (See bootstrap.php for more on ApiContext)

try {

Lookup the authorization

$authorization = Authorization::get($authorizationId, $apiContext);

Void the authorization

$voidedAuth = $authorization->void($apiContext); } catch (Exception $ex) { ResultPrinter::printError("Void Authorization", "Authorization", null, null, $ex); exit(1); diff --git a/sample/header.html b/sample/header.html index c6966ef..bb1ba3b 100644 --- a/sample/header.html +++ b/sample/header.html @@ -81,13 +81,14 @@ color: #FFF; text-decoration: none; } - /* - .string { color: green; } + + .string { color: #428bca; } .number { color: darkorange; } .boolean { color: blue; } .null { color: magenta; } - .key { color: red; } - */ + .key { color: slategray; font-weight: bold; } + .id { color: red; } + - +
@@ -315,6 +315,18 @@ if (PHP_SAPI == 'cli') {
+
  • +
    +
    Authorize Payment Using PayPal
    + +
    +
  • Get details of an authorized payment
    @@ -794,7 +806,7 @@ if (PHP_SAPI == 'cli') { Try It - Source Source
  • @@ -805,7 +817,7 @@ if (PHP_SAPI == 'cli') {
    @@ -817,7 +829,7 @@ if (PHP_SAPI == 'cli') { Try It - Source + Source
    @@ -830,7 +842,7 @@ if (PHP_SAPI == 'cli') { Try It - Source Source @@ -841,7 +853,18 @@ if (PHP_SAPI == 'cli') { + + +
  • +
    +
    Delete all webhooks
    +
    @@ -852,7 +875,7 @@ if (PHP_SAPI == 'cli') { diff --git a/sample/notifications/SearchWebhookEvents.php b/sample/notifications/SearchWebhookEvents.php index 86d8898..444949b 100644 --- a/sample/notifications/SearchWebhookEvents.php +++ b/sample/notifications/SearchWebhookEvents.php @@ -12,6 +12,7 @@ // 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'; +use PayPal\Api\Authorization; $params = array( // 'start_time'=>'2014-12-06T11:00:00Z', @@ -28,4 +29,5 @@ try { ResultPrinter::printResult("Search Webhook events", "WebhookEventList", null, $params, $output); + return $output; diff --git a/sample/notifications/createWebhook.php b/sample/notifications/createWebhook.php index 2c1a749..af87d4c 100644 --- a/sample/notifications/createWebhook.php +++ b/sample/notifications/createWebhook.php @@ -25,6 +25,10 @@ $webhook = new \PayPal\Api\Webhook(); // } // 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. +// #### There is an open source tool http://requestb.in/ that allows you to receive any web requests to a url given there. +// #### NOTE: Please note that you need an https url for paypal webhooks. You can however override the url with https, and accept +// any warnings your browser might show you. Also, please note that this is entirely for demo purposes, and you should not +// be using this in production $webhook->setUrl("https://requestb.in/10ujt3c1?uniqid=" . uniqid()); // # Event Types diff --git a/sample/payments/AuthorizePaymentUsingPayPal.php b/sample/payments/AuthorizePaymentUsingPayPal.php new file mode 100644 index 0000000..3c5f2c3 --- /dev/null +++ b/sample/payments/AuthorizePaymentUsingPayPal.php @@ -0,0 +1,120 @@ +setPaymentMethod("paypal"); + +// ### Itemized information +// (Optional) Lets you specify item wise +// information +$item1 = new Item(); +$item1->setName('Ground Coffee 40 oz') + ->setCurrency('USD') + ->setQuantity(1) + ->setPrice(7.5); +$item2 = new Item(); +$item2->setName('Granola bars') + ->setCurrency('USD') + ->setQuantity(5) + ->setPrice(2); + +$itemList = new ItemList(); +$itemList->setItems(array($item1, $item2)); + +// ### Additional payment details +// Use this optional field to set additional +// payment information such as tax, shipping +// charges etc. +$details = new Details(); +$details->setShipping(1.2) + ->setTax(1.3) + ->setSubtotal(17.50); + +// ### Amount +// Lets you specify a payment amount. +// You can also specify additional details +// such as shipping, tax. +$amount = new Amount(); +$amount->setCurrency("USD") + ->setTotal(20) + ->setDetails($details); + +// ### Transaction +// A transaction defines the contract of a +// payment - what is the payment for and who +// is fulfilling it. +$transaction = new Transaction(); +$transaction->setAmount($amount) + ->setItemList($itemList) + ->setDescription("Payment description") + ->setInvoiceNumber(uniqid()); + +// ### Redirect urls +// Set the urls that the buyer must be redirected to after +// payment approval/ cancellation. +$baseUrl = getBaseUrl(); +$redirectUrls = new RedirectUrls(); +$redirectUrls->setReturnUrl("$baseUrl/ExecutePayment.php?success=true") + ->setCancelUrl("$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("authorize") + ->setPayer($payer) + ->setRedirectUrls($redirectUrls) + ->setTransactions(array($transaction)); + + +// For Sample Purposes Only. +$request = clone $payment; + +// ### Create Payment +// Create a payment by calling the 'create' method +// passing it a valid apiContext. +// (See bootstrap.php for more on `ApiContext`) +// The return object contains the state and the +// url to which the buyer must be redirected to +// for payment approval +try { + $payment->create($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Created Payment Authorization Using PayPal. Please visit the URL to Authorize.", "Payment", null, $request, $ex); + exit(1); +} + +// ### Get redirect url +// The API response provides the url that you must redirect +// the buyer to. Retrieve the url from the $payment->getLinks() +// method +foreach ($payment->getLinks() as $link) { + if ($link->getRel() == 'approval_url') { + $approvalUrl = $link->getHref(); + break; + } +} + +ResultPrinter::printResult("Created Payment Authorization Using PayPal. Please visit the URL to Authorize.", "Payment", "$approvalUrl", $request, $payment); + +return $payment; diff --git a/sample/payments/CreatePaymentUsingPayPal.php b/sample/payments/CreatePaymentUsingPayPal.php index 5ffd62c..029f61b 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("authorize") +$payment->setIntent("sale") ->setPayer($payer) ->setRedirectUrls($redirectUrls) ->setTransactions(array($transaction)); diff --git a/sample/payments/GetAuthorization.php b/sample/payments/GetAuthorization.php index e2ee117..2a7185d 100644 --- a/sample/payments/GetAuthorization.php +++ b/sample/payments/GetAuthorization.php @@ -6,7 +6,7 @@ /** @var Authorization $authorization */ $authorization = require 'AuthorizePayment.php'; - +$authorizationId = '4U805254HC285294Y'; // $authorization->getId(); use PayPal\Api\Authorization; use PayPal\Api\Payment; @@ -18,12 +18,12 @@ use PayPal\Api\Payment; try { // Retrieve the authorization - $result = Authorization::get($authorization->getId(), $apiContext); + $result = Authorization::get($authorizationId, $apiContext); } catch (Exception $ex) { ResultPrinter::printError("Get Authorization", "Authorization", null, null, $ex); exit(1); } -ResultPrinter::printResult("Get Authorization", "Authorization", $authorization->getId(), null, $result); +ResultPrinter::printResult("Get Authorization", "Authorization", $authorizationId, null, $result); -return $authorization; +return $result; diff --git a/sample/payments/VoidAuthorization.php b/sample/payments/VoidAuthorization.php index 04690e9..bdd8559 100644 --- a/sample/payments/VoidAuthorization.php +++ b/sample/payments/VoidAuthorization.php @@ -6,7 +6,8 @@ /** @var Authorization $authorization */ $authorization = require 'AuthorizePayment.php'; - +// Replace $authorizationid with any static Id you might already have. It will do a void on it +$authorizationId = '1BF65516U6866543H'; // $authorization->getId(); use PayPal\Api\Authorization; @@ -17,7 +18,7 @@ use PayPal\Api\Authorization; try { // Lookup the authorization - $authorization = Authorization::get($authorization->getId(), $apiContext); + $authorization = Authorization::get($authorizationId, $apiContext); // Void the authorization $voidedAuth = $authorization->void($apiContext); diff --git a/tests/PayPal/Test/Functional/Api/WebhookFunctionalTest.php b/tests/PayPal/Test/Functional/Api/WebhookFunctionalTest.php index eef42ed..1f916e6 100644 --- a/tests/PayPal/Test/Functional/Api/WebhookFunctionalTest.php +++ b/tests/PayPal/Test/Functional/Api/WebhookFunctionalTest.php @@ -12,7 +12,11 @@ use PayPal\Api\Sale; use PayPal\Api\Webhook; use PayPal\Api\WebhookEvent; use PayPal\Api\WebhookEventList; +use PayPal\Api\WebhookEventType; +use PayPal\Api\WebhookEventTypeList; +use PayPal\Api\WebhookList; use PayPal\Common\PPModel; +use PayPal\Exception\PPConnectionException; use PayPal\Rest\ApiContext; use PayPal\Rest\IResource; use PayPal\Api\CreateProfileResponse; @@ -62,11 +66,30 @@ class WebhookFunctionalTest extends \PHPUnit_Framework_TestCase $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); + $result = null; + try { + $result = $obj->create(null, $this->mockPPRestCall); + } catch (PPConnectionException $ex) { + $data = $ex->getData(); + if (strpos($data,'WEBHOOK_NUMBER_LIMIT_EXCEEDED') !== false) { + $this->deleteAll(); + $result = $obj->create(null, $this->mockPPRestCall); + } else { + $this->fail($ex->getMessage()); + } + } $this->assertNotNull($result); return $result; } + public function deleteAll() + { + $result = Webhook::getAll(null, $this->mockPPRestCall); + foreach ($result->getWebhooks() as $webhookObject) { + $webhookObject->delete(null, $this->mockPPRestCall); + } + } + /** * @depends testCreate * @param $webhook Webhook @@ -84,6 +107,20 @@ class WebhookFunctionalTest extends \PHPUnit_Framework_TestCase /** * @depends testGet * @param $webhook Webhook + * @return WebhookEventTypeList + */ + public function testGetSubscribedEventTypes($webhook) + { + $result = WebhookEventType::subscribedEventTypes($webhook->getId(), null, $this->mockPPRestCall); + $this->assertNotNull($result); + $this->assertEquals(2, sizeof($result->getEventTypes())); + return $result; + } + + /** + * @depends testGet + * @param $webhook Webhook + * @return WebhookList */ public function testGetAll($webhook) { @@ -100,7 +137,7 @@ class WebhookFunctionalTest extends \PHPUnit_Framework_TestCase } $this->assertTrue($found, "The Created Web Profile was not found in the get list"); $this->assertEquals($webhook->getId(), $foundObject->getId()); - + return $result; } /** diff --git a/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testGetEvent.json b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testGetEvent.json index dcff480..4bc244c 100644 --- a/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testGetEvent.json +++ b/tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testGetEvent.json @@ -33,7 +33,7 @@ "id":"8PT597110X687430LKGECATA", "create_time":"2013-06-25T21:41:28Z", "resource_type":"authorization", - "trigger_event":"PAYMENT.AUTHORIZATION.CREATED", + "event_type":"PAYMENT.AUTHORIZATION.CREATED", "summary":"A payment authorization was created", "resource":{ "id":"2DC87612EK520411B", @@ -86,4 +86,4 @@ ] } } -} \ 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/testGetSubscribedEventTypes.json similarity index 100% rename from tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/webhook_get_subscribed_event_types.json rename to tests/PayPal/Test/Functional/resources/WebhookFunctionalTest/testGetSubscribedEventTypes.json