Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/code/Riskified/Decider/Api/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,16 @@ public function getDeclineNotificationContent($scopeId = 0)
);
}

/**
* @return bool
*/
public function getCustomerLoginHandleEnabled()
{
return (bool) $this->_scopeConfig->getValue(
'riskified/riskified/connect_customer'
);
}

/**
* Sets store id.
* @param $id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace Riskified\Decider\Api\Data;

interface ClientDetailsInterface
{
public function getData();
public function getCleanData();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace Riskified\Decider\Api\Data;

interface SessionDetailsInterface
{
public function getData();
public function getCleanData();
}
50 changes: 50 additions & 0 deletions app/code/Riskified/Decider/Model/Api/Data/ClientDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
namespace Riskified\Decider\Model\Api\Data;

use Magento\Framework\HTTP\Header;
use Magento\Framework\Locale\ResolverInterface;
use Riskified\Decider\Api\Data\ClientDetailsInterface;

class ClientDetails implements ClientDetailsInterface
{
/**
* @var ResolverInterface
*/
private $localeResolver;
/**
* @var Header
*/
private $httpHeader;

/**
* ClientDetails constructor.
* @param ResolverInterface $localeResolver
* @param Header $httpHeader
*/
public function __construct(
ResolverInterface $localeResolver,
Header $httpHeader
) {
$this->localeResolver = $localeResolver;
$this->httpHeader = $httpHeader;
}

/**
* @return array
*/
public function getData()
{
return [
'accept_language' => $this->localeResolver->getLocale(),
'user_agent' => $this->httpHeader->getHttpUserAgent()
];
}

/**
* @return array
*/
public function getCleanData()
{
return array_filter($this->getData(), 'strlen');
}
}
55 changes: 55 additions & 0 deletions app/code/Riskified/Decider/Model/Api/Data/SessionDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
namespace Riskified\Decider\Model\Api\Data;

use Magento\Framework\HTTP\PhpEnvironment\RemoteAddress;
use Magento\Framework\HTTP\Header;
use Magento\Framework\Session\SessionManager;
use Riskified\Decider\Api\Data\SessionDetailsInterface;
use Riskified\Decider\Model\DateFormatter;

class SessionDetails implements SessionDetailsInterface
{
/**
* @var \Magento\Framework\Session\SessionManager
*/
private $session;
private $remoteAddress;
private $mobileAgent;
private $httpHeader;

use DateFormatter;

public function __construct(
SessionManager $sessionManager,
RemoteAddress $remoteAddress,
Header $httpHeader
) {
$this->session = $sessionManager;
$this->remoteAddress = $remoteAddress;
$this->httpHeader = $httpHeader;
}

/**
* @return array
*/
public function getData()
{
$userAgent = $this->httpHeader->getHttpUserAgent();
$isMobile = \Zend_Http_UserAgent_Mobile::match($userAgent, $_SERVER);

return [
'created_at' => $this->formatDateAsIso8601(date('Y-m-d H:i:s')),
'cart_token' => $this->session->getSessionId(),
'browser_ip' => $this->remoteAddress->getRemoteAddress(),
'source' => $isMobile ? 'mobile_web' : 'desktop_web'
];
}

/**
* @return array
*/
public function getCleanData()
{
return array_filter($this->getData(), 'strlen');
}
}
15 changes: 15 additions & 0 deletions app/code/Riskified/Decider/Model/DateFormatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace Riskified\Decider\Model;

trait DateFormatter
{
/**
* @param $dateStr
*
* @return false|null|string
*/
public function formatDateAsIso8601($dateStr)
{
return ($dateStr == null) ? null : date('c', strtotime($dateStr));
}
}
Loading