Skip to content

Commit a0f4a4b

Browse files
Merge pull request #566 from ManikaSaiKiran/webhook-changes
Support for new payload of Webhooks
2 parents 5e4cafc + b76ce74 commit a0f4a4b

File tree

3 files changed

+295
-1
lines changed

3 files changed

+295
-1
lines changed

src/Core/CoreConstants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ class CoreConstants
297297
* The Request source header value.
298298
* @var string REQUESTSOURCEHEADER
299299
*/
300-
const USERAGENT = "V3PHPSDK6.2.1";
300+
const USERAGENT = "V3PHPSDK6.2.2";
301301

302302
public static function getType($string, $return=1)
303303
{
Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
<?php
2+
namespace QuickBooksOnline\API\WebhooksService;
3+
4+
/**
5+
* POJO Class for CloudEvents-based webhook event item
6+
*/
7+
class WebhooksCloudEvent
8+
{
9+
/**
10+
* The CloudEvents specification version
11+
*
12+
* @var string
13+
*/
14+
private $specVersion;
15+
16+
/**
17+
* Unique identifier for the event
18+
*
19+
* @var string
20+
*/
21+
private $id;
22+
23+
/**
24+
* The source of the event
25+
*
26+
* @var string
27+
*/
28+
private $source;
29+
30+
/**
31+
* The type of event
32+
*
33+
* @var string
34+
*/
35+
private $type;
36+
37+
/**
38+
* The content type of the data
39+
*
40+
* @var string
41+
*/
42+
private $dataContentType;
43+
44+
/**
45+
* The timestamp of the event
46+
*
47+
* @var string
48+
*/
49+
private $time;
50+
51+
/**
52+
* Intuit entity ID
53+
*
54+
* @var string
55+
*/
56+
private $intuitEntityId;
57+
58+
/**
59+
* Intuit account ID
60+
*
61+
* @var string
62+
*/
63+
private $intuitAccountId;
64+
65+
/**
66+
* The event data payload
67+
*
68+
* @var array
69+
*/
70+
private $data;
71+
72+
/**
73+
* Get the CloudEvents specification version
74+
*
75+
* @return string
76+
*/
77+
public function getSpecVersion()
78+
{
79+
return $this->specVersion;
80+
}
81+
82+
/**
83+
* Set the CloudEvents specification version
84+
*
85+
* @param string $specVersion
86+
* @return $this
87+
*/
88+
public function setSpecVersion($specVersion)
89+
{
90+
$this->specVersion = $specVersion;
91+
return $this;
92+
}
93+
94+
/**
95+
* Get the event ID
96+
*
97+
* @return string
98+
*/
99+
public function getId()
100+
{
101+
return $this->id;
102+
}
103+
104+
/**
105+
* Set the event ID
106+
*
107+
* @param string $id
108+
* @return $this
109+
*/
110+
public function setId($id)
111+
{
112+
$this->id = $id;
113+
return $this;
114+
}
115+
116+
/**
117+
* Get the event source
118+
*
119+
* @return string
120+
*/
121+
public function getSource()
122+
{
123+
return $this->source;
124+
}
125+
126+
/**
127+
* Set the event source
128+
*
129+
* @param string $source
130+
* @return $this
131+
*/
132+
public function setSource($source)
133+
{
134+
$this->source = $source;
135+
return $this;
136+
}
137+
138+
/**
139+
* Get the event type
140+
*
141+
* @return string
142+
*/
143+
public function getType()
144+
{
145+
return $this->type;
146+
}
147+
148+
/**
149+
* Set the event type
150+
*
151+
* @param string $type
152+
* @return $this
153+
*/
154+
public function setType($type)
155+
{
156+
$this->type = $type;
157+
return $this;
158+
}
159+
160+
/**
161+
* Get the data content type
162+
*
163+
* @return string
164+
*/
165+
public function getDataContentType()
166+
{
167+
return $this->dataContentType;
168+
}
169+
170+
/**
171+
* Set the data content type
172+
*
173+
* @param string $dataContentType
174+
* @return $this
175+
*/
176+
public function setDataContentType($dataContentType)
177+
{
178+
$this->dataContentType = $dataContentType;
179+
return $this;
180+
}
181+
182+
/**
183+
* Get the event timestamp
184+
*
185+
* @return string
186+
*/
187+
public function getTime()
188+
{
189+
return $this->time;
190+
}
191+
192+
/**
193+
* Set the event timestamp
194+
*
195+
* @param string $time
196+
* @return $this
197+
*/
198+
public function setTime($time)
199+
{
200+
$this->time = $time;
201+
return $this;
202+
}
203+
204+
/**
205+
* Get the Intuit entity ID
206+
*
207+
* @return string
208+
*/
209+
public function getIntuitEntityId()
210+
{
211+
return $this->intuitEntityId;
212+
}
213+
214+
/**
215+
* Set the Intuit entity ID
216+
*
217+
* @param string $intuitEntityId
218+
* @return $this
219+
*/
220+
public function setIntuitEntityId($intuitEntityId)
221+
{
222+
$this->intuitEntityId = $intuitEntityId;
223+
return $this;
224+
}
225+
226+
/**
227+
* Get the Intuit account ID
228+
*
229+
* @return string
230+
*/
231+
public function getIntuitAccountId()
232+
{
233+
return $this->intuitAccountId;
234+
}
235+
236+
/**
237+
* Set the Intuit account ID
238+
*
239+
* @param string $intuitAccountId
240+
* @return $this
241+
*/
242+
public function setIntuitAccountId($intuitAccountId)
243+
{
244+
$this->intuitAccountId = $intuitAccountId;
245+
return $this;
246+
}
247+
248+
/**
249+
* Get the event data payload
250+
*
251+
* @return array
252+
*/
253+
public function getData()
254+
{
255+
return $this->data;
256+
}
257+
258+
/**
259+
* Set the event data payload
260+
*
261+
* @param array $data
262+
* @return $this
263+
*/
264+
public function setData($data)
265+
{
266+
$this->data = $data;
267+
return $this;
268+
}
269+
}

src/WebhooksService/WebhooksService.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
class WebhooksService
99
{
1010
const WEBHOOKSWRAPPERNAME = "WebhooksEvent";
11+
const WEBHOOKSCLOUDEVENTSWRAPPERNAME = "WebhooksCloudEvent";
1112

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

30+
/**
31+
* Convert the CloudEvents payLoad of webhook to array of objects
32+
*
33+
* @param $payLoad
34+
* The CloudEvents payload to be converted
35+
* @return array
36+
* Array of WebhooksCloudEvent objects
37+
*
38+
*/
39+
public static function getWebhooksCloudEvents($payLoad)
40+
{
41+
JsonValidator::validate($payLoad);
42+
$string_arry = json_decode($payLoad, true);
43+
44+
$result = array();
45+
foreach ($string_arry as $eventData) {
46+
$obj = ReflectionUtil::constructObjectFromWebhooksArray($eventData, WebhooksService::WEBHOOKSCLOUDEVENTSWRAPPERNAME);
47+
if ($obj !== null) {
48+
$result[] = $obj;
49+
}
50+
}
51+
return $result;
52+
}
53+
2954
/**
3055
* use Token to verifier the payload is sent from Intuit
3156
*

0 commit comments

Comments
 (0)