One or more webhook objects.
Inheritance: extends PayPal\Common\PayPalResourceModel
 /**
  * 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.");
 }
Exemple #2
0
 /**
  * Shows details for a webhook, by ID.
  *
  * @param string $webhookId
  * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
  * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
  * @return Webhook
  */
 public static function get($webhookId, $apiContext = null, $restCall = null)
 {
     ArgumentValidator::validate($webhookId, 'webhookId');
     $payLoad = "";
     $json = self::executeCall("/v1/notifications/webhooks/{$webhookId}", "GET", $payLoad, null, $apiContext, $restCall);
     $ret = new Webhook();
     $ret->fromJson($json);
     return $ret;
 }
 /**
  * @dataProvider mockProvider
  * @param Webhook $obj
  */
 public function testDelete($obj, $mockApiContext)
 {
     $mockPayPalRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock();
     $mockPayPalRestCall->expects($this->any())->method('execute')->will($this->returnValue(true));
     $result = $obj->delete($mockApiContext, $mockPayPalRestCall);
     $this->assertNotNull($result);
 }
Exemple #4
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;
 }
<?php

// # Get Webhook Sample
//
// This sample code demonstrate how you can get a webhook, as documented here at:
// https://developer.paypal.com/webapps/developer/docs/api/#get-a-webhook
// API used: GET /v1/notifications/webhooks/<Webhook-Id>
// ## Get Webhook ID.
// In samples we are using CreateWebhook.php sample to get the created instance of webhook.
// However, in real case scenario, we could use just the ID from database or retrieved from the form.
/** @var \PayPal\Api\Webhook $webhook */
$webhook = (require 'CreateWebhook.php');
$webhookId = $webhook->getId();
// ### Get Webhook
try {
    $output = \PayPal\Api\Webhook::get($webhookId, $apiContext);
} catch (Exception $ex) {
    ResultPrinter::printError("Get a Webhook", "Webhook", null, $webhookId, $ex);
    exit(1);
}
ResultPrinter::printResult("Get a Webhook", "Webhook", $output->getId(), null, $output);
return $output;
 function delete_webhook($id)
 {
     // auth
     $apiContext = $this->apiContext();
     // set webhooks
     $webhook = new Webhook();
     try {
         $WebhookList = $webhook->get($id, $apiContext);
         $valid = true;
     } catch (Exception $ex) {
         $this->LoggingManager->log(print_r($ex, true), 'DEBUG');
         $valid = false;
     }
     if ($valid === true) {
         try {
             $WebhookList->delete($apiContext);
         } catch (Exception $ex) {
             $this->LoggingManager->log(print_r($ex, true), 'DEBUG');
         }
     }
     $avaliable_data = $this->available_webhooks();
     for ($i = 0, $n = count($avaliable_data); $i < $n; $i++) {
         $this->delete_config($avaliable_data[$i]['name']);
     }
 }