Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PPL-161 #198

Merged
merged 3 commits into from
Jun 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions samples/rest/notifications/CreateWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,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 @@ -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(
Expand All @@ -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.
)
);

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 @@ -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
Expand Down