Merge pull request #653 from paypal/webhooks-update

Update webhooks to API version 1.7
This commit is contained in:
Jay
2016-09-22 13:42:31 -05:00
committed by GitHub
20 changed files with 836 additions and 311 deletions

View File

@@ -0,0 +1,213 @@
<?php
namespace PayPal\Api;
use PayPal\Common\PayPalResourceModel;
use PayPal\Validation\ArgumentValidator;
use PayPal\Api\VerifyWebhookSignatureResponse;
use PayPal\Rest\ApiContext;
use PayPal\Validation\UrlValidator;
/**
* Class VerifyWebhookSignature
*
* Verify webhook signature.
*
* @package PayPal\Api
*
* @property string auth_algo
* @property string cert_url
* @property string transmission_id
* @property string transmission_sig
* @property string transmission_time
* @property string webhook_id
* @property \PayPal\Api\WebhookEvent webhook_event
*/
class VerifyWebhookSignature extends PayPalResourceModel
{
/**
* The algorithm that PayPal uses to generate the signature and that you can use to verify the signature. Extract this value from the `PAYPAL-AUTH-ALGO` response header, which is received with the webhook notification.
*
* @param string $auth_algo
*
* @return $this
*/
public function setAuthAlgo($auth_algo)
{
$this->auth_algo = $auth_algo;
return $this;
}
/**
* The algorithm that PayPal uses to generate the signature and that you can use to verify the signature. Extract this value from the `PAYPAL-AUTH-ALGO` response header, which is received with the webhook notification.
*
* @return string
*/
public function getAuthAlgo()
{
return $this->auth_algo;
}
/**
* The X.509 public key certificate. Download the certificate from this URL and use it to verify the signature. Extract this value from the `PAYPAL-CERT-URL` response header, which is received with the webhook notification.
*
* @param string $cert_url
* @throws \InvalidArgumentException
* @return $this
*/
public function setCertUrl($cert_url)
{
UrlValidator::validate($cert_url, "CertUrl");
$this->cert_url = $cert_url;
return $this;
}
/**
* The X.509 public key certificate. Download the certificate from this URL and use it to verify the signature. Extract this value from the `PAYPAL-CERT-URL` response header, which is received with the webhook notification.
*
* @return string
*/
public function getCertUrl()
{
return $this->cert_url;
}
/**
* The ID of the HTTP transmission. Contained in the `PAYPAL-TRANSMISSION-ID` header of the notification message.
*
* @param string $transmission_id
*
* @return $this
*/
public function setTransmissionId($transmission_id)
{
$this->transmission_id = $transmission_id;
return $this;
}
/**
* The ID of the HTTP transmission. Contained in the `PAYPAL-TRANSMISSION-ID` header of the notification message.
*
* @return string
*/
public function getTransmissionId()
{
return $this->transmission_id;
}
/**
* The PayPal-generated asymmetric signature. Extract this value from the `PAYPAL-TRANSMISSION-SIG` response header, which is received with the webhook notification.
*
* @param string $transmission_sig
*
* @return $this
*/
public function setTransmissionSig($transmission_sig)
{
$this->transmission_sig = $transmission_sig;
return $this;
}
/**
* The PayPal-generated asymmetric signature. Extract this value from the `PAYPAL-TRANSMISSION-SIG` response header, which is received with the webhook notification.
*
* @return string
*/
public function getTransmissionSig()
{
return $this->transmission_sig;
}
/**
* The date and time of the HTTP transmission. Contained in the `PAYPAL-TRANSMISSION-TIME` header of the notification message.
*
* @param string $transmission_time
*
* @return $this
*/
public function setTransmissionTime($transmission_time)
{
$this->transmission_time = $transmission_time;
return $this;
}
/**
* The date and time of the HTTP transmission. Contained in the `PAYPAL-TRANSMISSION-TIME` header of the notification message.
*
* @return string
*/
public function getTransmissionTime()
{
return $this->transmission_time;
}
/**
* The ID of the webhook as configured in your Developer Portal account.
*
* @param string $webhook_id
*
* @return $this
*/
public function setWebhookId($webhook_id)
{
$this->webhook_id = $webhook_id;
return $this;
}
/**
* The ID of the webhook as configured in your Developer Portal account.
*
* @return string
*/
public function getWebhookId()
{
return $this->webhook_id;
}
/**
* The webhook notification, which is the content of the HTTP `POST` request body.
*
* @param \PayPal\Api\WebhookEvent $webhook_event
*
* @return $this
*/
public function setWebhookEvent($webhook_event)
{
$this->webhook_event = $webhook_event;
return $this;
}
/**
* The webhook notification, which is the content of the HTTP `POST` request body.
*
* @return \PayPal\Api\WebhookEvent
*/
public function getWebhookEvent()
{
return $this->webhook_event;
}
/**
* Verifies a webhook signature.
*
* @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 VerifyWebhookSignatureResponse
*/
public function post($apiContext = null, $restCall = null)
{
$payLoad = $this->toJSON();
$json = self::executeCall(
"/v1/notifications/verify-webhook-signature",
"POST",
$payLoad,
null,
$apiContext,
$restCall
);
$ret = new VerifyWebhookSignatureResponse();
$ret->fromJson($json);
return $ret;
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace PayPal\Api;
use PayPal\Common\PayPalModel;
/**
* Class VerifyWebhookSignatureResponse
*
* The verify webhook signature response.
*
* @package PayPal\Api
*
* @property string verification_status
*/
class VerifyWebhookSignatureResponse extends PayPalModel
{
/**
* The status of the signature verification. Value is `SUCCESS` or `FAILURE`.
* Valid Values: ["SUCCESS", "FAILURE"]
*
* @param string $verification_status
*
* @return $this
*/
public function setVerificationStatus($verification_status)
{
$this->verification_status = $verification_status;
return $this;
}
/**
* The status of the signature verification. Value is `SUCCESS` or `FAILURE`.
*
* @return string
*/
public function getVerificationStatus()
{
return $this->verification_status;
}
}

View File

@@ -3,15 +3,15 @@
namespace PayPal\Api;
use PayPal\Common\PayPalResourceModel;
use PayPal\Rest\ApiContext;
use PayPal\Transport\PayPalRestCall;
use PayPal\Validation\ArgumentValidator;
use PayPal\Api\WebhookList;
use PayPal\Rest\ApiContext;
use PayPal\Validation\UrlValidator;
/**
* Class Webhook
*
* Represents Webhook resource.
* One or more webhook objects.
*
* @package PayPal\Api
*
@@ -22,7 +22,7 @@ use PayPal\Validation\UrlValidator;
class Webhook extends PayPalResourceModel
{
/**
* Identifier of the webhook resource.
* The ID of the webhook.
*
* @param string $id
*
@@ -35,7 +35,7 @@ class Webhook extends PayPalResourceModel
}
/**
* Identifier of the webhook resource.
* The ID of the webhook.
*
* @return string
*/
@@ -45,7 +45,7 @@ class Webhook extends PayPalResourceModel
}
/**
* Webhook notification endpoint url.
* The URL that is configured to listen on `localhost` for incoming `POST` notification messages that contain event information.
*
* @param string $url
* @throws \InvalidArgumentException
@@ -59,7 +59,7 @@ class Webhook extends PayPalResourceModel
}
/**
* Webhook notification endpoint url.
* The URL that is configured to listen on `localhost` for incoming `POST` notification messages that contain event information.
*
* @return string
*/
@@ -69,7 +69,7 @@ class Webhook extends PayPalResourceModel
}
/**
* List of Webhooks event-types.
* A list of up to ten events to which to subscribe your webhook. To subscribe to all events including new events as they are added, specify the asterisk (`*`) wildcard. To replace the `event_types` array, specify the `*` wildcard. To see all supported events, [list available events](#available-event-type.list).
*
* @param \PayPal\Api\WebhookEventType[] $event_types
*
@@ -82,7 +82,7 @@ class Webhook extends PayPalResourceModel
}
/**
* List of Webhooks event-types.
* A list of up to ten events to which to subscribe your webhook. To subscribe to all events including new events as they are added, specify the asterisk (`*`) wildcard. To replace the `event_types` array, specify the `*` wildcard. To see all supported events, [list available events](#available-event-type.list).
*
* @return \PayPal\Api\WebhookEventType[]
*/
@@ -122,7 +122,7 @@ class Webhook extends PayPalResourceModel
}
/**
* Creates the Webhook for the application associated with the access token.
* Subscribes your webhook listener to events. A successful call returns a [`webhook`](/docs/api/webhooks/#definition-webhook) object, which includes the webhook ID for later use.
*
* @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
@@ -144,7 +144,7 @@ class Webhook extends PayPalResourceModel
}
/**
* Retrieves the Webhook identified by webhook_id for the application associated with access token.
* 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.
@@ -171,15 +171,34 @@ class Webhook extends PayPalResourceModel
/**
* Retrieves all Webhooks for the application associated with access token.
*
* @deprecated Please use Webhook#getAllWithParams instead.
*
* @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 WebhookList
*/
public static function getAll($apiContext = null, $restCall = null)
{
return self::getAllWithParams(array(), $apiContext, $restCall);
}
/**
* Lists all webhooks for an app.
*
* @param array $params
* @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 WebhookList
*/
public static function getAllWithParams($params = array(), $apiContext = null, $restCall = null)
{
ArgumentValidator::validate($params, 'params');
$payLoad = "";
$allowedParams = array(
'anchor_type' => 1,
);
$json = self::executeCall(
"/v1/notifications/webhooks",
"/v1/notifications/webhooks?" . http_build_query(array_intersect_key($params, $allowedParams)),
"GET",
$payLoad,
null,
@@ -192,7 +211,7 @@ class Webhook extends PayPalResourceModel
}
/**
* Updates the Webhook identified by webhook_id for the application associated with access token.
* Replaces webhook fields with new values. Pass a `json_patch` object with `replace` operation and `path`, which is `/url` for a URL or `/event_types` for events. The `value` is either the URL or a list of events.
*
* @param PatchRequest $patchRequest
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
@@ -217,7 +236,7 @@ class Webhook extends PayPalResourceModel
}
/**
* Deletes the Webhook identified by webhook_id for the application associated with access token.
* Deletes a webhook, by ID.
*
* @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

View File

@@ -3,30 +3,31 @@
namespace PayPal\Api;
use PayPal\Common\PayPalResourceModel;
use PayPal\Exception\PayPalConnectionException;
use PayPal\Rest\ApiContext;
use PayPal\Transport\PayPalRestCall;
use PayPal\Validation\ArgumentValidator;
use PayPal\Validation\JsonValidator;
use PayPal\Api\WebhookEventList;
use PayPal\Rest\ApiContext;
/**
* Class WebhookEvent
*
* Represents a Webhooks event
* A webhook event notification.
*
* @package PayPal\Api
*
* @property string id
* @property string create_time
* @property string resource_type
* @property string event_version
* @property string event_type
* @property string summary
* @property mixed resource
* @property \PayPal\Common\PayPalModel resource
* @property string status
* @property mixed[] transmissions
*/
class WebhookEvent extends PayPalResourceModel
{
/**
* Identifier of the Webhooks event resource.
* The ID of the webhook event notification.
*
* @param string $id
*
@@ -39,7 +40,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* Identifier of the Webhooks event resource.
* The ID of the webhook event notification.
*
* @return string
*/
@@ -49,7 +50,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* Time the resource was created.
* The date and time when the webhook event notification was created.
*
* @param string $create_time
*
@@ -62,7 +63,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* Time the resource was created.
* The date and time when the webhook event notification was created.
*
* @return string
*/
@@ -72,7 +73,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* Name of the resource contained in resource element.
* The name of the resource related to the webhook notification event.
*
* @param string $resource_type
*
@@ -85,7 +86,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* Name of the resource contained in resource element.
* The name of the resource related to the webhook notification event.
*
* @return string
*/
@@ -95,7 +96,30 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* Name of the event type that occurred on resource, identified by data_resource element, to trigger the Webhooks event.
* The version of the event.
*
* @param string $event_version
*
* @return $this
*/
public function setEventVersion($event_version)
{
$this->event_version = $event_version;
return $this;
}
/**
* The version of the event.
*
* @return string
*/
public function getEventVersion()
{
return $this->event_version;
}
/**
* The event that triggered the webhook event notification.
*
* @param string $event_type
*
@@ -108,7 +132,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* Name of the event type that occurred on resource, identified by data_resource element, to trigger the Webhooks event.
* The event that triggered the webhook event notification.
*
* @return string
*/
@@ -118,7 +142,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* A summary description of the event. E.g. A successful payment authorization was created for $$
* A summary description for the event notification. For example, `A payment authorization was created.`
*
* @param string $summary
*
@@ -131,7 +155,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* A summary description of the event. E.g. A successful payment authorization was created for $$
* A summary description for the event notification. For example, `A payment authorization was created.`
*
* @return string
*/
@@ -141,7 +165,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* This contains the resource that is identified by resource_type element.
* The resource that triggered the webhook event notification.
*
* @param \PayPal\Common\PayPalModel $resource
*
@@ -154,7 +178,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* This contains the resource that is identified by resource_type element.
* The resource that triggered the webhook event notification.
*
* @return \PayPal\Common\PayPalModel
*/
@@ -171,6 +195,8 @@ class WebhookEvent extends PayPalResourceModel
*
* NOTE: PLEASE DO NOT USE THE DATA PROVIDED IN WEBHOOK DIRECTLY, AS HACKER COULD PASS IN FAKE DATA. IT IS VERY IMPORTANT THAT YOU RETRIEVE THE ID AND MAKE A SEPARATE CALL TO PAYPAL API.
*
* @deprecated todo: add refrence to correct method
*
* @param string $body
* @param ApiContext $apiContext
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
@@ -227,7 +253,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* Resends the Webhooks event resource identified by event_id.
* Resends a webhook event notification, by ID. Any pending notifications are not resent.
*
* @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
@@ -250,7 +276,7 @@ class WebhookEvent extends PayPalResourceModel
}
/**
* Retrieves the list of Webhooks events resources for the application associated with token. The developers can use it to see list of past webhooks events.
* Lists webhook event notifications. Use query parameters to filter the response.
*
* @param array $params
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
@@ -265,6 +291,8 @@ class WebhookEvent extends PayPalResourceModel
'page_size' => 1,
'start_time' => 1,
'end_time' => 1,
'transaction_id' => 1,
'event_type' => 1,
);
$json = self::executeCall(
"/v1/notifications/webhooks-events" . "?" . http_build_query(array_intersect_key($params, $allowedParams)),

View File

@@ -7,7 +7,7 @@ use PayPal\Common\PayPalModel;
/**
* Class WebhookEventList
*
* List of Webhooks event resources
* List of webhooks events.
*
* @package PayPal\Api
*
@@ -18,7 +18,7 @@ use PayPal\Common\PayPalModel;
class WebhookEventList extends PayPalModel
{
/**
* A list of Webhooks event resources
* A list of webhooks events.
*
* @param \PayPal\Api\WebhookEvent[] $events
*
@@ -31,7 +31,7 @@ class WebhookEventList extends PayPalModel
}
/**
* A list of Webhooks event resources
* A list of webhooks events.
*
* @return \PayPal\Api\WebhookEvent[]
*/
@@ -71,7 +71,7 @@ class WebhookEventList extends PayPalModel
}
/**
* Number of items returned in each range of results. Note that the last results range could have fewer items than the requested number of items.
* The number of items in each range of results. Note that the response might have fewer items than the requested `page_size` value.
*
* @param int $count
*
@@ -84,7 +84,7 @@ class WebhookEventList extends PayPalModel
}
/**
* Number of items returned in each range of results. Note that the last results range could have fewer items than the requested number of items.
* The number of items in each range of results. Note that the response might have fewer items than the requested `page_size` value.
*
* @return int
*/

View File

@@ -3,24 +3,25 @@
namespace PayPal\Api;
use PayPal\Common\PayPalResourceModel;
use PayPal\Rest\ApiContext;
use PayPal\Transport\PayPalRestCall;
use PayPal\Validation\ArgumentValidator;
use PayPal\Api\WebhookEventTypeList;
use PayPal\Rest\ApiContext;
/**
* Class WebhookEventType
*
* Contains the information for a Webhooks event-type
* A list of events.
*
* @package PayPal\Api
*
* @property string name
* @property string description
* @property string status
*/
class WebhookEventType extends PayPalResourceModel
{
/**
* Unique event-type name.
* The unique event name.
*
* @param string $name
*
@@ -33,7 +34,7 @@ class WebhookEventType extends PayPalResourceModel
}
/**
* Unique event-type name.
* The unique event name.
*
* @return string
*/
@@ -43,7 +44,7 @@ class WebhookEventType extends PayPalResourceModel
}
/**
* Human readable description of the event-type
* A human-readable description of the event.
*
* @param string $description
*
@@ -56,7 +57,7 @@ class WebhookEventType extends PayPalResourceModel
}
/**
* Human readable description of the event-type
* A human-readable description of the event.
*
* @return string
*/
@@ -66,7 +67,30 @@ class WebhookEventType extends PayPalResourceModel
}
/**
* Retrieves the list of events-types subscribed by the given Webhook.
* The status of a webhook event.
*
* @param string $status
*
* @return $this
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* The status of a webhook event.
*
* @return string
*/
public function getStatus()
{
return $this->status;
}
/**
* Lists event subscriptions 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.
@@ -91,7 +115,7 @@ class WebhookEventType extends PayPalResourceModel
}
/**
* Retrieves the master list of available Webhooks events-types resources for any webhook to subscribe to.
* Lists available events to which any webhook can subscribe. For a list of supported events, see [Webhook events](/docs/integration/direct/rest/webhooks/webhook-events/).
*
* @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

View File

@@ -7,7 +7,7 @@ use PayPal\Common\PayPalModel;
/**
* Class WebhookEventTypeList
*
* List of Webhooks event-types
* List of webhook events.
*
* @package PayPal\Api
*
@@ -16,7 +16,7 @@ use PayPal\Common\PayPalModel;
class WebhookEventTypeList extends PayPalModel
{
/**
* A list of Webhooks event-types
* A list of webhook events.
*
* @param \PayPal\Api\WebhookEventType[] $event_types
*
@@ -29,7 +29,7 @@ class WebhookEventTypeList extends PayPalModel
}
/**
* A list of Webhooks event-types
* A list of webhook events.
*
* @return \PayPal\Api\WebhookEventType[]
*/

View File

@@ -7,7 +7,7 @@ use PayPal\Common\PayPalModel;
/**
* Class WebhookList
*
* List of Webhooks
* List of webhooks.
*
* @package PayPal\Api
*
@@ -16,7 +16,7 @@ use PayPal\Common\PayPalModel;
class WebhookList extends PayPalModel
{
/**
* A list of Webhooks
* A list of webhooks.
*
* @param \PayPal\Api\Webhook[] $webhooks
*
@@ -29,7 +29,7 @@ class WebhookList extends PayPalModel
}
/**
* A list of Webhooks
* A list of webhooks.
*
* @return \PayPal\Api\Webhook[]
*/