/** * Creates a webhook * * @return bool|\PayPal\Api\Webhook */ public function createWebhook() { $webhook = new \PayPal\Api\Webhook(); $webhook->setUrl(Mage::helper('iways_paypalplus')->getWebhooksUrl()); $webhookEventTypes = array(); foreach (Mage::getModel('iways_paypalplus/webhook_event')->getSupportedWebhookEvents() as $webhookEvent) { $webhookEventType = new \PayPal\Api\WebhookEventType(); $webhookEventType->setName($webhookEvent); $webhookEventTypes[] = $webhookEventType; } $webhook->setEventTypes($webhookEventTypes); try { $webhookData = $webhook->create($this->_apiContext); $this->saveWebhookId($webhookData->getId()); return $webhookData; } catch (PayPal\Exception\PayPalConnectionException $ex) { if ($ex->getData()) { $data = Mage::helper('core')->jsonDecode($ex->getData()); if ($data['name'] == self::WEBHOOK_URL_ALREADY_EXISTS) { return true; } } Mage::helper('iways_paypalplus')->handleException($ex); return false; } catch (Exception $e) { Mage::logException($e); return false; } return false; }
/** * Creates a webhook * * @return bool|\PayPal\Api\Webhook */ public function createWebhook() { $webhook = new \PayPal\Api\Webhook(); $webhook->setUrl(Mage::helper('iways_paypalplus')->getWebhooksUrl()); $webhookEventTypes = array(); foreach (Mage::getModel('iways_paypalplus/webhook_event')->getSupportedWebhookEvents() as $webhookEvent) { $webhookEventType = new \PayPal\Api\WebhookEventType(); $webhookEventType->setName($webhookEvent); $webhookEventTypes[] = $webhookEventType; } $webhook->setEventTypes($webhookEventTypes); $webhookData = $webhook->create($this->_apiContext); $this->saveWebhookId($webhookData->getId()); return $webhookData; }