Skip to content

Commit

Permalink
Release 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavle committed Dec 2, 2021
1 parent 4f00f29 commit e509c6b
Show file tree
Hide file tree
Showing 14 changed files with 958 additions and 642 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/nbproject/private/
Tests/vendor
Tests/composer.lock
/simpletest
/.vs
24 changes: 23 additions & 1 deletion IntegrationConfigHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function getMatchedIntegrationConfig(array $customerIntegration, $current
return false;
}
if ($this->evaluateTrigger($trigger, $currentPageUrl, $request)) {
return $integrationConfig;
return $integrationConfig;
}
}
}
Expand Down Expand Up @@ -70,6 +70,8 @@ private function evaluateTriggerPart(array $triggerPart, $currentPageUrl, $reque
return UserAgentValidatorHelper::evaluate($triggerPart, $request->getUserAgent());
case "HttpHeaderValidator":
return HttpHeaderValidatorHelper::evaluate($triggerPart, $request->getHeaderArray());
case "RequestBodyValidator":
return RequestBodyValidatorHelper::evaluate($triggerPart, $request->getRequestBodyAsString());
default:
return false;
}
Expand Down Expand Up @@ -181,6 +183,26 @@ public static function evaluate(array $triggerPart, array $headerList) {
}
}

class RequestBodyValidatorHelper
{
public static function evaluate(array $triggerPart, $requestBody) {

if (!array_key_exists("Operator", $triggerPart) ||
!array_key_exists("IsNegative", $triggerPart) ||
!array_key_exists("IsIgnoreCase", $triggerPart)) {
return false;
}

return ComparisonOperatorHelper::Evaluate(
$triggerPart["Operator"],
$triggerPart["IsNegative"],
$triggerPart["IsIgnoreCase"],
$requestBody,
array_key_exists("ValueToCompare",$triggerPart)? $triggerPart["ValueToCompare"]: null,
array_key_exists("ValuesToCompare",$triggerPart)? $triggerPart["ValuesToCompare"]: null);
}
}

class ComparisonOperatorHelper
{
public static function evaluate($opt, $isNegative, $isIgnoreCase, $value, $valueToCompare, $valuesToCompare) {
Expand Down
40 changes: 27 additions & 13 deletions KnownUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class KnownUser
{
const QueueITAjaxHeaderKey = "x-queueit-ajaxpageurl";
const QueueITAjaxHeaderKey = "x-queueit-ajaxpageurl";

//used for unittest
private static $userInQueueService = null;
Expand All @@ -22,6 +22,10 @@ private static function getUserInQueueService()
return KnownUser::$userInQueueService;
}

public static function setHttpRequestProvider(IHttpRequestProvider $customHttpRequestProvider){
KnownUser::$httpRequestProvider = $customHttpRequestProvider;
}

//used for unittest
private static $httpRequestProvider = null;
private static function getHttpRequestProvider()
Expand All @@ -33,7 +37,7 @@ private static function getHttpRequestProvider()
}

private static $debugInfoArray = null;
public static function extendQueueCookie($eventId, $cookieValidityMinute, $cookieDomain, $secretKey)
public static function extendQueueCookie($eventId, $cookieValidityMinute, $cookieDomain, $isCookieHttpOnly, $isCookieSecure, $secretKey)
{
if (empty($eventId)) {
throw new KnownUserException("eventId can not be null or empty.");
Expand All @@ -45,7 +49,7 @@ public static function extendQueueCookie($eventId, $cookieValidityMinute, $cooki
throw new KnownUserException("cookieValidityMinute should be integer greater than 0.");
}
$userInQueueService = KnownUser::getUserInQueueService();
$userInQueueService->extendQueueCookie($eventId, $cookieValidityMinute, $cookieDomain, $secretKey);
$userInQueueService->extendQueueCookie($eventId, $cookieValidityMinute, $cookieDomain, $isCookieHttpOnly, $isCookieSecure, $secretKey);
}

private static function _cancelRequestByLocalConfig(
Expand Down Expand Up @@ -107,7 +111,7 @@ public static function cancelRequestByLocalConfig(
}

try {
$result = KnownUser::_cancelRequestByLocalConfig($targetUrl,$queueitToken,$cancelConfig,$customerId,$secretKey,$connectorDiagnostics->isEnabled);
$result = KnownUser::_cancelRequestByLocalConfig($targetUrl, $queueitToken, $cancelConfig, $customerId, $secretKey, $connectorDiagnostics->isEnabled);
KnownUser::sendDebugCookie();
return $result;
} catch (\Exception $e) {
Expand Down Expand Up @@ -217,14 +221,14 @@ public static function validateRequestByIntegrationConfig($currentUrlWithoutQueu
public static function resolveQueueRequestByLocalConfig($targetUrl, $queueitToken, QueueEventConfig $queueConfig, $customerId, $secretKey)
{
$connectorDiagnostics = ConnectorDiagnostics::verify($customerId, $secretKey, $queueitToken);

if ($connectorDiagnostics->hasError) {
return $connectorDiagnostics->validationResult;
}

try {
$targetUrl = KnownUser::generateTargetUrl($targetUrl);
$result = KnownUser::_resolveQueueRequestByLocalConfig($targetUrl, $queueitToken, $queueConfig, $customerId, $secretKey,$connectorDiagnostics->isEnabled);
$result = KnownUser::_resolveQueueRequestByLocalConfig($targetUrl, $queueitToken, $queueConfig, $customerId, $secretKey, $connectorDiagnostics->isEnabled);
KnownUser::sendDebugCookie();
return $result;
} catch (\Exception $e) {
Expand Down Expand Up @@ -291,12 +295,14 @@ private static function handleQueueAction(
$eventConfig = new QueueEventConfig();
$targetUrl = "";
$eventConfig->eventId = $matchedConfig["EventId"];
$eventConfig->queueDomain = $matchedConfig["QueueDomain"];
$eventConfig->layoutName = $matchedConfig["LayoutName"];
$eventConfig->culture = $matchedConfig["Culture"];
$eventConfig->cookieDomain = $matchedConfig["CookieDomain"];
$eventConfig->queueDomain = $matchedConfig["QueueDomain"];
$eventConfig->extendCookieValidity = $matchedConfig["ExtendCookieValidity"];
$eventConfig->cookieValidityMinute = $matchedConfig["CookieValidityMinute"];
$eventConfig->cookieDomain = $matchedConfig["CookieDomain"];
$eventConfig->isCookieHttpOnly = array_key_exists("IsCookieHttpOnly", $matchedConfig) ? $matchedConfig["IsCookieHttpOnly"] : false;
$eventConfig->isCookieSecure = array_key_exists("IsCookieSecure", $matchedConfig) ? $matchedConfig["IsCookieSecure"] : false;
$eventConfig->version = $customerIntegration["Version"];
$eventConfig->actionName = $matchedConfig["Name"];

Expand Down Expand Up @@ -325,10 +331,12 @@ private static function handleCancelAction(
$isDebug
) {
$cancelEventConfig = new CancelEventConfig();
$cancelEventConfig->eventId = $matchedConfig["EventId"];
$cancelEventConfig->queueDomain = $matchedConfig["QueueDomain"];
$cancelEventConfig->cookieDomain = $matchedConfig["CookieDomain"];
$cancelEventConfig->eventId = $matchedConfig["EventId"];
$cancelEventConfig->version = $customerIntegration["Version"];
$cancelEventConfig->cookieDomain = $matchedConfig["CookieDomain"];
$cancelEventConfig->isCookieHttpOnly = array_key_exists("IsCookieHttpOnly", $matchedConfig) ? $matchedConfig["IsCookieHttpOnly"] : false;
$cancelEventConfig->isCookieSecure = array_key_exists("IsCookieSecure", $matchedConfig) ? $matchedConfig["IsCookieSecure"] : false;
$cancelEventConfig->actionName = $matchedConfig["Name"];

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

Expand Down Expand Up @@ -413,12 +421,12 @@ public function getCookie($cookieName)
}
}

public function setCookie($name, $value, $expire, $domain)
public function setCookie($name, $value, $expire, $domain, $isHttpOnly, $isSecure)
{
if ($domain == null) {
$domain = "";
}
setcookie($name, $value, $expire, "/", $domain, false, false);
setcookie($name, $value, $expire, "/", $domain, $isSecure, $isHttpOnly);
}

public function getCookieArray()
Expand All @@ -438,6 +446,7 @@ function getUserHostAddress();
function getCookieManager();
function getAbsoluteUri();
function getHeaderArray();
function getRequestBodyAsString();
}

class HttpRequestProvider implements IHttpRequestProvider
Expand Down Expand Up @@ -489,6 +498,11 @@ function getHeaderArray()
}
return $this->allHeadersLowerCaseKeyArray;
}

function getRequestBodyAsString()
{
return '';
}
}

//https://github.com/ralouphie/getallheaders/blob/master/src/getallheaders.php
Expand Down
25 changes: 19 additions & 6 deletions Models.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class QueueEventConfig
public $extendCookieValidity;
public $cookieValidityMinute;
public $cookieDomain;
public $isCookieHttpOnly;
public $isCookieSecure;
public $version;
public $actionName;

Expand All @@ -23,8 +25,14 @@ public function getString() {
return "EventId:" . $this->eventId
. "&Version:" . $this->version
. "&ActionName:" . $this->actionName
. "&QueueDomain:" . $this->queueDomain . "&CookieDomain:" . $this->cookieDomain . "&ExtendCookieValidity:" . $this->extendCookieValidity
. "&CookieValidityMinute:" . $this->cookieValidityMinute . "&LayoutName:" . $this->layoutName . "&Culture:" . $this->culture;
. "&QueueDomain:" . $this->queueDomain
. "&CookieDomain:" . $this->cookieDomain
. "&IsCookieHttpOnly:" . Utils::boolToString($this->isCookieHttpOnly)
. "&IsCookieSecure:" . Utils::boolToString($this->isCookieSecure)
. "&ExtendCookieValidity:" . Utils::boolToString($this->extendCookieValidity)
. "&CookieValidityMinute:" . $this->cookieValidityMinute
. "&LayoutName:" . $this->layoutName
. "&Culture:" . $this->culture;
}
}

Expand All @@ -33,6 +41,8 @@ class CancelEventConfig
public $eventId;
public $queueDomain;
public $cookieDomain;
public $isCookieHttpOnly;
public $isCookieSecure;
public $version;
public $actionName;

Expand All @@ -44,8 +54,11 @@ function __construct() {
public function getString() {
return "EventId:" . $this->eventId
. "&Version:" . $this->version
. "&ActionName:" . $this->actionName
. "&QueueDomain:" . $this->queueDomain . "&CookieDomain:" . $this->cookieDomain;
. "&QueueDomain:" . $this->queueDomain
. "&CookieDomain:" . $this->cookieDomain
. "&IsCookieHttpOnly:" . Utils::boolToString($this->isCookieHttpOnly)
. "&IsCookieSecure:" . Utils::boolToString($this->isCookieSecure)
. "&ActionName:" . $this->actionName;
}
}

Expand All @@ -55,7 +68,7 @@ class RequestValidationResult
public $redirectUrl;
public $queueId;
public $actionType;
public $redirectType;
public $redirectType;
public $actionName;
public $isAjaxResult;

Expand All @@ -64,7 +77,7 @@ function __construct($actionType, $eventId, $queueId, $redirectUrl, $redirectTyp
$this->eventId = $eventId;
$this->queueId = $queueId;
$this->redirectUrl = $redirectUrl;
$this->redirectType = $redirectType;
$this->redirectType = $redirectType;
$this->actionName = $actionName;
}

Expand Down
9 changes: 9 additions & 0 deletions QueueITHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ public static function isNullOrEmptyString($value)
{
return (!isset($value) || trim($value) === '');
}

public static function boolToString($value)
{
if(is_null($value)) {
return "null";
}

return $value ? "true" : "false";
}
}

class QueueUrlParams
Expand Down
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ try
else
{
header('HTTP/1.0: 200');
header($result->getAjaxQueueRedirectHeaderKey() . ': '. $result->getAjaxRedirectUrl());
header($result->getAjaxQueueRedirectHeaderKey() . ': ' . $result->getAjaxRedirectUrl());
header("Access-Control-Expose-Headers" . ': ' . $result->getAjaxQueueRedirectHeaderKey());
}

die();
Expand Down Expand Up @@ -155,3 +156,36 @@ catch(\Exception $e)
// This was a configuration error, so we let the user continue
}
```
## Request body trigger (advanced)

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.
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.
Once enabled you will need to update your integration so request body is available for the connector.
You need to create a new context provider similar to this one:

```php

class HttpRequestBodyProvider extends QueueIT\KnownUserV3\SDK\HttpRequestProvider
{
function getRequestBodyAsString()
{
$requestBody = file_get_contents('php://input');

if(isset($requestBody)){
return $requestBody;
}
else{
return '';
}
}
}

```

And then use it instead of default `HttpRequestProvider`

```php
// Default implementation of HttpRequestProvider always returns empty string as request body.
// Use following line to set a custom httpRequestBodyProvider
QueueIT\KnownUserV3\SDK\KnownUser::setHttpRequestProvider(new HttpRequestBodyProvider());
```
12 changes: 8 additions & 4 deletions Tests/HttpRequestProviderMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
class HttpRequestProviderMock implements QueueIT\KnownUserV3\SDK\IHttpRequestProvider
{
public $userAgent;
public $userHostAddress;
public $userHostAddress;
public $cookieManager;
public $absoluteUri;
public $headerArray;
public $requestBody;

public function getUserAgent() {
return $this->userAgent;
}
public function getUserHostAddress() {
return $this->userHostAddress;
}
public function getUserHostAddress() {
return $this->userHostAddress;
}
public function getCookieManager() {
return $this->cookieManager;
}
Expand All @@ -26,5 +27,8 @@ public function getHeaderArray() {
return array();
return $this->headerArray;
}
public function getRequestBodyAsString() {
return $this->requestBody;
}
}
?>
Loading

0 comments on commit e509c6b

Please sign in to comment.