Skip to content

Commit e509c6b

Browse files
author
Pavle
committed
Release 3.7
1 parent 4f00f29 commit e509c6b

14 files changed

+958
-642
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/nbproject/private/
2+
Tests/vendor
3+
Tests/composer.lock
4+
/simpletest
5+
/.vs

IntegrationConfigHelpers.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function getMatchedIntegrationConfig(array $customerIntegration, $current
2222
return false;
2323
}
2424
if ($this->evaluateTrigger($trigger, $currentPageUrl, $request)) {
25-
return $integrationConfig;
25+
return $integrationConfig;
2626
}
2727
}
2828
}
@@ -70,6 +70,8 @@ private function evaluateTriggerPart(array $triggerPart, $currentPageUrl, $reque
7070
return UserAgentValidatorHelper::evaluate($triggerPart, $request->getUserAgent());
7171
case "HttpHeaderValidator":
7272
return HttpHeaderValidatorHelper::evaluate($triggerPart, $request->getHeaderArray());
73+
case "RequestBodyValidator":
74+
return RequestBodyValidatorHelper::evaluate($triggerPart, $request->getRequestBodyAsString());
7375
default:
7476
return false;
7577
}
@@ -181,6 +183,26 @@ public static function evaluate(array $triggerPart, array $headerList) {
181183
}
182184
}
183185

186+
class RequestBodyValidatorHelper
187+
{
188+
public static function evaluate(array $triggerPart, $requestBody) {
189+
190+
if (!array_key_exists("Operator", $triggerPart) ||
191+
!array_key_exists("IsNegative", $triggerPart) ||
192+
!array_key_exists("IsIgnoreCase", $triggerPart)) {
193+
return false;
194+
}
195+
196+
return ComparisonOperatorHelper::Evaluate(
197+
$triggerPart["Operator"],
198+
$triggerPart["IsNegative"],
199+
$triggerPart["IsIgnoreCase"],
200+
$requestBody,
201+
array_key_exists("ValueToCompare",$triggerPart)? $triggerPart["ValueToCompare"]: null,
202+
array_key_exists("ValuesToCompare",$triggerPart)? $triggerPart["ValuesToCompare"]: null);
203+
}
204+
}
205+
184206
class ComparisonOperatorHelper
185207
{
186208
public static function evaluate($opt, $isNegative, $isIgnoreCase, $value, $valueToCompare, $valuesToCompare) {

KnownUser.php

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class KnownUser
1212
{
13-
const QueueITAjaxHeaderKey = "x-queueit-ajaxpageurl";
13+
const QueueITAjaxHeaderKey = "x-queueit-ajaxpageurl";
1414

1515
//used for unittest
1616
private static $userInQueueService = null;
@@ -22,6 +22,10 @@ private static function getUserInQueueService()
2222
return KnownUser::$userInQueueService;
2323
}
2424

25+
public static function setHttpRequestProvider(IHttpRequestProvider $customHttpRequestProvider){
26+
KnownUser::$httpRequestProvider = $customHttpRequestProvider;
27+
}
28+
2529
//used for unittest
2630
private static $httpRequestProvider = null;
2731
private static function getHttpRequestProvider()
@@ -33,7 +37,7 @@ private static function getHttpRequestProvider()
3337
}
3438

3539
private static $debugInfoArray = null;
36-
public static function extendQueueCookie($eventId, $cookieValidityMinute, $cookieDomain, $secretKey)
40+
public static function extendQueueCookie($eventId, $cookieValidityMinute, $cookieDomain, $isCookieHttpOnly, $isCookieSecure, $secretKey)
3741
{
3842
if (empty($eventId)) {
3943
throw new KnownUserException("eventId can not be null or empty.");
@@ -45,7 +49,7 @@ public static function extendQueueCookie($eventId, $cookieValidityMinute, $cooki
4549
throw new KnownUserException("cookieValidityMinute should be integer greater than 0.");
4650
}
4751
$userInQueueService = KnownUser::getUserInQueueService();
48-
$userInQueueService->extendQueueCookie($eventId, $cookieValidityMinute, $cookieDomain, $secretKey);
52+
$userInQueueService->extendQueueCookie($eventId, $cookieValidityMinute, $cookieDomain, $isCookieHttpOnly, $isCookieSecure, $secretKey);
4953
}
5054

5155
private static function _cancelRequestByLocalConfig(
@@ -107,7 +111,7 @@ public static function cancelRequestByLocalConfig(
107111
}
108112

109113
try {
110-
$result = KnownUser::_cancelRequestByLocalConfig($targetUrl,$queueitToken,$cancelConfig,$customerId,$secretKey,$connectorDiagnostics->isEnabled);
114+
$result = KnownUser::_cancelRequestByLocalConfig($targetUrl, $queueitToken, $cancelConfig, $customerId, $secretKey, $connectorDiagnostics->isEnabled);
111115
KnownUser::sendDebugCookie();
112116
return $result;
113117
} catch (\Exception $e) {
@@ -217,14 +221,14 @@ public static function validateRequestByIntegrationConfig($currentUrlWithoutQueu
217221
public static function resolveQueueRequestByLocalConfig($targetUrl, $queueitToken, QueueEventConfig $queueConfig, $customerId, $secretKey)
218222
{
219223
$connectorDiagnostics = ConnectorDiagnostics::verify($customerId, $secretKey, $queueitToken);
220-
224+
221225
if ($connectorDiagnostics->hasError) {
222226
return $connectorDiagnostics->validationResult;
223227
}
224228

225229
try {
226230
$targetUrl = KnownUser::generateTargetUrl($targetUrl);
227-
$result = KnownUser::_resolveQueueRequestByLocalConfig($targetUrl, $queueitToken, $queueConfig, $customerId, $secretKey,$connectorDiagnostics->isEnabled);
231+
$result = KnownUser::_resolveQueueRequestByLocalConfig($targetUrl, $queueitToken, $queueConfig, $customerId, $secretKey, $connectorDiagnostics->isEnabled);
228232
KnownUser::sendDebugCookie();
229233
return $result;
230234
} catch (\Exception $e) {
@@ -291,12 +295,14 @@ private static function handleQueueAction(
291295
$eventConfig = new QueueEventConfig();
292296
$targetUrl = "";
293297
$eventConfig->eventId = $matchedConfig["EventId"];
294-
$eventConfig->queueDomain = $matchedConfig["QueueDomain"];
295298
$eventConfig->layoutName = $matchedConfig["LayoutName"];
296299
$eventConfig->culture = $matchedConfig["Culture"];
297-
$eventConfig->cookieDomain = $matchedConfig["CookieDomain"];
300+
$eventConfig->queueDomain = $matchedConfig["QueueDomain"];
298301
$eventConfig->extendCookieValidity = $matchedConfig["ExtendCookieValidity"];
299302
$eventConfig->cookieValidityMinute = $matchedConfig["CookieValidityMinute"];
303+
$eventConfig->cookieDomain = $matchedConfig["CookieDomain"];
304+
$eventConfig->isCookieHttpOnly = array_key_exists("IsCookieHttpOnly", $matchedConfig) ? $matchedConfig["IsCookieHttpOnly"] : false;
305+
$eventConfig->isCookieSecure = array_key_exists("IsCookieSecure", $matchedConfig) ? $matchedConfig["IsCookieSecure"] : false;
300306
$eventConfig->version = $customerIntegration["Version"];
301307
$eventConfig->actionName = $matchedConfig["Name"];
302308

@@ -325,10 +331,12 @@ private static function handleCancelAction(
325331
$isDebug
326332
) {
327333
$cancelEventConfig = new CancelEventConfig();
328-
$cancelEventConfig->eventId = $matchedConfig["EventId"];
329334
$cancelEventConfig->queueDomain = $matchedConfig["QueueDomain"];
330-
$cancelEventConfig->cookieDomain = $matchedConfig["CookieDomain"];
335+
$cancelEventConfig->eventId = $matchedConfig["EventId"];
331336
$cancelEventConfig->version = $customerIntegration["Version"];
337+
$cancelEventConfig->cookieDomain = $matchedConfig["CookieDomain"];
338+
$cancelEventConfig->isCookieHttpOnly = array_key_exists("IsCookieHttpOnly", $matchedConfig) ? $matchedConfig["IsCookieHttpOnly"] : false;
339+
$cancelEventConfig->isCookieSecure = array_key_exists("IsCookieSecure", $matchedConfig) ? $matchedConfig["IsCookieSecure"] : false;
332340
$cancelEventConfig->actionName = $matchedConfig["Name"];
333341

334342
return KnownUser::_cancelRequestByLocalConfig($currentUrlWithoutQueueITToken, $queueitToken, $cancelEventConfig, $customerId, $secretKey, $isDebug);
@@ -374,7 +382,7 @@ private static function sendDebugCookie()
374382
foreach (KnownUser::$debugInfoArray as $key => $value) {
375383
array_push($cookieNameValues, $key . '=' . $value);
376384
}
377-
KnownUser::getHttpRequestProvider()->getCookieManager()->setCookie("queueitdebug", implode('|', $cookieNameValues), 0, null);
385+
KnownUser::getHttpRequestProvider()->getCookieManager()->setCookie("queueitdebug", implode('|', $cookieNameValues), 0, null, false, false);
378386
}
379387
}
380388

@@ -413,12 +421,12 @@ public function getCookie($cookieName)
413421
}
414422
}
415423

416-
public function setCookie($name, $value, $expire, $domain)
424+
public function setCookie($name, $value, $expire, $domain, $isHttpOnly, $isSecure)
417425
{
418426
if ($domain == null) {
419427
$domain = "";
420428
}
421-
setcookie($name, $value, $expire, "/", $domain, false, false);
429+
setcookie($name, $value, $expire, "/", $domain, $isSecure, $isHttpOnly);
422430
}
423431

424432
public function getCookieArray()
@@ -438,6 +446,7 @@ function getUserHostAddress();
438446
function getCookieManager();
439447
function getAbsoluteUri();
440448
function getHeaderArray();
449+
function getRequestBodyAsString();
441450
}
442451

443452
class HttpRequestProvider implements IHttpRequestProvider
@@ -489,6 +498,11 @@ function getHeaderArray()
489498
}
490499
return $this->allHeadersLowerCaseKeyArray;
491500
}
501+
502+
function getRequestBodyAsString()
503+
{
504+
return '';
505+
}
492506
}
493507

494508
//https://github.com/ralouphie/getallheaders/blob/master/src/getallheaders.php

Models.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class QueueEventConfig
1111
public $extendCookieValidity;
1212
public $cookieValidityMinute;
1313
public $cookieDomain;
14+
public $isCookieHttpOnly;
15+
public $isCookieSecure;
1416
public $version;
1517
public $actionName;
1618

@@ -23,8 +25,14 @@ public function getString() {
2325
return "EventId:" . $this->eventId
2426
. "&Version:" . $this->version
2527
. "&ActionName:" . $this->actionName
26-
. "&QueueDomain:" . $this->queueDomain . "&CookieDomain:" . $this->cookieDomain . "&ExtendCookieValidity:" . $this->extendCookieValidity
27-
. "&CookieValidityMinute:" . $this->cookieValidityMinute . "&LayoutName:" . $this->layoutName . "&Culture:" . $this->culture;
28+
. "&QueueDomain:" . $this->queueDomain
29+
. "&CookieDomain:" . $this->cookieDomain
30+
. "&IsCookieHttpOnly:" . Utils::boolToString($this->isCookieHttpOnly)
31+
. "&IsCookieSecure:" . Utils::boolToString($this->isCookieSecure)
32+
. "&ExtendCookieValidity:" . Utils::boolToString($this->extendCookieValidity)
33+
. "&CookieValidityMinute:" . $this->cookieValidityMinute
34+
. "&LayoutName:" . $this->layoutName
35+
. "&Culture:" . $this->culture;
2836
}
2937
}
3038

@@ -33,6 +41,8 @@ class CancelEventConfig
3341
public $eventId;
3442
public $queueDomain;
3543
public $cookieDomain;
44+
public $isCookieHttpOnly;
45+
public $isCookieSecure;
3646
public $version;
3747
public $actionName;
3848

@@ -44,8 +54,11 @@ function __construct() {
4454
public function getString() {
4555
return "EventId:" . $this->eventId
4656
. "&Version:" . $this->version
47-
. "&ActionName:" . $this->actionName
48-
. "&QueueDomain:" . $this->queueDomain . "&CookieDomain:" . $this->cookieDomain;
57+
. "&QueueDomain:" . $this->queueDomain
58+
. "&CookieDomain:" . $this->cookieDomain
59+
. "&IsCookieHttpOnly:" . Utils::boolToString($this->isCookieHttpOnly)
60+
. "&IsCookieSecure:" . Utils::boolToString($this->isCookieSecure)
61+
. "&ActionName:" . $this->actionName;
4962
}
5063
}
5164

@@ -55,7 +68,7 @@ class RequestValidationResult
5568
public $redirectUrl;
5669
public $queueId;
5770
public $actionType;
58-
public $redirectType;
71+
public $redirectType;
5972
public $actionName;
6073
public $isAjaxResult;
6174

@@ -64,7 +77,7 @@ function __construct($actionType, $eventId, $queueId, $redirectUrl, $redirectTyp
6477
$this->eventId = $eventId;
6578
$this->queueId = $queueId;
6679
$this->redirectUrl = $redirectUrl;
67-
$this->redirectType = $redirectType;
80+
$this->redirectType = $redirectType;
6881
$this->actionName = $actionName;
6982
}
7083

QueueITHelpers.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ public static function isNullOrEmptyString($value)
88
{
99
return (!isset($value) || trim($value) === '');
1010
}
11+
12+
public static function boolToString($value)
13+
{
14+
if(is_null($value)) {
15+
return "null";
16+
}
17+
18+
return $value ? "true" : "false";
19+
}
1120
}
1221

1322
class QueueUrlParams

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ try
4747
else
4848
{
4949
header('HTTP/1.0: 200');
50-
header($result->getAjaxQueueRedirectHeaderKey() . ': '. $result->getAjaxRedirectUrl());
50+
header($result->getAjaxQueueRedirectHeaderKey() . ': ' . $result->getAjaxRedirectUrl());
51+
header("Access-Control-Expose-Headers" . ': ' . $result->getAjaxQueueRedirectHeaderKey());
5152
}
5253

5354
die();
@@ -155,3 +156,36 @@ catch(\Exception $e)
155156
// This was a configuration error, so we let the user continue
156157
}
157158
```
159+
## Request body trigger (advanced)
160+
161+
The connector supports triggering on request body content. An example could be a POST call with specific item ID where you want end-users to queue up for.
162+
For this to work, you will need to contact Queue-it support or enable request body triggers in your integration settings in your GO Queue-it platform account.
163+
Once enabled you will need to update your integration so request body is available for the connector.
164+
You need to create a new context provider similar to this one:
165+
166+
```php
167+
168+
class HttpRequestBodyProvider extends QueueIT\KnownUserV3\SDK\HttpRequestProvider
169+
{
170+
function getRequestBodyAsString()
171+
{
172+
$requestBody = file_get_contents('php://input');
173+
174+
if(isset($requestBody)){
175+
return $requestBody;
176+
}
177+
else{
178+
return '';
179+
}
180+
}
181+
}
182+
183+
```
184+
185+
And then use it instead of default `HttpRequestProvider`
186+
187+
```php
188+
// Default implementation of HttpRequestProvider always returns empty string as request body.
189+
// Use following line to set a custom httpRequestBodyProvider
190+
QueueIT\KnownUserV3\SDK\KnownUser::setHttpRequestProvider(new HttpRequestBodyProvider());
191+
```

Tests/HttpRequestProviderMock.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
class HttpRequestProviderMock implements QueueIT\KnownUserV3\SDK\IHttpRequestProvider
55
{
66
public $userAgent;
7-
public $userHostAddress;
7+
public $userHostAddress;
88
public $cookieManager;
99
public $absoluteUri;
1010
public $headerArray;
11+
public $requestBody;
1112

1213
public function getUserAgent() {
1314
return $this->userAgent;
1415
}
15-
public function getUserHostAddress() {
16-
return $this->userHostAddress;
17-
}
16+
public function getUserHostAddress() {
17+
return $this->userHostAddress;
18+
}
1819
public function getCookieManager() {
1920
return $this->cookieManager;
2021
}
@@ -26,5 +27,8 @@ public function getHeaderArray() {
2627
return array();
2728
return $this->headerArray;
2829
}
30+
public function getRequestBodyAsString() {
31+
return $this->requestBody;
32+
}
2933
}
3034
?>

0 commit comments

Comments
 (0)