Skip to content

Commit

Permalink
Merge pull request #7 from bayonetio/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
imran-arshad authored Dec 24, 2020
2 parents d287325 + 4f57602 commit f23640a
Show file tree
Hide file tree
Showing 67 changed files with 4,979 additions and 1 deletion.
145 changes: 145 additions & 0 deletions Block/Adminhtml/OrderEdit/Tab/View.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?php

namespace Bayonet\BayonetAntiFraud\Block\Adminhtml\OrderEdit\Tab;

use \Bayonet\BayonetAntiFraud\Helper\DirectQuery;
use \Magento\Backend\Block\Template;
use \Magento\Backend\Block\Widget\Tab\TabInterface;

/**
* Order custom tab
*/
class View extends Template implements TabInterface
{
protected $_template = 'tab/view/my_order_info.phtml';
protected $directQuery;

public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
DirectQuery $directQuery,
array $data = []
) {
parent::__construct($context, $data);
$this->_coreRegistry = $registry;
$this->directQuery = $directQuery;
}

/**
* Retrieve order model instance
*
* @return \Magento\Sales\Model\Order
*/
public function getOrder()
{
return $this->_coreRegistry->registry('current_order');
}

/**
* Retrieve order model instance
*
* @return \Magento\Sales\Model\Order
*/
public function getOrderId()
{
return $this->getOrder()->getEntityId();
}

/**
* Retrieve order increment id
*
* @return string
*/
public function getOrderIncrementId()
{
return $this->getOrder()->getIncrementId();
}

/**
* {@inheritdoc}
*/
public function getTabLabel()
{
return __('Bayonet Anti-Fraud');
}

/**
* Gets the Bayonet Tracking ID of an order
*
* @return string
*/
public function getTrackingId()
{
return $this->directQuery->customQuery(
'bayonet_antifraud_orders',
'bayonet_tracking_id',
['order_id' => $this->getOrderId()]
);
}

/**
* Gets the Bayonet API response of an order
*
* @return string
*/
public function getApiResponse()
{
return $this->directQuery->customQuery(
'bayonet_antifraud_orders',
'consulting_api_response',
['order_id' => $this->getOrderId()]
);
}

/**
* Gets the Decision from the Bayonet API of an order
*
* @return string
*/
public function getDecision()
{
return $this->directQuery->customQuery(
'bayonet_antifraud_orders',
'decision',
['order_id' => $this->getOrderId()]
);
}

/**
* Gets the Bayonet API triggered rules (if exist) of an order
*
* @return string
*/
public function getRules()
{
return $this->directQuery->customQuery(
'bayonet_antifraud_orders',
'triggered_rules',
['order_id' => $this->getOrderId()]
);
}

/**
* {@inheritdoc}
*/
public function getTabTitle()
{
return __('Bayonet Anti-Fraud');
}

/**
* {@inheritdoc}
*/
public function canShowTab()
{
return true;
}

/**
* {@inheritdoc}
*/
public function isHidden()
{
return false;
}
}
99 changes: 99 additions & 0 deletions Block/Fingerprint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace Bayonet\BayonetAntiFraud\Block;

use \Magento\Framework\View\Element\Template\Context;
use \Magento\Framework\View\Element\Template;
use \Bayonet\BayonetAntiFraud\Helper\DirectQuery;

/**
* Block class used to get data in the Fingerprint template
*/
class Fingerprint extends Template
{
protected $_isScopePrivate = false;
protected $directQuery;
protected $httpContext;

public function __construct(
Context $context,
\Magento\Framework\App\Http\Context $httpContext,
DirectQuery $directQuery,
array $data = []
) {
parent::__construct($context, $data);
$this->directQuery = $directQuery;
$this->httpContext = $httpContext;
}

/**
* Gets the controller URL
*
* @return string
*/
public function getAjaxUrl()
{
return $this->getUrl('device/fingerprint/index');
}

/**
* Gets the current value of the 'enable' configuration field
*
* @return int
*/
public function getEnabled()
{
return (int)$this->directQuery->customQuery(
'core_config_data',
'value',
['path' => 'bayonetantifraud_general/general/enable']
);
}

/**
* Gets the API key in order to generate the fingerprint token
* It checks whether the the API mode is in live or sandbox in order
* to return the corresponding key
*
* @return string
*/
public function getApiKey()
{
$apiMode = (int)$this->directQuery->customQuery(
'core_config_data',
'value',
['path' => 'bayonetantifraud_general/general/api_mode']
);
$apiKey = $apiMode === 1 ? $this->directQuery->customQuery(
'core_config_data',
'value',
['path' => 'bayonetantifraud_general/general/js_live_key']
) : $this->directQuery->customQuery(
'core_config_data',
'value',
['path' => 'bayonetantifraud_general/general/js_sandbox_key']
);

return $apiKey;
}

/**
* Gets a bool that indicates whether a customer is logged in or not
*
* @return bool
*/
public function getCustomerIsLoggedIn()
{
return (bool)$this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
}

/**
* Gets the ID of the logged in customer
*
* @return string
*/
public function getCustomerId()
{
return $this->httpContext->getValue('customer_id');
}
}
Loading

0 comments on commit f23640a

Please sign in to comment.