예제 #1
0
 /**
  * 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;
 }
예제 #2
0
//         "event_types":[
//            {
//                "name":"PAYMENT.AUTHORIZATION.CREATED"
//            },
//            {
//                "name":"PAYMENT.AUTHORIZATION.VOIDED"
//            }
//         ]
//      }
// Fill up the basic information that is required for the webhook
// The URL should be actually accessible over the internet. Having a localhost here would not work.
// #### There is an open source tool http://requestb.in/ that allows you to receive any web requests to a url given there.
// #### NOTE: Please note that you need an https url for paypal webhooks. You can however override the url with https, and accept
// any warnings your browser might show you. Also, please note that this is entirely for demo purposes, and you should not
// be using this in production
$webhook->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);
예제 #3
0
 /**
  * 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;
 }