Skip to content

Commit

Permalink
Merge pull request #198 from angelleye/PPL-161
Browse files Browse the repository at this point in the history
PPL-161
  • Loading branch information
Drew Angell authored Jun 2, 2019
2 parents 566cb48 + 498c8c9 commit c6bdb70
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 56 deletions.
18 changes: 4 additions & 14 deletions samples/rest/notifications/CreateWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,12 @@

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

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
$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_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.

$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,
Expand Down
8 changes: 6 additions & 2 deletions samples/rest/notifications/UpdateWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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(
Expand All @@ -25,7 +25,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.
)
);

Expand Down
47 changes: 20 additions & 27 deletions src/angelleye/PayPal/rest/notifications/NotificationsAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 3 additions & 13 deletions templates/rest/notifications/CreateWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,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
Expand Down

0 comments on commit c6bdb70

Please sign in to comment.