Skip to content

Commit

Permalink
Merge branch 'master' into MAG-519
Browse files Browse the repository at this point in the history
  • Loading branch information
ebanolopes committed Jan 21, 2020
2 parents 891c6b3 + 03081df commit e38b865
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 13 deletions.
27 changes: 27 additions & 0 deletions www/magento/app/code/community/Signifyd/Connect/Model/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ public function processAdditional(Signifyd_Connect_Model_Case $case)
}

break;

case 'INELIGIBLE':
$orderModel->unholdOrder($order, "guarantee ineligible");
break;
}
} else {
$this->logger->addLog("Order {$case->getOrderIncrement()} not found", $case);
Expand Down Expand Up @@ -403,6 +407,29 @@ public function processGuarantee($case, $request)
return true;
}

public function processIneligible($case, $request)
{
if (!$case) {
return false;
}

$this->_request = $request;
$this->setPrevious($case);

try {
$case->setGuarantee('INELIGIBLE');
$case->setMagentoStatus(self::COMPLETED_STATUS);

$case->save();
$this->processAdditional($case);
} catch (Exception $e) {
$this->logger->addLog('Process ineligible error: ' . $e->__toString(), $case);
return false;
}

return true;
}

/**
* Setting the previous case guarantee and score
* @param $case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public function apiAction()
$this->getResponse()->setBody($this->getDefaultMessage());
} else {
$requestJson = json_decode($request, true);
if (empty($requestJson) || !isset($requestJson['orderId'])) {

if (empty($requestJson) || (!isset($requestJson['orderId']) && !isset($requestJson['caseId']))) {
$this->logger->addLog('API invalid request');
return;
}
Expand All @@ -127,25 +128,32 @@ public function apiAction()
return;
}

/** @var Signifyd_Connect_Model_Case $case */
$case = Mage::getModel('signifyd_connect/case')->load($requestJson['orderId']);

if (!Mage::helper('signifyd_connect')->isEnabled($case)) {
$this->logger->addLog('API extension disabled', $case);
$this->getResponse()->setBody($this->getDisabledMessage());
return;
if (isset($requestJson['orderId'])) {
/** @var Signifyd_Connect_Model_Case $case */
$case = Mage::getModel('signifyd_connect/case')->load($requestJson['orderId']);
} elseif (isset($requestJson['caseId'])) {
/** @var Signifyd_Connect_Model_Case $case */
$case = Mage::getModel('signifyd_connect/case')->load($requestJson['caseId'], 'code');
}

if ($case->isObjectNew()) {
$this->logger->addLog('Case not yet in DB. Likely timing issue. order_increment: ' . $requestJson['orderId']);
$this->logger->addLog('Case not yet in DB. Likely timing issue.');
$this->getResponse()->setHttpResponseCode(409);
return;
}

if (!Mage::helper('signifyd_connect')->isEnabled($case)) {
$this->logger->addLog('API extension disabled', $case);
$this->getResponse()->setBody($this->getDisabledMessage());
return;
}

if ($this->validateRequest($request, $hash, $case)) {
$orderId = $case->getId();

// Prevent recurring on save
if (is_null(Mage::registry('signifyd_action_' . $requestJson['orderId']))) {
Mage::register('signifyd_action_' . $requestJson['orderId'], 1);
if (is_null(Mage::registry('signifyd_action_' . $orderId))) {
Mage::register('signifyd_action_' . $orderId, 1);
}

$this->logger->addLog('API processing', $case);
Expand All @@ -161,6 +169,9 @@ public function apiAction()
case "guarantees/completion":
Mage::getModel('signifyd_connect/case')->processGuarantee($case, $requestJson);
break;
case "guarantees/ineligible":
Mage::getModel('signifyd_connect/case')->processIneligible($case, $requestJson);
break;
default:
$this->logger->addLog('API invalid topic', $case);
$this->getResponse()->setHttpResponseCode(403);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<config>
<modules>
<Signifyd_Connect>
<version>4.5.4</version>
<version>4.6.0</version>
</Signifyd_Connect>
</modules>
<global>
Expand Down
2 changes: 1 addition & 1 deletion www/magento/var/connect/Signifyd_Connect.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<description>Supports all versions of Magento</description>
<license>OSL</license>
<license_uri>http://opensource.org/licenses/osl-3.0.php</license_uri>
<version>4.5.4</version>
<version>4.6.0</version>
<stability>stable</stability>
<notes>Supports all versions of Magento</notes>
<authors>
Expand Down

0 comments on commit e38b865

Please sign in to comment.