1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170:
<?php
namespace Apptus\ESales\Connector;
class JavaScriptNotifier
{
/* @internal */
const CUSTOMER_KEY_HEADER_NAME = 'eSales-customer_key';
/* @internal */
const MARKET_HEADER_NAME = 'eSales-market';
private function __construct()
{
}
/**
* Pass through a JavaScript notification to the cluster.
*
* This method is for advanced users only. If two identical notifications are sent with the same id for the same session key,
* the second notification will be ignored.
*
* @param Connector
* The eSales connector to notify through.
* @param string
* The key of the eSales session to attach the notification to.
* @param string
* Identifier for detection of re-sent notifications.
* @param string
* click|adding_to_cart|property|rating|end
* @param string
* The ticket for the object clicked or added to cart.
* @param string
* A valid Java identifier as name of the property.
* @param string
* The value of the property.
* @param string
* The key of the rated product.
* @param string
* Integer rating as a string.
* @throws RequestFailedException
* if the notification cannot be sent to the eSales service.
*
* @deprecated This method is deprecated due to severe security issues.
* It is strongly recommended not to allow client side property notifications, these should be made server side.
* Use {@link notifySafe()} for the other types of notifications.
*/
public static function notify(
Connector $connector,
$sessionKey,
$id,
$type,
$ticket,
$propertyName,
$propertyValue,
$productKey,
$rating
)
{
$params = array(
'id' => $id,
'ticket' => $ticket,
'name' => $propertyName,
'value' => $propertyValue,
'product_key' => $productKey,
'rating' => $rating,
'session_key' => $sessionKey,
);
$connector->cluster->notify('/' . $type, $params);
}
/**
* Pass through a JavaScript notification to the cluster.
*
* This method is for advanced users only. If two identical notifications are sent with the same id for the same session key,
* the second notification will be ignored.
*
* @param Connector
* The eSales connector to notify through.
* @param string
* The key of the eSales session to attach the notification to.
* @param string
* Identifier for detection of re-sent notifications.
* @param string
* click|adding_to_cart|rating|end
* @param string
* The ticket for the object clicked or added to cart.
* @param string
* The key of the rated product.
* @param string
* Integer rating as a string.
* @throws RequestFailedException
* if the notification cannot be sent to the eSales service.
*/
public static function notifySafe(
Connector $connector,
$sessionKey,
$id,
$type,
$ticket,
$productKey,
$rating
)
{
$params = array(
'id' => $id,
'ticket' => $ticket,
'product_key' => $productKey,
'rating' => $rating,
'session_key' => $sessionKey,
);
$connector->cluster->notify('/' . $type, $params);
}
/**
* Pass through a JavaScript notification to the cluster.
*
* This method is for advanced users only. If two identical notifications are sent with the same id for the same session key,
* the second notification will be ignored.
*
* @param Connector
* The eSales connector to notify through.
* @param string
* The key of the eSales session to attach the notification to.
* @param string
* The key of the customer for the notification.
* Warning! Must not be taken from the client, as this will pose a security threat.
* @param string
* The market for which the notification is made.
* Warning! Must not be taken from the client, as this will pose a security threat.
* @param string
* Identifier for detection of re-sent notifications.
* @param string
* click|adding_to_cart|property|rating|end
* @param string
* The ticket for the object clicked or added to cart.
* @param string
* The key of the rated product.
* @param string
* Integer rating as a string.
* @throws RequestFailedException
* if the notification cannot be sent to the eSales service.
*
* Warning! It is strongly recommended not to allow client side property notifications, these should be made from the server.
*/
public static function notifyWithProperties(
Connector $connector,
$sessionKey,
$customerKey,
$market,
$id,
$type,
$ticket,
$productKey,
$rating)
{
$params = array(
'id' => $id,
'ticket' => $ticket,
'product_key' => $productKey,
'rating' => $rating,
'session_key' => $sessionKey,
);
$headers = array(
self::CUSTOMER_KEY_HEADER_NAME => $customerKey,
self::MARKET_HEADER_NAME => $market,
);
$connector->cluster->notify('/' . $type, $params, $headers);
}
}