setUrl("https://requestb.in/10ujt3c1?uniqid=" . uniqid()); // # Event Types // Event types correspond to what kind of notifications you want to receive on the given URL. $webhookEventTypes = array(); $webhookEventTypes[] = new \PayPal\Api\WebhookEventType( '{ "name":"PAYMENT.AUTHORIZATION.CREATED" }' ); $webhookEventTypes[] = new \PayPal\Api\WebhookEventType( '{ "name":"PAYMENT.AUTHORIZATION.VOIDED" }' ); $webhook->setEventTypes($webhookEventTypes); // For Sample Purposes Only. $request = clone $webhook; // ### Create Webhook try { $output = $webhook->create($apiContext); } catch (Exception $ex) { // ^ Ignore workflow code segment if ($ex instanceof \PayPal\Exception\PayPalConnectionException) { $data = $ex->getData(); ResultPrinter::printError("Created Webhook Failed. Checking if it is Webhook Number Limit Exceeded. Trying to delete all existing webhooks", "Webhook", "Please Use Delete All Webhooks Sample to delete all existing webhooks in sample", $request, $ex); if (strpos($data,'WEBHOOK_NUMBER_LIMIT_EXCEEDED') !== false) { require 'DeleteAllWebhooks.php'; try { $output = $webhook->create($apiContext); } catch (Exception $ex) { ResultPrinter::printError("Created Webhook", "Webhook", null, $request, $ex); exit(1); } } else { ResultPrinter::printError("Created Webhook", "Webhook", null, $request, $ex); exit(1); } } else { ResultPrinter::printError("Created Webhook", "Webhook", null, $request, $ex); exit(1); } // Print Success Result } ResultPrinter::printResult("Created Webhook", "Webhook", $output->getId(), $request, $output); return $output;