WebhookMessage

Extends \NextEvent\PHPSDK\Model\Model

A webhook message comes from the platform the app runs on and contains data, which can be used for various processes.

The instance of this class should be used, to verify content of the incoming message to make your platform more secure. In order to verify the incoming message, you have to know the secret, you configured on the webhook in the NextEvent App.

Example:

try {
  $gate = WebhookMessage::current()->verify()->getModel(Gate::class);
  // Do something...
}
catch (WebhookMessageException $exception) {
   // Handle this
}
package

Default

Methods

Supports getX or hasX Methods for properties which are yet unknown.

__call(string $name, array $args) : mixed
inherited

If the source of your model contains, e.g. a property named 'my_property', you can call getMyProperty() to retrieve it's value.

Arguments

$name

string

$args

array

Response

mixed

Model constructor

__construct(array $source) 
inherited

Parse source data.

Throws
\NextEvent\PHPSDK\Exception\InvalidModelDataException

Arguments

$source

array

The source data as received from the API

Creates a webhook message from the current request.

current() : \NextEvent\PHPSDK\Model\WebhookMessage
static

Response

\NextEvent\PHPSDK\Model\WebhookMessage

The current webhook message.

Get the value for the given variable.

get(string $var) : mixed
inherited

Should be used, if you expect the model to have custom properties which are not known/covered by the known getters

Arguments

$var

string

Response

mixed

Get the event of this webhook message.

getEvent() : string

Response

string

Get the headers of this webhook message.

getHeaders() : array

Response

array

Get the id of this webhook message.

getId() : string

Response

string

Decodes the json payload and returns it as an associative array.

getJSON() : array
Throws
\NextEvent\PHPSDK\Model\NextEvent\PHPSDK\Exception\WebhookMessageException

If not verified yet.

Response

array

Creates a model from the given class name and returns it.

getModel(string $className,  $args = array()) : \NextEvent\PHPSDK\Model\NextEvent\PHPSDK\Model\Model
Throws
\NextEvent\PHPSDK\Model\NextEvent\PHPSDK\Exception\WebhookMessageException

If not verified yet or if the event type does not fit the provided model class.

Arguments

$className

string

The full class name of the model to generate.

$args

Response

\NextEvent\PHPSDK\Model\NextEvent\PHPSDK\Model\Model

Get the raw payload of this webhook message.

getPayload() : string

Response

string

Get the signature for this webhook message.

getSignature() : string

Response

string

Check model state if it is valid

isValid() : boolean
inherited abstract

Response

boolean

String representation of object

serialize() : string
inherited

Implements Serializable interface

Response

string

Convert model to an Array

toArray() : array
inherited

Response

array

Convert the model for logging

toLogContext() : array
inherited

Implements the LogContextInterface interface

Response

array

Represent the model as string

toString() : string
inherited

Response

string

Constructs the object from a string

unserialize( $serialized) 
inherited

Implements Serializable interface

Arguments

$serialized

Verifies the signature of this message with the given secret.

verify(string $secret) : \NextEvent\PHPSDK\Model\NextEvent\PHPSDK\Model\WebhookMessage
Throws
\NextEvent\PHPSDK\Model\NextEvent\PHPSDK\Exception\WebhookMessageException

If no signature is present or the signature is invalid.

Arguments

$secret

string

Response

\NextEvent\PHPSDK\Model\NextEvent\PHPSDK\Model\WebhookMessage