getAll() public static method

Retrieves all Webhooks for the application associated with access token.
Deprecation: Please use Webhook#getAllWithParams instead.
public static getAll ( ApiContext $apiContext = null, PayPalRestCall $restCall = null ) : WebhookList
$apiContext PayPal\Rest\ApiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
$restCall PayPalRestCall is the Rest Call Service that is used to make rest calls
return WebhookList
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     if (Config::get("customer_portal.paypal_enabled") !== true) {
         $this->error("PayPal is not enabled in the customer portal configuration.");
         return;
     }
     $apiContext = new ApiContext(new OAuthTokenCredential(Config::get("customer_portal.paypal_api_client_id"), Config::get("customer_portal.paypal_api_client_secret")));
     $apiContext->setConfig(['mode' => 'live', 'log.LogEnabled' => true, 'log.FileName' => storage_path("logs/paypal.log"), 'log.LogLevel' => 'ERROR']);
     try {
         Webhook::getAll($apiContext);
     } catch (Exception $e) {
         $this->error("Credentials failed! Please make sure this is a LIVE account and not a SANDBOX account and try again.");
         $this->error("Specific error was: {$e->getMessage()}");
         return;
     }
     $this->info("Credentials tested successfully.");
 }
 /**
  * @dataProvider mockProvider
  * @param Webhook $obj
  */
 public function testGetAll($obj, $mockApiContext)
 {
     $mockPayPalRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock();
     $mockPayPalRestCall->expects($this->any())->method('execute')->will($this->returnValue(WebhookListTest::getJson()));
     $result = $obj->getAll($mockApiContext, $mockPayPalRestCall);
     $this->assertNotNull($result);
 }
Esempio n. 3
0
<?php

// # Get All Webhooks Sample
//
// Use this call to list all the webhooks, as documented here at:
// https://developer.paypal.com/webapps/developer/docs/api/#list-all-webhooks
// API used: GET /v1/notifications/webhooks
// ## List Webhooks
// This step is not necessarily required. We are creating a webhook for sample purpose only, so that we would not
// get an empty list at any point.
// In real case, you dont need to create any webhook to make this API call.
/** @var \PayPal\Api\Webhook $webhook */
$webhook = (require_once __DIR__ . '/../bootstrap.php');
// ### Get List of All Webhooks
try {
    $output = \PayPal\Api\Webhook::getAll($apiContext);
} catch (Exception $ex) {
    // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
    ResultPrinter::printError("List all webhooks", "WebhookList", null, $webhookId, $ex);
    exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("List all webhooks", "WebhookList", null, null, $output);
return $output;
 /**
  * @depends testGet
  * @param $webhook Webhook
  * @return WebhookList
  */
 public function testGetAll($webhook)
 {
     $result = Webhook::getAll($this->apiContext, $this->mockPayPalRestCall);
     $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());
     return $result;
 }
 function list_webhooks()
 {
     // auth
     $apiContext = $this->apiContext();
     // set webhooks
     $webhooks = new Webhook();
     try {
         $WebhookList = $webhooks->getAll($apiContext);
         $valid = true;
     } catch (Exception $ex) {
         $this->LoggingManager->log(print_r($ex, true), 'DEBUG');
         $valid = false;
     }
     // set array
     $list_array = array();
     if ($valid === true) {
         $webhooks = $WebhookList->getWebhooks();
         for ($w = 0, $z = count($webhooks); $w < $z; $w++) {
             $eventtypes = $webhooks[$w]->getEventTypes();
             $list_array[$w]['id'] = $webhooks[$w]->getId();
             $list_array[$w]['url'] = $webhooks[$w]->getUrl();
             for ($i = 0, $n = count($eventtypes); $i < $n; $i++) {
                 $list_array[$w]['data'][] = array('name' => $eventtypes[$i]->getName(), 'description' => $eventtypes[$i]->getDescription(), 'orders_status' => $this->get_config($eventtypes[$i]->getName()));
             }
         }
     }
     return $list_array;
 }