Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Core/CoreConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class CoreConstants
* The Request source header value.
* @var string REQUESTSOURCEHEADER
*/
const USERAGENT = "V3PHPSDK6.2.1";
const USERAGENT = "V3PHPSDK6.2.2";

public static function getType($string, $return=1)
{
Expand Down
269 changes: 269 additions & 0 deletions src/WebhooksService/WebhooksCloudEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
<?php
namespace QuickBooksOnline\API\WebhooksService;

/**
* POJO Class for CloudEvents-based webhook event item
*/
class WebhooksCloudEvent
{
/**
* The CloudEvents specification version
*
* @var string
*/
private $specVersion;

/**
* Unique identifier for the event
*
* @var string
*/
private $id;

/**
* The source of the event
*
* @var string
*/
private $source;

/**
* The type of event
*
* @var string
*/
private $type;

/**
* The content type of the data
*
* @var string
*/
private $dataContentType;

/**
* The timestamp of the event
*
* @var string
*/
private $time;

/**
* Intuit entity ID
*
* @var string
*/
private $intuitEntityId;

/**
* Intuit account ID
*
* @var string
*/
private $intuitAccountId;

/**
* The event data payload
*
* @var array
*/
private $data;

/**
* Get the CloudEvents specification version
*
* @return string
*/
public function getSpecVersion()
{
return $this->specVersion;
}

/**
* Set the CloudEvents specification version
*
* @param string $specVersion
* @return $this
*/
public function setSpecVersion($specVersion)
{
$this->specVersion = $specVersion;
return $this;
}

/**
* Get the event ID
*
* @return string
*/
public function getId()
{
return $this->id;
}

/**
* Set the event ID
*
* @param string $id
* @return $this
*/
public function setId($id)
{
$this->id = $id;
return $this;
}

/**
* Get the event source
*
* @return string
*/
public function getSource()
{
return $this->source;
}

/**
* Set the event source
*
* @param string $source
* @return $this
*/
public function setSource($source)
{
$this->source = $source;
return $this;
}

/**
* Get the event type
*
* @return string
*/
public function getType()
{
return $this->type;
}

/**
* Set the event type
*
* @param string $type
* @return $this
*/
public function setType($type)
{
$this->type = $type;
return $this;
}

/**
* Get the data content type
*
* @return string
*/
public function getDataContentType()
{
return $this->dataContentType;
}

/**
* Set the data content type
*
* @param string $dataContentType
* @return $this
*/
public function setDataContentType($dataContentType)
{
$this->dataContentType = $dataContentType;
return $this;
}

/**
* Get the event timestamp
*
* @return string
*/
public function getTime()
{
return $this->time;
}

/**
* Set the event timestamp
*
* @param string $time
* @return $this
*/
public function setTime($time)
{
$this->time = $time;
return $this;
}

/**
* Get the Intuit entity ID
*
* @return string
*/
public function getIntuitEntityId()
{
return $this->intuitEntityId;
}

/**
* Set the Intuit entity ID
*
* @param string $intuitEntityId
* @return $this
*/
public function setIntuitEntityId($intuitEntityId)
{
$this->intuitEntityId = $intuitEntityId;
return $this;
}

/**
* Get the Intuit account ID
*
* @return string
*/
public function getIntuitAccountId()
{
return $this->intuitAccountId;
}

/**
* Set the Intuit account ID
*
* @param string $intuitAccountId
* @return $this
*/
public function setIntuitAccountId($intuitAccountId)
{
$this->intuitAccountId = $intuitAccountId;
return $this;
}

/**
* Get the event data payload
*
* @return array
*/
public function getData()
{
return $this->data;
}

/**
* Set the event data payload
*
* @param array $data
* @return $this
*/
public function setData($data)
{
$this->data = $data;
return $this;
}
}
25 changes: 25 additions & 0 deletions src/WebhooksService/WebhooksService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class WebhooksService
{
const WEBHOOKSWRAPPERNAME = "WebhooksEvent";
const WEBHOOKSCLOUDEVENTSWRAPPERNAME = "WebhooksCloudEvent";

/**
* Convert the payLoad of webhook to object
Expand All @@ -26,6 +27,30 @@ public static function getWebhooksEvent($payLoad)
return $obj;
}

/**
* Convert the CloudEvents payLoad of webhook to array of objects
*
* @param $payLoad
* The CloudEvents payload to be converted
* @return array
* Array of WebhooksCloudEvent objects
*
*/
public static function getWebhooksCloudEvents($payLoad)
{
JsonValidator::validate($payLoad);
$string_arry = json_decode($payLoad, true);

$result = array();
foreach ($string_arry as $eventData) {
$obj = ReflectionUtil::constructObjectFromWebhooksArray($eventData, WebhooksService::WEBHOOKSCLOUDEVENTSWRAPPERNAME);
if ($obj !== null) {
$result[] = $obj;
}
}
return $result;
}

/**
* use Token to verifier the payload is sent from Intuit
*
Expand Down