Skip to content

Commit

Permalink
Merge pull request #51 from signifyd/4.2
Browse files Browse the repository at this point in the history
4.2.0
  • Loading branch information
ebanolopes authored Jul 6, 2021
2 parents 779bd3c + 28c7d83 commit 23480ac
Show file tree
Hide file tree
Showing 33 changed files with 1,044 additions and 197 deletions.
56 changes: 56 additions & 0 deletions Block/Adminhtml/Grid/Column/SignifydGuarantee.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Signifyd\Connect\Block\Adminhtml\Grid\Column;

use Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer;
use Signifyd\Connect\Model\ResourceModel\Casedata as CasedataResourceModel;
use Signifyd\Connect\Model\CasedataFactory;

class SignifydGuarantee extends AbstractRenderer
{
/**
* @var CasedataResourceModel
*/
protected $casedataResourceModel;

/**
* @var CasedataFactory
*/
protected $casedataFactory;

/**
* SignifydGuarantee constructor.
* @param CasedataResourceModel $casedataResourceModel
* @param CasedataFactory $casedataFactory
* @param \Magento\Backend\Block\Context $context
* @param array $data
*/
public function __construct(
CasedataResourceModel $casedataResourceModel,
CasedataFactory $casedataFactory,
\Magento\Backend\Block\Context $context,
array $data = []
) {
$this->casedataResourceModel = $casedataResourceModel;
$this->casedataFactory = $casedataFactory;
parent::__construct($context, $data);
}

public function render(\Magento\Framework\DataObject $row)
{
$return = '';
$quoteId = $row->getData('quote_id');

/** @var \Signifyd\Connect\Model\Casedata $case */
$case = $this->casedataFactory->create();
$this->casedataResourceModel->load($case, $quoteId, 'quote_id');

if ($case->isEmpty() === false) {
$guarantee = $case->getGuarantee();
$url = "https://www.signifyd.com/cases/" . $case->getCode();
$return = "<a href=\"$url\" target=\"_blank\">$guarantee</a>";
}

return $return;
}
}
67 changes: 67 additions & 0 deletions Block/Adminhtml/Shopcart/Abandoned/Grid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Signifyd\Connect\Block\Adminhtml\Shopcart\Abandoned;

use Magento\Store\Model\ScopeInterface;
use Signifyd\Connect\Helper\PurchaseHelper;

class Grid extends \Magento\Reports\Block\Adminhtml\Shopcart\Abandoned\Grid
{
/**
* @var PurchaseHelper
*/
protected $purchaseHelper;

/**
* Grid constructor.
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Backend\Helper\Data $backendHelper
* @param \Magento\Reports\Model\ResourceModel\Quote\CollectionFactory $quotesFactory
* @param PurchaseHelper $purchaseHelper
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Backend\Helper\Data $backendHelper,
\Magento\Reports\Model\ResourceModel\Quote\CollectionFactory $quotesFactory,
PurchaseHelper $purchaseHelper,
array $data = []
) {
$this->purchaseHelper = $purchaseHelper;
parent::__construct($context, $backendHelper, $quotesFactory, $data);
}

/**
* Prepare columns
*
* @return \Magento\Backend\Block\Widget\Grid\Extended
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function _prepareColumns()
{
$return = parent::_prepareColumns();

if ($this->getRequest()->getParam('store')) {
$storeId = (int)$this->getRequest()->getParam('store');
$policyName = $this->purchaseHelper->getPolicyName(ScopeInterface::SCOPE_STORES, $storeId);
} else {
$policyName = $this->purchaseHelper->getPolicyName();
}

if ($policyName == 'PRE_AUTH') {
$this->addColumn(
'signifyd_guarantee',
[
'header' => __('Signifyd Decision'),
'index' => 'signifyd_guarantee',
'sortable' => false,
'header_css_class' => 'col-name',
'column_css_class' => 'col-name',
'renderer' => \Signifyd\Connect\Block\Adminhtml\Grid\Column\SignifydGuarantee::class
]
);
}

return $return;
}
}
37 changes: 23 additions & 14 deletions Controller/Webhooks/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,32 +175,36 @@ public function processRequest($request, $hash, $topic)
return;
}

if (isset($requestJson->caseId) === false) {
$httpCode = Http::STATUS_CODE_200;
throw new LocalizedException(__("Invalid body, no 'caseId' field found on request"));
}

/** @var $case \Signifyd\Connect\Model\Casedata */
$case = $this->casedataFactory->create();
$this->casedataResourceModel->loadForUpdate($case, $requestJson->caseId, 'code');

switch ($topic) {
case 'cases/test':
// Test is only verifying that the endpoint is reachable. So we just complete here
$this->getResponse()->setStatusCode(Http::STATUS_CODE_200);
return;

case 'cases/creation':
$message = 'Case creation will not be processed by Magento';
$this->getResponse()->appendBody($message);
$this->logger->debug("WEBHOOK: {$message}");
$this->getResponse()->setStatusCode(Http::STATUS_CODE_200);
return;
if ($this->configHelper->isScoreOnly() === false) {
$message = 'Case creation will not be processed by Magento';
$this->getResponse()->appendBody($message);
$this->logger->debug("WEBHOOK: {$message}");
$this->getResponse()->setStatusCode(Http::STATUS_CODE_200);
return;
}
break;
}

$this->emulation->startEnvironmentEmulation(0, 'adminhtml');

try {
if (isset($requestJson->caseId) === false) {
$httpCode = Http::STATUS_CODE_200;
throw new LocalizedException(__("Invalid body, no 'caseId' field found on request"));
}

$httpCode = null;
/** @var $case \Signifyd\Connect\Model\Casedata */
$case = $this->casedataFactory->create();
$this->casedataResourceModel->loadForUpdate($case, $requestJson->caseId, 'code');

if ($case->isEmpty()) {
$httpCode = Http::STATUS_CODE_400;
Expand All @@ -218,7 +222,10 @@ public function processRequest($request, $hash, $topic)
} elseif ($case->getMagentoStatus() == Casedata::WAITING_SUBMISSION_STATUS) {
$httpCode = Http::STATUS_CODE_400;
throw new LocalizedException(__("Case {$requestJson->caseId} it is not ready to be updated"));
} elseif ($case->getMagentoStatus() == Casedata::COMPLETED_STATUS) {
} elseif ($case->getMagentoStatus() == Casedata::COMPLETED_STATUS &&
$this->configHelper->isScoreOnly() === false &&
$topic != 'cases/review'
) {
$httpCode = Http::STATUS_CODE_200;
throw new LocalizedException(
__("Case {$requestJson->caseId} already completed, no action will be taken")
Expand All @@ -232,6 +239,8 @@ public function processRequest($request, $hash, $topic)

$this->logger->info("WEBHOOK: Processing case {$case->getId()}");

$this->emulation->startEnvironmentEmulation(0, 'adminhtml');

$currentCaseHash = sha1(implode(',', $case->getData()));
$case->updateCase($requestJson);
$newCaseHash = sha1(implode(',', $case->getData()));
Expand Down
42 changes: 42 additions & 0 deletions Helper/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,46 @@ public function isScoreOnly()
{
return (bool) $this->scopeConfigInterface->getValue('signifyd/general/score_only');
}

public function getDecisionRequest()
{
return $this->scopeConfigInterface->getValue('signifyd/general/decision_request');
}

public function getGuaranteesReviewedAction()
{
return $this->scopeConfigInterface->getValue('signifyd/advanced/guarantees_reviewed_action');
}

/**
* Get restricted payment methods from store configs
*
* @return array|mixed
*/
public function getRestrictedPaymentMethodsConfig()
{
$restrictedPaymentMethods = $this->getConfigData('signifyd/general/restrict_payment_methods');
$restrictedPaymentMethods = explode(',', $restrictedPaymentMethods);
$restrictedPaymentMethods = array_map('trim', $restrictedPaymentMethods);

return $restrictedPaymentMethods;
}

/**
* Check if there is any restrictions by payment method or state
*
* @param $method
* @param null $state
* @return bool
*/
public function isPaymentRestricted($paymentMethodCode)
{
$restrictedPaymentMethods = $this->getRestrictedPaymentMethodsConfig();

if (in_array($paymentMethodCode, $restrictedPaymentMethods)) {
return true;
}

return false;
}
}
4 changes: 2 additions & 2 deletions Helper/OrderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public function getCannotHoldReason(Order $order)
$completeCase = true;
}

if (in_array($order->getState(), $notHoldableStates)) {
if ($order->getActionFlag(Order::ACTION_FLAG_HOLD) === false) {
$reason = "order is on {$order->getState()} state";
} elseif ($order->getActionFlag(Order::ACTION_FLAG_HOLD) === false) {
} elseif (in_array($order->getState(), $notHoldableStates)) {
$reason = "order action flag is set to do not hold";
} else {
$reason = "unknown reason";
Expand Down
Loading

0 comments on commit 23480ac

Please sign in to comment.