From a2efbe1c18135afe72b99a2699a601ea55ba9173 Mon Sep 17 00:00:00 2001 From: tejas Date: Tue, 14 May 2019 11:03:57 +0530 Subject: [PATCH 1/3] PPL-161 , Adjustments to the code for notifications listing,. --- samples/rest/notifications/CreateWebhook.php | 15 +++------------ .../rest/notifications/NotificationsAPI.php | 2 +- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/samples/rest/notifications/CreateWebhook.php b/samples/rest/notifications/CreateWebhook.php index 71c3b29f..cdc97427 100644 --- a/samples/rest/notifications/CreateWebhook.php +++ b/samples/rest/notifications/CreateWebhook.php @@ -13,20 +13,11 @@ $PayPal = new \angelleye\PayPal\rest\notifications\NotificationsAPI($configArray); -$event_types = array(); - -$event_type_1 = array( - 'Name' => 'VAULT.CREDIT-CARD.CREATED', // The unique event name. You can fine list of webhooks name in PayPal_Webhooks.txt +$event_types = array( + 'VAULT.CREDIT-CARD.CREATED', // The unique event name. You can fine list of webhooks name in PayPal_Webhooks.txt + 'VAULT.CREDIT-CARD.DELETED' // The unique event name. You can fine list of webhooks name in PayPal_Webhooks.txt ); -array_push($event_types, $event_type_1); - -$event_type_2 = array( - 'Name' => 'VAULT.CREDIT-CARD.DELETED', // The unique event name. You can fine list of webhooks name in PayPal_Webhooks.txt -); - -array_push($event_types, $event_type_2); - $url = "https://requestb.in/10ujt3c1?uniqid=" . uniqid(); // The URL that is configured to listen on localhost for incoming POST notification messages that contain event information. diff --git a/src/angelleye/PayPal/rest/notifications/NotificationsAPI.php b/src/angelleye/PayPal/rest/notifications/NotificationsAPI.php index aaa48947..377b9c9c 100644 --- a/src/angelleye/PayPal/rest/notifications/NotificationsAPI.php +++ b/src/angelleye/PayPal/rest/notifications/NotificationsAPI.php @@ -81,7 +81,7 @@ public function CreateWebhook($requestData){ $webhookEventTypes = array(); foreach ($requestData['EventTypes'] as $value) { $type = new WebhookEventType(); - $type->setName($value['Name']); + $type->setName($value); $webhookEventTypes[] = $type; } $webhook->setEventTypes($webhookEventTypes); From cd44b785696c492e803613053facabc7d89deb89 Mon Sep 17 00:00:00 2001 From: tejas Date: Tue, 14 May 2019 11:06:15 +0530 Subject: [PATCH 2/3] PPL-161 , adjustments to templates also. --- templates/rest/notifications/CreateWebhook.php | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/templates/rest/notifications/CreateWebhook.php b/templates/rest/notifications/CreateWebhook.php index 129a50bc..1bbe5ee2 100644 --- a/templates/rest/notifications/CreateWebhook.php +++ b/templates/rest/notifications/CreateWebhook.php @@ -13,23 +13,13 @@ $PayPal = new \angelleye\PayPal\rest\notifications\NotificationsAPI($configArray); -$event_types = array(); - -$event_type_1 = array( - 'Name' => '', // The unique event name. You can fine list of webhooks name in PayPal_Webhooks.txt -); - -array_push($event_types, $event_type_1); - -$event_type_2 = array( - 'Name' => '', // The unique event name. You can fine list of webhooks name in PayPal_Webhooks.txt +$event_types = array( + '', // The unique event name. You can fine list of webhooks name in PayPal_Webhooks.txt + '' ); -array_push($event_types, $event_type_2); - $url = ""; // The URL that is configured to listen on localhost for incoming POST notification messages that contain event information. - $requestData = array( 'Url' => $url, 'EventTypes' => $event_types From 498c8c9123d27cadd8d86725ffd7daf492decaec Mon Sep 17 00:00:00 2001 From: tejas Date: Tue, 14 May 2019 15:27:00 +0530 Subject: [PATCH 3/3] PPL-161 , added code to update webhook in a optimized way. --- samples/rest/notifications/CreateWebhook.php | 3 +- samples/rest/notifications/UpdateWebhook.php | 8 +++- .../rest/notifications/NotificationsAPI.php | 45 ++++++++----------- 3 files changed, 26 insertions(+), 30 deletions(-) diff --git a/samples/rest/notifications/CreateWebhook.php b/samples/rest/notifications/CreateWebhook.php index cdc97427..0f1ba072 100644 --- a/samples/rest/notifications/CreateWebhook.php +++ b/samples/rest/notifications/CreateWebhook.php @@ -18,8 +18,7 @@ 'VAULT.CREDIT-CARD.DELETED' // The unique event name. You can fine list of webhooks name in PayPal_Webhooks.txt ); -$url = "https://requestb.in/10ujt3c1?uniqid=" . uniqid(); // The URL that is configured to listen on localhost for incoming POST notification messages that contain event information. - +$url = "https://dev.aetesting.xyz/?angelleye_paypal_webhooks&action=webhook_handler"; // The URL that is configured to listen on localhost for incoming POST notification messages that contain event information. $requestData = array( 'Url' => $url, diff --git a/samples/rest/notifications/UpdateWebhook.php b/samples/rest/notifications/UpdateWebhook.php index 93d6adbb..0a1cfcae 100644 --- a/samples/rest/notifications/UpdateWebhook.php +++ b/samples/rest/notifications/UpdateWebhook.php @@ -13,7 +13,7 @@ $PayPal = new \angelleye\PayPal\rest\notifications\NotificationsAPI($configArray); -$webhook_id = '8EL46366UX208650W'; // The ID of the webhook to update. +$webhook_id = '9F037003R3934961K'; // The ID of the webhook to update. $requestData = array( array( @@ -24,7 +24,11 @@ array( 'Op' => 'replace', // The operation to complete. Valid Values: ["add", "remove", "replace", test"] 'Path' => '/event_types', // The JSON pointer to the target document location at which to complete the operation. - 'Value' => 'PAYMENT.SALE.REFUNDED' // The value to apply. The remove operation does not require a value. + 'Value' => array( + 'PAYMENT.SALE.REFUNDED', + 'PAYMENT.SALE.REVERSED', + 'RISK.DISPUTE.CREATED' + ) // The value to apply. The remove operation does not require a value. ) ); diff --git a/src/angelleye/PayPal/rest/notifications/NotificationsAPI.php b/src/angelleye/PayPal/rest/notifications/NotificationsAPI.php index 377b9c9c..3f322614 100644 --- a/src/angelleye/PayPal/rest/notifications/NotificationsAPI.php +++ b/src/angelleye/PayPal/rest/notifications/NotificationsAPI.php @@ -172,35 +172,28 @@ public function UpdateWebhook($webhook_id,$requestData){ $webhook = new Webhook(); $pathRequest = new \PayPal\Api\PatchRequest(); try { - $webhook->setId($webhook_id); + $webhook->setId($webhook_id); $i=0; - foreach ($requestData as $value) { - if(is_array($value['Value'])){ - if(!empty($value['Op']) && !empty($value['Path']) && count($value['Value'])>3){ - $ob=(object) array_filter($value['Value']); - $pathOperation = new \PayPal\Api\Patch(); - $pathOperation->setOp($value['Op']) - ->setPath($value['Path']) - ->setValue($ob); - $pathRequest->addPatch($pathOperation); - $i++; + foreach ($requestData as $value) { + if(!empty($value['Op']) && !empty($value['Path']) && !empty($value['Value'])){ + $pathOperation = new \PayPal\Api\Patch(); + $pathOperation->setOp($value['Op']) + ->setPath($value['Path']); + if($value['Path'] == '/event_types'){ + $webhookEventTypes = array(); + foreach($value['Value'] as $event){ + $type = new WebhookEventType(); + $type->setName($event); + $webhookEventTypes[] = $type->toArray(); + } + $pathOperation->setValue($webhookEventTypes); } - } - else{ - if(!empty($value['Op']) && !empty($value['Path']) && !empty($value['Value'])){ - $pathOperation = new \PayPal\Api\Patch(); - $pathOperation->setOp($value['Op']) - ->setPath($value['Path']); - if($value['Path'] == '/event_types'){ - $pathOperation->setValue(json_decode('[{"name":"'.$value['Value'].'"}]')); - } - else{ - $pathOperation->setValue($value['Value']); - } - $pathRequest->addPatch($pathOperation); - $i++; + else{ + $pathOperation->setValue($value['Value']); } - } + $pathRequest->addPatch($pathOperation); + $i++; + } } if($i>0) {