PayPalApiWebhook

Class Webhook.

Defined (1)

The class is defined in the following location(s).

/classes/lib/PayPal/Api/Webhook.php  
  1. class Webhook extends PayPalResourceModel 
  2. /** 
  3. * Identifier of the webhook resource. 
  4. * @param string $id 
  5. *  
  6. * @return $this 
  7. */ 
  8. public function setId($id) 
  9. $this->id = $id; 
  10. return $this; 
  11.  
  12. /** 
  13. * Identifier of the webhook resource. 
  14. * @return string 
  15. */ 
  16. public function getId() 
  17. return $this->id; 
  18.  
  19. /** 
  20. * Webhook notification endpoint url. 
  21. * @param string $url 
  22. * @throws \InvalidArgumentException 
  23. * @return $this 
  24. */ 
  25. public function setUrl($url) 
  26. UrlValidator::validate($url, "Url"); 
  27. $this->url = $url; 
  28. return $this; 
  29.  
  30. /** 
  31. * Webhook notification endpoint url. 
  32. * @return string 
  33. */ 
  34. public function getUrl() 
  35. return $this->url; 
  36.  
  37. /** 
  38. * List of Webhooks event-types. 
  39. * @param \PayPal\Api\WebhookEventType[] $event_types 
  40. *  
  41. * @return $this 
  42. */ 
  43. public function setEventTypes($event_types) 
  44. $this->event_types = $event_types; 
  45. return $this; 
  46.  
  47. /** 
  48. * List of Webhooks event-types. 
  49. * @return \PayPal\Api\WebhookEventType[] 
  50. */ 
  51. public function getEventTypes() 
  52. return $this->event_types; 
  53.  
  54. /** 
  55. * Append EventTypes to the list. 
  56. * @param \PayPal\Api\WebhookEventType $webhookEventType 
  57. * @return $this 
  58. */ 
  59. public function addEventType($webhookEventType) 
  60. if (!$this->getEventTypes()) { 
  61. return $this->setEventTypes(array($webhookEventType)); 
  62. } else { 
  63. return $this->setEventTypes( 
  64. array_merge($this->getEventTypes(), array($webhookEventType)) 
  65. ); 
  66.  
  67. /** 
  68. * Remove EventTypes from the list. 
  69. * @param \PayPal\Api\WebhookEventType $webhookEventType 
  70. * @return $this 
  71. */ 
  72. public function removeEventType($webhookEventType) 
  73. return $this->setEventTypes( 
  74. array_diff($this->getEventTypes(), array($webhookEventType)) 
  75. ); 
  76.  
  77. /** 
  78. * Creates the Webhook for the application associated with the access token. 
  79. * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. 
  80. * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls 
  81. * @return Webhook 
  82. */ 
  83. public function create($apiContext = null, $restCall = null) 
  84. $payLoad = $this->toJSON(); 
  85. $json = self::executeCall( 
  86. "/v1/notifications/webhooks",  
  87. "POST",  
  88. $payLoad,  
  89. null,  
  90. $apiContext,  
  91. $restCall 
  92. ); 
  93. $this->fromJson($json); 
  94. return $this; 
  95.  
  96. /** 
  97. * Retrieves the Webhook identified by webhook_id for the application associated with access token. 
  98. * @param string $webhookId 
  99. * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. 
  100. * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls 
  101. * @return Webhook 
  102. */ 
  103. public static function get($webhookId, $apiContext = null, $restCall = null) 
  104. ArgumentValidator::validate($webhookId, 'webhookId'); 
  105. $payLoad = ""; 
  106. $json = self::executeCall( 
  107. "/v1/notifications/webhooks/$webhookId",  
  108. "GET",  
  109. $payLoad,  
  110. null,  
  111. $apiContext,  
  112. $restCall 
  113. ); 
  114. $ret = new Webhook(); 
  115. $ret->fromJson($json); 
  116. return $ret; 
  117.  
  118. /** 
  119. * Retrieves all Webhooks for the application associated with access token. 
  120. * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. 
  121. * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls 
  122. * @return WebhookList 
  123. */ 
  124. public static function getAll($apiContext = null, $restCall = null) 
  125. $payLoad = ""; 
  126. $json = self::executeCall( 
  127. "/v1/notifications/webhooks",  
  128. "GET",  
  129. $payLoad,  
  130. null,  
  131. $apiContext,  
  132. $restCall 
  133. ); 
  134. $ret = new WebhookList(); 
  135. $ret->fromJson($json); 
  136. return $ret; 
  137.  
  138. /** 
  139. * Updates the Webhook identified by webhook_id for the application associated with access token. 
  140. * @param PatchRequest $patchRequest 
  141. * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. 
  142. * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls 
  143. * @return Webhook 
  144. */ 
  145. public function update($patchRequest, $apiContext = null, $restCall = null) 
  146. ArgumentValidator::validate($this->getId(), "Id"); 
  147. ArgumentValidator::validate($patchRequest, 'patchRequest'); 
  148. $payLoad = $patchRequest->toJSON(); 
  149. $json = self::executeCall( 
  150. "/v1/notifications/webhooks/{$this->getId()}",  
  151. "PATCH",  
  152. $payLoad,  
  153. null,  
  154. $apiContext,  
  155. $restCall 
  156. ); 
  157. $this->fromJson($json); 
  158. return $this; 
  159.  
  160. /** 
  161. * Deletes the Webhook identified by webhook_id for the application associated with access token. 
  162. * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. 
  163. * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls 
  164. * @return bool 
  165. */ 
  166. public function delete($apiContext = null, $restCall = null) 
  167. ArgumentValidator::validate($this->getId(), "Id"); 
  168. $payLoad = ""; 
  169. self::executeCall( 
  170. "/v1/notifications/webhooks/{$this->getId()}",  
  171. "DELETE",  
  172. $payLoad,  
  173. null,  
  174. $apiContext,  
  175. $restCall 
  176. ); 
  177. return true; 
  178.