Skip to content

Commit

Permalink
Merge pull request #56 from signifyd/4.3.4
Browse files Browse the repository at this point in the history
4.3.4
  • Loading branch information
ebanolopes authored Jan 31, 2022
2 parents 8610bd0 + 160c86c commit c5d48bf
Show file tree
Hide file tree
Showing 23 changed files with 868 additions and 331 deletions.
48 changes: 48 additions & 0 deletions Controller/Adminhtml/MarkAsFixed/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Copyright © All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Signifyd\Connect\Controller\Adminhtml\MarkAsFixed;

use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Backend\App\Action\Context;

class Index extends \Magento\Backend\App\Action
{
/**
* @var Context
*/
protected $context;

/**
* @var WriterInterface
*/
protected $configWriter;

/**
* UpgradeSchema constructor.
* @param WriterInterface $configWriter
* @param Context $context
*/
public function __construct(
Context $context,
WriterInterface $configWriter
) {
parent::__construct($context);
$this->configWriter = $configWriter;
}

public function execute()
{
$this->configWriter->delete("signifyd/general/upgrade4.3_inconsistency");

$this->messageManager->addSuccessMessage(__('Successfully marked as fixed'));
$this->messageManager->addWarningMessage(__(
"If the inconsistency message is still visible, it's necessary to clear the config cache"
));
return $this->_redirect($this->_redirect->getRefererUrl());
}
}
52 changes: 45 additions & 7 deletions Controller/Adminhtml/Webhooks/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

use Magento\Backend\App\Action;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Filesystem\DirectoryList;
use Signifyd\Connect\Model\WebhookLink;
use Signifyd\Core\Api\WebhooksApiFactory;
use Signifyd\Models\WebhookFactory;
use Signifyd\Connect\Helper\ConfigHelper;

class Register extends Action
{
Expand Down Expand Up @@ -35,6 +37,16 @@ class Register extends Action
*/
protected $webhookFactory;

/**
* @var ConfigHelper
*/
protected $configHelper;

/**
* @var DirectoryList
*/
protected $directory;

/**
* Register constructor.
* @param Action\Context $context
Expand All @@ -43,21 +55,27 @@ class Register extends Action
* @param WebhooksApiFactory $webhooksApiFactory
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param WebhookFactory $webhookFactory
* @param ConfigHelper $configHelper
* @param DirectoryList $directory
*/
public function __construct(
Action\Context $context,
ScopeConfigInterface $scopeConfig,
WebhookLink $webhookLink,
WebhooksApiFactory $webhooksApiFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager,
WebhookFactory $webhookFactory
WebhookFactory $webhookFactory,
ConfigHelper $configHelper,
DirectoryList $directory
) {
parent::__construct($context);
$this->scopeConfig = $scopeConfig;
$this->webhookLink = $webhookLink;
$this->webhooksApiFactory = $webhooksApiFactory;
$this->storeManager = $storeManager;
$this->webhookFactory = $webhookFactory;
$this->configHelper = $configHelper;
$this->directory = $directory;
}

public function execute()
Expand All @@ -79,7 +97,10 @@ public function execute()

$apiKey = $this->scopeConfig->getValue('signifyd/general/key', $scopeType, $scopeCode);
$url = $this->webhookLink->getUrl();
$args = ['apiKey' => $apiKey];
$args = [
'apiKey' => $apiKey,
'logLocation' => $this->directory->getPath('log')
];

$webhooksApiGet = $this->webhooksApiFactory->create(['args' => $args]);

Expand All @@ -89,6 +110,7 @@ public function execute()
$bulkResponseGet = $webhooksApiGet->getWebhooks();

$decisionMadeIsSet = false;
$caseReviewIsSet = false;

foreach ($bulkResponseGet->getObjects() as $webhook) {
$webhooksApiCancel = $this->webhooksApiFactory->create(['args' => $args]);
Expand All @@ -97,17 +119,33 @@ public function execute()
$decisionMadeIsSet = true;
}

if ($webhook->eventType === 'CASE_REVIEW') {
$caseReviewIsSet = true;
}

if ($webhook->eventType === 'GUARANTEE_COMPLETION') {
$webhooksApiCancel->deleteWebhook($webhook);
}
}

if ($decisionMadeIsSet === false) {
if ($decisionMadeIsSet === false || $caseReviewIsSet === false) {
$webhooksApiCreate = $this->webhooksApiFactory->create(['args' => $args]);
$webHookGuaranteeCompletion = $this->webhookFactory->create();
$webHookGuaranteeCompletion->setEvent('DECISION_MADE');
$webHookGuaranteeCompletion->setUrl($url);
$webhooksToCreate = [$webHookGuaranteeCompletion];
$webhooksToCreate = [];

if ($decisionMadeIsSet === false) {
$webHookDecisionMade = $this->webhookFactory->create();
$webHookDecisionMade->setEvent('DECISION_MADE');
$webHookDecisionMade->setUrl($url);
$webhooksToCreate[] = $webHookDecisionMade;
}

if ($caseReviewIsSet === false) {
$webHookDecisionMade = $this->webhookFactory->create();
$webHookDecisionMade->setEvent('CASE_REVIEW');
$webHookDecisionMade->setUrl($url);
$webhooksToCreate[] = $webHookDecisionMade;
}

$webhooksApiCreate->createWebhooks($webhooksToCreate);
}
} catch (\Exception $e) {
Expand Down
64 changes: 64 additions & 0 deletions Cron/ValidateOrderId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/**
* Copyright 2016 SIGNIFYD Inc. All rights reserved.
* See LICENSE.txt for license details.
*/

namespace Signifyd\Connect\Cron;

use Signifyd\Connect\Model\ResourceModel\Casedata\CollectionFactory as CasedataCollectionFactory;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;

class ValidateOrderId
{
/**
* @var CasedataCollectionFactory
*/
protected $casedataCollection;

/**
* @var WriterInterface
*/
protected $writerInterface;

/**
* @var ScopeConfigInterface
*/
protected $scopeConfigInterface;

/**
* @param CasedataCollectionFactory $casedataCollection
* @param WriterInterface $writerInterface
* @param ScopeConfigInterface $scopeConfigInterface
*/
public function __construct(
CasedataCollectionFactory $casedataCollection,
WriterInterface $writerInterface,
ScopeConfigInterface $scopeConfigInterface
) {
$this->casedataCollection = $casedataCollection;
$this->writerInterface = $writerInterface;
$this->scopeConfigInterface = $scopeConfigInterface;
}

public function execute()
{
$upgradeInconsistency = $this->scopeConfigInterface->getValue("signifyd/general/upgrade4.3_inconsistency");

if (isset($upgradeInconsistency)) {
return;
}

/** @var \Signifyd\Connect\Model\ResourceModel\Casedata\Collection $casedataCollection */
$casedataCollection = $this->casedataCollection->create();
$casedataCollection->addFieldToFilter('order_id', ['null' => true]);

if ($casedataCollection->count() > 0) {
$this->writerInterface->save("signifyd/general/upgrade4.3_inconsistency", "cron");
} else {
$this->writerInterface->save("signifyd/general/upgrade4.3_inconsistency", "fixed");
}
}
}
22 changes: 18 additions & 4 deletions Helper/PurchaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ public function processOrderData($order)
$case['decisionRequest'] = $this->getDecisionRequest();
$case['sellers'] = $this->getSellers();
$case['tags'] = $this->getTags();
$case['purchase']['checkoutToken'] = sha1($this->jsonSerializer->serialize($case));
$case['purchase']['checkoutToken'] = uniqid();

/**
* This registry entry it's used to collect data from some payment methods like Payflow Link
Expand Down Expand Up @@ -1186,6 +1186,20 @@ public function postCaseToSignifyd($caseData, $order)
}
}

public function updateCaseSignifyd($updateData, $order, $caseId)
{
$caseResponse = $this->configHelper->getSignifydCaseApi($order)->updateCase($updateData, $caseId);

if (empty($caseResponse->getCaseId()) === false) {
$this->logger->debug("Case updated. Id is {$caseResponse->getCaseId()}", ['entity' => $order]);
return $caseResponse;
} else {
$this->logger->error($this->jsonSerializer->serialize($caseResponse));
$this->logger->error("Case failed to update.", ['entity' => $order]);
return false;
}
}

/**
* @param Order $order
* @return bool
Expand All @@ -1208,7 +1222,7 @@ public function cancelCaseOnSignifyd(Order $order)

$guarantee = $case->getData('guarantee');

if (empty($guarantee) || in_array($guarantee, ['DECLINED'])) {
if (empty($guarantee) || in_array($guarantee, ['DECLINED', 'REJECT', 'N/A'])) {
$this->logger->debug("Guarantee cancel skipped: current guarantee is {$guarantee}", ['entity' => $order]);
return false;
}
Expand Down Expand Up @@ -1466,7 +1480,7 @@ public function getBin(Order $order)
return null;
}

return $bin;
return (string) $bin;
} catch (Exception $e) {
$this->logger->error('Error fetching bin: ' . $e->getMessage(), ['entity' => $order]);
return null;
Expand Down Expand Up @@ -1519,7 +1533,7 @@ public function processQuoteData(Quote $quote, $checkoutPaymentDetails = null, $
$case['deviceFingerprints'] = $this->getDeviceFingerprints();
$case['policy'] = $this->makePolicy($quote, ScopeInterface::SCOPE_STORES, $quote->getStoreId());
$case['decisionRequest'] = $this->getDecisionRequest();
$case['purchase']['checkoutToken'] = sha1($this->jsonSerializer->serialize($case));
$case['purchase']['checkoutToken'] = uniqid();

$positiveAction = $this->configHelper->getConfigData('signifyd/advanced/guarantee_positive_action');
$transactionType = $positiveAction == 'capture' ? 'SALE' : 'AUTHORIZATION';
Expand Down
Loading

0 comments on commit c5d48bf

Please sign in to comment.