Version Notes
Supports all versions of Magento
Download this release
Release Info
| Developer | Magento Core Team |
| Extension | Signifyd_Connect |
| Version | 3.5.2 |
| Comparing to | |
| See all releases | |
Code changes from version 3.5.1 to 3.5.2
app/code/community/Signifyd/Connect/Controllers/Adminhtml/SignifydController.php
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Signifyd_Connect_Adminhtml_SignifydController extends Mage_Adminhtml_Controller_Action
|
| 4 |
+
{
|
| 5 |
+
public function indexAction()
|
| 6 |
+
{
|
| 7 |
+
$this->_title($this->__('Sales'))->_title($this->__('Signifyd Scores'));
|
| 8 |
+
$this->loadLayout();
|
| 9 |
+
$this->_setActiveMenu('sales/sales');
|
| 10 |
+
$this->_addContent($this->getLayout()->createBlock('signifyd_connect/adminhtml_sales_order'));
|
| 11 |
+
$this->renderLayout();
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
public function gridAction()
|
| 15 |
+
{
|
| 16 |
+
$this->loadLayout();
|
| 17 |
+
$this->getResponse()->setBody(
|
| 18 |
+
$this->getLayout()->createBlock('signifyd_connect/adminhtml_sales_order_grid')->toHtml()
|
| 19 |
+
);
|
| 20 |
+
}
|
| 21 |
+
}
|
app/code/community/Signifyd/Connect/Controllers/ConnectController.php
ADDED
|
@@ -0,0 +1,470 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Signifyd_Connect_ConnectController extends Mage_Core_Controller_Front_Action
|
| 4 |
+
{
|
| 5 |
+
public $_request = array();
|
| 6 |
+
public $_topic = false;
|
| 7 |
+
public $_order = false;
|
| 8 |
+
public $_store_id = null;
|
| 9 |
+
public $_case = false;
|
| 10 |
+
|
| 11 |
+
public function getApiKey()
|
| 12 |
+
{
|
| 13 |
+
return Mage::getStoreConfig('signifyd_connect/settings/key');
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
public function holdThreshold()
|
| 17 |
+
{
|
| 18 |
+
return (int)Mage::getStoreConfig('signifyd_connect/advanced/hold_orders_threshold', $this->_store_id);
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
public function canHold()
|
| 22 |
+
{
|
| 23 |
+
return Mage::getStoreConfig('signifyd_connect/advanced/hold_orders', $this->_store_id);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
public function canInvoice()
|
| 27 |
+
{
|
| 28 |
+
return Mage::getStoreConfig('signifyd_connect/advanced/invoice_orders', $this->_store_id);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
public function notifyCustomer()
|
| 32 |
+
{
|
| 33 |
+
return Mage::getStoreConfig('signifyd_connect/advanced/invoice_orders_notify', $this->_store_id);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
public function enabled()
|
| 37 |
+
{
|
| 38 |
+
$retrieve_scores = Mage::getStoreConfig('signifyd_connect/advanced/retrieve_score');
|
| 39 |
+
$enabled = Mage::getStoreConfig('signifyd_connect/settings/enabled');
|
| 40 |
+
|
| 41 |
+
return $enabled && $retrieve_scores;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
public function getUrl($code)
|
| 46 |
+
{
|
| 47 |
+
return Mage::getStoreConfig('signifyd_connect/settings/url', $this->_store_id) . '/cases/' . $code;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
public function logErrors()
|
| 51 |
+
{
|
| 52 |
+
return Mage::getStoreConfig('signifyd_connect/log/error');
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
public function logRequest()
|
| 56 |
+
{
|
| 57 |
+
return Mage::getStoreConfig('signifyd_connect/log/request');
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
public function getRawPost()
|
| 61 |
+
{
|
| 62 |
+
if (isset($HTTP_RAW_POST_DATA) && $HTTP_RAW_POST_DATA) {
|
| 63 |
+
return $HTTP_RAW_POST_DATA;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
$post = file_get_contents("php://input");
|
| 67 |
+
|
| 68 |
+
if ($post) {
|
| 69 |
+
return $post;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
return '';
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
public function getDefaultMessage()
|
| 76 |
+
{
|
| 77 |
+
return 'This URL is working! Please copy & paste the current URL into your <a href="https://signifyd.com/settings">settings</a> page in the Notifications section';
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
public function getDisabledMessage()
|
| 81 |
+
{
|
| 82 |
+
return 'This URL is disabled in the Magento admin panel! Please enable score retrieval under Admin>System>Config>Signifyd Connect>Advanced before setting this url in your Signifyd <a href="https://signifyd.com/settings">settings</a> page.';
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
public function unsupported()
|
| 86 |
+
{
|
| 87 |
+
Mage::app()->getResponse()
|
| 88 |
+
->setHeader('HTTP/1.1','403 Forbidden')
|
| 89 |
+
->sendResponse();
|
| 90 |
+
echo 'This request type is currently unsupported';
|
| 91 |
+
exit;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
public function complete()
|
| 95 |
+
{
|
| 96 |
+
Mage::app()->getResponse()
|
| 97 |
+
->setHeader('HTTP/1.1','200 Ok')
|
| 98 |
+
->sendResponse();
|
| 99 |
+
|
| 100 |
+
exit;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
public function validRequest($request, $hash)
|
| 104 |
+
{
|
| 105 |
+
$check = base64_encode(hash_hmac('sha256', $request, $this->getApiKey(), true));
|
| 106 |
+
|
| 107 |
+
if ($this->logRequest()) {
|
| 108 |
+
Mage::log('API request hash check: ' . $check, null, 'signifyd_connect.log');
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
if ($check == $hash) {
|
| 112 |
+
return true;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
return false;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
public function initCase($order_increment)
|
| 119 |
+
{
|
| 120 |
+
$case = false;
|
| 121 |
+
|
| 122 |
+
if (isset($this->_request['orderId'])) {
|
| 123 |
+
$cases = Mage::getModel('signifyd_connect/case')->getCollection();
|
| 124 |
+
$cases->addFieldToFilter('order_increment', $this->_request['orderId']);
|
| 125 |
+
|
| 126 |
+
foreach ($cases as $c) {
|
| 127 |
+
$case = $c;
|
| 128 |
+
break;
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
return $case;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
public function initRequest($request)
|
| 136 |
+
{
|
| 137 |
+
$this->_request = json_decode($request, true);
|
| 138 |
+
|
| 139 |
+
$topic = $this->getHeader('X-SIGNIFYD-TOPIC');
|
| 140 |
+
|
| 141 |
+
$this->_topic = $topic;
|
| 142 |
+
|
| 143 |
+
$this->_case = $this->initCase($this->_request['orderId']);
|
| 144 |
+
|
| 145 |
+
$this->_order = Mage::getModel('sales/order')->loadByIncrementId($this->_request['orderId']);
|
| 146 |
+
|
| 147 |
+
if ($this->_order && $this->_order->getId()) {
|
| 148 |
+
$this->_store_id = $this->_order->getStoreId();
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
if (!$this->_case && $this->logRequest()) {
|
| 152 |
+
Mage::log('No matching case was found for this request. order_increment: ' . $this->_request['orderId'], null, 'signifyd_connect.log');
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
public function holdOrder($order)
|
| 157 |
+
{
|
| 158 |
+
if ($order && $order->getId() && $order->canHold() && $this->canHold()) {
|
| 159 |
+
$order->hold();
|
| 160 |
+
$order->save();
|
| 161 |
+
|
| 162 |
+
if ($this->logRequest()) {
|
| 163 |
+
Mage::log('Order ' . $order->getId() . ' held', null, 'signifyd_connect.log');
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
public function invoiceOrder($order)
|
| 169 |
+
{
|
| 170 |
+
if ($order && $order->getId() && $order->canInvoice() && $this->canInvoice()) {
|
| 171 |
+
$items = array();
|
| 172 |
+
foreach ($order->getAllItems() as $item) {
|
| 173 |
+
$items[$item->getId()] = $item->getQtyOrdered();
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
$invoice_api = Mage::getModel('sales/order_invoice_api');
|
| 177 |
+
|
| 178 |
+
try {
|
| 179 |
+
$invoice_id = $invoice_api->create($order->getIncrementId(), $items, null, false, true);
|
| 180 |
+
|
| 181 |
+
$invoice_api->capture($invoice_id);
|
| 182 |
+
} catch (Exception $e) {
|
| 183 |
+
if ($this->logErrors()) {
|
| 184 |
+
Mage::log('Exception while creating invoice: ' . $e->__toString(), null, 'signifyd_connect.log');
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
public function processAdditional($case, $original_status=false)
|
| 191 |
+
{
|
| 192 |
+
if ($this->canHold() || $this->canInvoice()) {
|
| 193 |
+
$order = $this->_order;
|
| 194 |
+
$held = false;
|
| 195 |
+
|
| 196 |
+
if ($order && $order->getId() && $this->canHold()) {
|
| 197 |
+
$threshold = $this->holdThreshold();
|
| 198 |
+
|
| 199 |
+
if (!$original_status || $original_status == 'PENDING') {
|
| 200 |
+
if ($threshold && $case->getScore() <= $threshold) {
|
| 201 |
+
$this->holdOrder($order);
|
| 202 |
+
$held = true;
|
| 203 |
+
}
|
| 204 |
+
} else if ($original_status) {
|
| 205 |
+
if ($this->_request['reviewDisposition'] == 'FRAUDULENT') {
|
| 206 |
+
if ($order->canHold()) {
|
| 207 |
+
$order->hold();
|
| 208 |
+
$order->save();
|
| 209 |
+
|
| 210 |
+
if ($this->logRequest()) {
|
| 211 |
+
Mage::log('Order ' . $order->getId() . ' held', null, 'signifyd_connect.log');
|
| 212 |
+
}
|
| 213 |
+
}
|
| 214 |
+
} else if ($this->_request['reviewDisposition'] == 'GOOD') {
|
| 215 |
+
if ($order->canUnhold()) {
|
| 216 |
+
$order->unhold();
|
| 217 |
+
$order->save();
|
| 218 |
+
|
| 219 |
+
if ($this->logRequest()) {
|
| 220 |
+
Mage::log('Order ' . $order->getId() . ' unheld', null, 'signifyd_connect.log');
|
| 221 |
+
}
|
| 222 |
+
}
|
| 223 |
+
}
|
| 224 |
+
}
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
if ($order && $order->getId() && $this->canInvoice() && !$held && !$original_status) {
|
| 228 |
+
$this->invoiceOrder($order);
|
| 229 |
+
}
|
| 230 |
+
}
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
public function processCreation()
|
| 234 |
+
{
|
| 235 |
+
$case = $this->_case;
|
| 236 |
+
|
| 237 |
+
if (!$case) {
|
| 238 |
+
return;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
if (isset($this->_request['score'])) {
|
| 242 |
+
$case->setScore($this->_request['score']);
|
| 243 |
+
|
| 244 |
+
if ($this->logRequest()) {
|
| 245 |
+
Mage::log('Set score to ' . $this->_request['score'], null, 'signifyd_connect.log');
|
| 246 |
+
}
|
| 247 |
+
} else {
|
| 248 |
+
if ($this->logRequest()) {
|
| 249 |
+
Mage::log('No score value available', null, 'signifyd_connect.log');
|
| 250 |
+
}
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
if (isset($this->_request['status'])) {
|
| 254 |
+
$case->setSignifydStatus($this->_request['status']);
|
| 255 |
+
|
| 256 |
+
if ($this->logRequest()) {
|
| 257 |
+
Mage::log('Set status to ' . $this->_request['status'], null, 'signifyd_connect.log');
|
| 258 |
+
}
|
| 259 |
+
} else {
|
| 260 |
+
if ($this->logRequest()) {
|
| 261 |
+
Mage::log('No status value available', null, 'signifyd_connect.log');
|
| 262 |
+
}
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
$case->setUpdated(strftime('%Y-%m-%d %H:%M:%S', time()));
|
| 266 |
+
$case->save();
|
| 267 |
+
|
| 268 |
+
if ($this->logRequest()) {
|
| 269 |
+
Mage::log('Case ' . $case->getId() . ' created with status ' . $case->getSignifydStatus() . ' and score ' . $case->getScore(), null, 'signifyd_connect.log');
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
$this->processAdditional($case);
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
public function processReview()
|
| 276 |
+
{
|
| 277 |
+
$case = $this->_case;
|
| 278 |
+
|
| 279 |
+
if (!$case) {
|
| 280 |
+
return;
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
$original_status = $case->getSignifydStatus();
|
| 284 |
+
|
| 285 |
+
if (isset($this->_request['score'])) {
|
| 286 |
+
$case->setScore($this->_request['score']);
|
| 287 |
+
|
| 288 |
+
if ($this->logRequest()) {
|
| 289 |
+
Mage::log('Set score to ' . $this->_request['score'], null, 'signifyd_connect.log');
|
| 290 |
+
}
|
| 291 |
+
} else {
|
| 292 |
+
if ($this->logRequest()) {
|
| 293 |
+
Mage::log('No score value available', null, 'signifyd_connect.log');
|
| 294 |
+
}
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
if (isset($this->_request['status'])) {
|
| 298 |
+
$case->setSignifydStatus($this->_request['status']);
|
| 299 |
+
|
| 300 |
+
if ($this->logRequest()) {
|
| 301 |
+
Mage::log('Set status to ' . $this->_request['status'], null, 'signifyd_connect.log');
|
| 302 |
+
}
|
| 303 |
+
} else {
|
| 304 |
+
if ($this->logRequest()) {
|
| 305 |
+
Mage::log('No status value available', null, 'signifyd_connect.log');
|
| 306 |
+
}
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
$case->setUpdated(strftime('%Y-%m-%d %H:%M:%S', time()));
|
| 310 |
+
$case->save();
|
| 311 |
+
|
| 312 |
+
$this->processAdditional($case, $original_status);
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
public function caseLookup()
|
| 316 |
+
{
|
| 317 |
+
$result = false;
|
| 318 |
+
$case = $this->_case;
|
| 319 |
+
|
| 320 |
+
try {
|
| 321 |
+
$url = $this->getUrl($case->getCode());
|
| 322 |
+
|
| 323 |
+
$response = Mage::helper('signifyd_connect')->request($url, null, $this->getApiKey(), null, 'application/json');
|
| 324 |
+
|
| 325 |
+
$response_code = $response->getHttpCode();
|
| 326 |
+
|
| 327 |
+
if (substr($response_code, 0, 1) == '2') {
|
| 328 |
+
$result = json_decode($response->getRawResponse(), true);
|
| 329 |
+
} else {
|
| 330 |
+
if ($this->logRequest()) {
|
| 331 |
+
Mage::log('Fallback request received a ' . $response_code . ' response from Signifyd', null, 'signifyd_connect.log');
|
| 332 |
+
}
|
| 333 |
+
}
|
| 334 |
+
} catch (Exception $e) {
|
| 335 |
+
if ($this->logErrors()) {
|
| 336 |
+
Mage::log('Fallback issue: ' . $e->__toString(), null, 'signifyd_connect.log');
|
| 337 |
+
}
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
return $result;
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
public function processFallback($request)
|
| 344 |
+
{
|
| 345 |
+
if ($this->logRequest()) {
|
| 346 |
+
Mage::log('Attempting auth via fallback request', null, 'signifyd_connect.log');
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
$request = json_decode($request, true);
|
| 350 |
+
|
| 351 |
+
$this->_topic = "cases/review"; // Topic header is most likely not available
|
| 352 |
+
|
| 353 |
+
if (is_array($request) && isset($request['orderId'])) {
|
| 354 |
+
$cases = Mage::getModel('signifyd_connect/case')->getCollection();
|
| 355 |
+
$cases->addFieldToFilter('order_increment', $request['orderId']);
|
| 356 |
+
|
| 357 |
+
foreach ($cases as $case) {
|
| 358 |
+
$this->_case = $case;
|
| 359 |
+
break;
|
| 360 |
+
}
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
$this->_order = Mage::getModel('sales/order')->loadByIncrementId($this->_request['orderId']);
|
| 364 |
+
|
| 365 |
+
if ($this->_order && $this->_order->getId()) {
|
| 366 |
+
$this->_store_id = $this->_order->getStoreId();
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
if ($this->_case) {
|
| 370 |
+
$lookup = $this->caseLookup();
|
| 371 |
+
|
| 372 |
+
if ($lookup && is_array($lookup)) {
|
| 373 |
+
$this->_request = $lookup;
|
| 374 |
+
|
| 375 |
+
$this->processReview();
|
| 376 |
+
} else {
|
| 377 |
+
if ($this->logRequest()) {
|
| 378 |
+
Mage::log('Fallback failed with an invalid response from Signifyd', null, 'signifyd_connect.log');
|
| 379 |
+
}
|
| 380 |
+
}
|
| 381 |
+
} else {
|
| 382 |
+
if ($this->logRequest()) {
|
| 383 |
+
Mage::log('Fallback failed with no matching case found', null, 'signifyd_connect.log');
|
| 384 |
+
}
|
| 385 |
+
}
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
public function getHeader($header)
|
| 389 |
+
{
|
| 390 |
+
// T379: Some frameworks add an extra HTTP_ before the header, so check for both names
|
| 391 |
+
// Header values stored in the $_SERVER variable have dashes converted to underscores, hence str_replace
|
| 392 |
+
$direct = strtoupper(str_replace('-', '_', $header));
|
| 393 |
+
$extraHttp = 'HTTP_' . $direct;
|
| 394 |
+
|
| 395 |
+
// Check the $_SERVER global
|
| 396 |
+
if (isset($_SERVER[$direct])) {
|
| 397 |
+
return $_SERVER[$direct];
|
| 398 |
+
} else if (isset($_SERVER[$extraHttp])) {
|
| 399 |
+
return $_SERVER[$extraHttp];
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
Mage::log('Valid Header Not Found: ' . $header, null, 'signifyd_connect.log');
|
| 403 |
+
return '';
|
| 404 |
+
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
public function apiAction()
|
| 408 |
+
{
|
| 409 |
+
if (!$this->enabled()) {
|
| 410 |
+
echo $this->getDisabledMessage();
|
| 411 |
+
|
| 412 |
+
return;
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
$request = $this->getRawPost();
|
| 416 |
+
|
| 417 |
+
$hash = $this->getHeader('X-SIGNIFYD-SEC-HMAC-SHA256');
|
| 418 |
+
|
| 419 |
+
if ($this->logRequest()) {
|
| 420 |
+
Mage::log('API request: ' . $request, null, 'signifyd_connect.log');
|
| 421 |
+
Mage::log('API request hash: ' . $hash, null, 'signifyd_connect.log');
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
if ($request) {
|
| 425 |
+
if ($this->validRequest($request, $hash)) {
|
| 426 |
+
$this->initRequest($request);
|
| 427 |
+
|
| 428 |
+
$topic = $this->_topic;
|
| 429 |
+
|
| 430 |
+
if ($this->logRequest()) {
|
| 431 |
+
Mage::log('API request topic: ' . $topic, null, 'signifyd_connect.log');
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
switch ($topic) {
|
| 435 |
+
case "cases/creation":
|
| 436 |
+
try {
|
| 437 |
+
$this->processCreation($request);
|
| 438 |
+
} catch (Exception $e) {
|
| 439 |
+
if ($this->logErrors()) {
|
| 440 |
+
Mage::log('Case scoring issue: ' . $e->__toString(), null, 'signifyd_connect.log');
|
| 441 |
+
}
|
| 442 |
+
}
|
| 443 |
+
break;
|
| 444 |
+
case "cases/rescore":
|
| 445 |
+
case "cases/review":
|
| 446 |
+
try {
|
| 447 |
+
$this->processReview($request);
|
| 448 |
+
} catch (Exception $e) {
|
| 449 |
+
if ($this->logErrors()) {
|
| 450 |
+
Mage::log('Case review issue: ' . $e->__toString(), null, 'signifyd_connect.log');
|
| 451 |
+
}
|
| 452 |
+
}
|
| 453 |
+
break;
|
| 454 |
+
default:
|
| 455 |
+
$this->unsupported();
|
| 456 |
+
}
|
| 457 |
+
} else {
|
| 458 |
+
if ($this->logRequest()) {
|
| 459 |
+
Mage::log('API request failed auth', null, 'signifyd_connect.log');
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
$this->processFallback($request);
|
| 463 |
+
}
|
| 464 |
+
} else {
|
| 465 |
+
echo $this->getDefaultMessage();
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
$this->complete();
|
| 469 |
+
}
|
| 470 |
+
}
|
package.xml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>Signifyd_Connect</name>
|
| 4 |
-
<version>3.5.
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
|
| 7 |
<channel>community</channel>
|
|
@@ -10,9 +10,9 @@
|
|
| 10 |
<description>Supports all versions of Magento</description>
|
| 11 |
<notes>Supports all versions of Magento</notes>
|
| 12 |
<authors><author><name>signifyd</name><user>auto-converted</user><email>manelis@signifyd.com</email></author></authors>
|
| 13 |
-
<date>2015-
|
| 14 |
-
<time>
|
| 15 |
-
<contents><target name="mageetc"><dir name="modules"><file name="Signifyd_Connect.xml" hash="bcd998a24567eba8a20423c40fba2adf"/></dir></target><target name="magecommunity"><dir name="Signifyd"><dir name="Connect"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="Grid.php" hash="fcdcd4cb2933147e4b573b4fb7217992"/></dir><file name="Order.php" hash="e49f869c0aa5fb3ab6b70fb5752049ac"/></dir></dir><file name="Renderer.php" hash="5564e9c6926afbbdade26a6fe746948a"/></dir><dir name="Helper"><file name="Data.php" hash="2b4ecd3e91506eed6d155f8f6e299507"/></dir><dir name="Model"><dir name="Resource"><dir name="Case"><file name="Collection.php" hash="b7dac9979a0c81db56294d1548570fc2"/></dir><file name="Case.php" hash="621fb50264bd0cdeba720dee6949a0bf"/></dir><file name="Case.php" hash="92e044f7414eddfe084320b4a2098cee"/><file name="Cron.php" hash="51665978bd2bcf67b493f2a2b450d1b8"/><file name="Link.php" hash="0027fc75ef766aa1f51a004305987937"/><file name="Observer.php" hash="2215026284b8f4fe415380ea0cdb19f1"/><file name="Setup.php" hash="e803ffb4b86c7d8ec1d149e665d65877"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="SignifydController.php" hash="937fa40bfd59857c738691e0fc6594e7"/></dir><file name="ConnectController.php" hash="4d5cf9c36b3a72e8f1d1f80aa4752b26"/></dir><dir name="etc"><file name="adminhtml.xml" hash="894bd3f5ac76e9f602ab6ab592648b03"/><file name="config.xml" hash="ccc20c3f6832e2e85faa20855fcca529"/><file name="system.xml" hash="dc115570682f75c6666d5b4657db729f"/></dir><dir name="sql"><dir name="signifyd_connect_setup"><file name="mysql4-install-3.1.1.php" hash="7fb2ccaf8352eea26e626ace6de53d80"/><file name="mysql4-install-3.3.0.php" hash="f61d0c018b28ae04d8d14b38556d18ad"/><file name="mysql4-install-3.4.0.php" hash="109cc5ca60974d0c4755dcb0f5ade3e7"/><file name="mysql4-install-3.4.5.php" hash="401b92235c0e534c941a64c60d24b851"/><file name="mysql4-upgrade-3.2.0-3.2.1.php" hash="9e36c608afd6e30e3052334e085eeff4"/><file name="mysql4-upgrade-3.2.1-3.2.2.php" hash="efcc5d46a41e549e508a693f1e77bf44"/><file name="mysql4-upgrade-3.2.2-3.2.3.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.2.3-3.3.0.php" hash="94b907c2cacde5fb9831408ce9a06190"/><file name="mysql4-upgrade-3.3.0-3.4.0.php" hash="6eb18705081483bb8d9c14adcdefd095"/><file name="mysql4-upgrade-3.4.0-3.4.1.php" hash="79f2064f1fa20d646e66aa3e7912d2a0"/><file name="mysql4-upgrade-3.4.1-3.4.2.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.4.2-3.4.3.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.4.3-3.4.4.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.4.4-3.4.5.php" hash="5b7507d6bb97bf44d27b7a89c56924bb"/><file name="mysql4-upgrade-3.4.5-3.4.6.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.4.6-3.4.7.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.4.7-3.4.8.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.4.8-3.4.9.php" hash="3ceb86495f33475774d4fc8727254cfc"/></dir></dir></dir></dir></target></contents>
|
| 16 |
<compatible/>
|
| 17 |
<dependencies/>
|
| 18 |
</package>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>Signifyd_Connect</name>
|
| 4 |
+
<version>3.5.2</version>
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
|
| 7 |
<channel>community</channel>
|
| 10 |
<description>Supports all versions of Magento</description>
|
| 11 |
<notes>Supports all versions of Magento</notes>
|
| 12 |
<authors><author><name>signifyd</name><user>auto-converted</user><email>manelis@signifyd.com</email></author></authors>
|
| 13 |
+
<date>2015-03-15</date>
|
| 14 |
+
<time>23:22:11</time>
|
| 15 |
+
<contents><target name="mageetc"><dir name="modules"><file name="Signifyd_Connect.xml" hash="bcd998a24567eba8a20423c40fba2adf"/></dir></target><target name="magecommunity"><dir name="Signifyd"><dir name="Connect"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="Grid.php" hash="fcdcd4cb2933147e4b573b4fb7217992"/></dir><file name="Order.php" hash="e49f869c0aa5fb3ab6b70fb5752049ac"/></dir></dir><file name="Renderer.php" hash="5564e9c6926afbbdade26a6fe746948a"/></dir><dir name="Controllers"><dir name="Adminhtml"><file name="SignifydController.php" hash="937fa40bfd59857c738691e0fc6594e7"/></dir><file name="ConnectController.php" hash="4d5cf9c36b3a72e8f1d1f80aa4752b26"/></dir><dir name="Helper"><file name="Data.php" hash="2b4ecd3e91506eed6d155f8f6e299507"/></dir><dir name="Model"><dir name="Resource"><dir name="Case"><file name="Collection.php" hash="b7dac9979a0c81db56294d1548570fc2"/></dir><file name="Case.php" hash="621fb50264bd0cdeba720dee6949a0bf"/></dir><file name="Case.php" hash="92e044f7414eddfe084320b4a2098cee"/><file name="Cron.php" hash="51665978bd2bcf67b493f2a2b450d1b8"/><file name="Link.php" hash="0027fc75ef766aa1f51a004305987937"/><file name="Observer.php" hash="2215026284b8f4fe415380ea0cdb19f1"/><file name="Setup.php" hash="e803ffb4b86c7d8ec1d149e665d65877"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="SignifydController.php" hash="937fa40bfd59857c738691e0fc6594e7"/></dir><file name="ConnectController.php" hash="4d5cf9c36b3a72e8f1d1f80aa4752b26"/></dir><dir name="etc"><file name="adminhtml.xml" hash="894bd3f5ac76e9f602ab6ab592648b03"/><file name="config.xml" hash="ccc20c3f6832e2e85faa20855fcca529"/><file name="system.xml" hash="dc115570682f75c6666d5b4657db729f"/></dir><dir name="sql"><dir name="signifyd_connect_setup"><file name="mysql4-install-3.1.1.php" hash="7fb2ccaf8352eea26e626ace6de53d80"/><file name="mysql4-install-3.3.0.php" hash="f61d0c018b28ae04d8d14b38556d18ad"/><file name="mysql4-install-3.4.0.php" hash="109cc5ca60974d0c4755dcb0f5ade3e7"/><file name="mysql4-install-3.4.5.php" hash="401b92235c0e534c941a64c60d24b851"/><file name="mysql4-upgrade-3.2.0-3.2.1.php" hash="9e36c608afd6e30e3052334e085eeff4"/><file name="mysql4-upgrade-3.2.1-3.2.2.php" hash="efcc5d46a41e549e508a693f1e77bf44"/><file name="mysql4-upgrade-3.2.2-3.2.3.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.2.3-3.3.0.php" hash="94b907c2cacde5fb9831408ce9a06190"/><file name="mysql4-upgrade-3.3.0-3.4.0.php" hash="6eb18705081483bb8d9c14adcdefd095"/><file name="mysql4-upgrade-3.4.0-3.4.1.php" hash="79f2064f1fa20d646e66aa3e7912d2a0"/><file name="mysql4-upgrade-3.4.1-3.4.2.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.4.2-3.4.3.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.4.3-3.4.4.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.4.4-3.4.5.php" hash="5b7507d6bb97bf44d27b7a89c56924bb"/><file name="mysql4-upgrade-3.4.5-3.4.6.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.4.6-3.4.7.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.4.7-3.4.8.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.4.8-3.4.9.php" hash="3ceb86495f33475774d4fc8727254cfc"/></dir></dir></dir></dir></target></contents>
|
| 16 |
<compatible/>
|
| 17 |
<dependencies/>
|
| 18 |
</package>
|
