Skip to content

Commit

Permalink
Added Enable Debug Log feature
Browse files Browse the repository at this point in the history
  • Loading branch information
fraudlabspro committed Dec 13, 2024
1 parent 8bb81d1 commit e8c26d4
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Block/Adminhtml/Order/View/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function toHtml(){
return '
<div class="entry-edit">
<div class="entry-edit-head" style="background:#cc0000;">
<h4 class="icon-head head-shipping-method"><a href="http://www.fraudlabspro.com" target="_blank"><img src="http://www.fraudlabspro.com/images/logo-small.png" width="163" height="20" border="0" align="absMiddle" /></a></h4>
<h4 class="icon-head head-shipping-method"><a href="https://www.fraudlabspro.com" target="_blank"><img src="https://www.fraudlabspro.com/images/logo-small.png" width="163" height="20" border="0" align="absMiddle" /></a></h4>
</div>
<fieldset>
Expand Down Expand Up @@ -239,7 +239,7 @@ public function toHtml(){
$out .= '
<div class="entry-edit">
<div class="entry-edit-head" style="background:#cc0000; padding:5px;">
<h4 class="icon-head head-shipping-method"><a href="http://www.fraudlabspro.com" target="_blank"><img src="http://www.fraudlabspro.com/images/logo-small.png" width="163" height="20" border="0" align="absMiddle" /></a></h4>
<h4 class="icon-head head-shipping-method"><a href="https://www.fraudlabspro.com" target="_blank"><img src="https://www.fraudlabspro.com/images/logo-small.png" width="163" height="20" border="0" align="absMiddle" /></a></h4>
</div>
<fieldset>
Expand All @@ -255,7 +255,7 @@ public function toHtml(){
</tr>
<tr>
<td style="padding:5px;"><span><strong>IP Location</strong> <a href="javascript:;" title="Location of the IP address.">[?]</a></span></td>
<td colspan="3" style="padding:5px;"><span>' . implode(', ', $location) . ' <a href="http://www.geolocation.com/' . $data['ip_address'] . '" target="_blank">[Map]</a></span></td>
<td colspan="3" style="padding:5px;"><span>' . implode(', ', $location) . ' <a href="https://www.geolocation.com/' . $data['ip_address'] . '" target="_blank">[Map]</a></span></td>
<td style="padding:5px;"><span><strong>IP to Billing Distance</strong> <a href="javascript:;" title="Distance from IP address to Billing Location.">[?]</a></span></td>
<td style="padding:5px;"><span>' . ( ( $distanceKm ) ? ( $distanceKm . ' KM / ' . $distanceMile . ' Miles' ) : '-' ) . ' </span></td>
</tr>
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Revision History for FraudLabs Pro Magento2

2.7.0 2024-12-04
Added Enable Debug Log feature.

2.6.1 2024-11-19
Fixed undefined array key warning.

Expand Down
44 changes: 35 additions & 9 deletions Controller/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ public function processSendRequestToFraudLabsPro($order) {

$orderId = $order->getIncrementId();

if (empty($orderId))
if (empty($orderId)) {
$this->_writelog('Order ' . $orderId . ' is empty. Skip for FraudLabs Pro validation.');
return true;
}

$data = 0;

Expand All @@ -81,9 +83,12 @@ public function processSendRequestToFraudLabsPro($order) {
$data = json_decode($order->getfraudlabspro_response(), true);
}

if ($data)
if ($data) {
$this->_writelog('Order ' . $orderId . ' has been validated. Skip for FraudLabs Pro validation.');
return true;
}

$this->_writelog('FraudLabs Pro validation has started for Order ' . $orderId . '.');
$apiKey = $this->scopeConfig->getValue('fraudlabspro/active_display/api_key', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$approveStatus = $this->scopeConfig->getValue('fraudlabspro/active_display/approve_status', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$reviewStatus = $this->scopeConfig->getValue('fraudlabspro/active_display/review_status', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
Expand Down Expand Up @@ -196,7 +201,7 @@ public function processSendRequestToFraudLabsPro($order) {
'device_fingerprint' => (isset($_COOKIE['flp_device'])) ? $_COOKIE['flp_device'] : '',
'flp_checksum' => (isset($_COOKIE['flp_checksum'])) ? $_COOKIE['flp_checksum'] : '',
'source' => 'magento',
'source_version' => '2.6.1',
'source_version' => '2.7.0',
'items' => $item_sku,
'coupon_code' => $order->getCouponCode() ? $order->getCouponCode() : '',
'coupon_amount' => $order->getCouponCode() ? -($order->getDiscountAmount()) : '',
Expand Down Expand Up @@ -228,6 +233,9 @@ public function processSendRequestToFraudLabsPro($order) {
$result['is_phone_verified'] = 'No';

$order->setfraudlabspro_response(json_encode($result))->save();
$this->_writelog('FraudLabs Pro validation has been completed for Order ' . $orderId . '. Status: ' . $result['fraudlabspro_status'] . ', Transaction ID: ' . $result['fraudlabspro_id']);
$this->_writelog('The order state for Order ' . $orderId . ': ' . $order->getState());
$this->_writelog('The order status for Order ' . $orderId . ': ' . $order->getStatus());

if ($result['fraudlabspro_status'] == 'APPROVE') {
switch ($approveStatus) {
Expand Down Expand Up @@ -269,6 +277,8 @@ public function processSendRequestToFraudLabsPro($order) {
$order->setStatus(\Magento\Sales\Model\Order::STATE_HOLDED, true)->save();
break;
}
$this->_writelog('The updated order state for APPROVE Order ' . $orderId . ': ' . $order->getState());
$this->_writelog('The updated order status for APPROVE Order ' . $orderId . ': ' . $order->getStatus());
}

if ($result['fraudlabspro_status'] == 'REVIEW') {
Expand Down Expand Up @@ -311,6 +321,8 @@ public function processSendRequestToFraudLabsPro($order) {
$order->setStatus(\Magento\Sales\Model\Order::STATE_HOLDED, true)->save();
break;
}
$this->_writelog('The updated order state for REVIEW Order ' . $orderId . ': ' . $order->getState());
$this->_writelog('The updated order status for REVIEW Order ' . $orderId . ': ' . $order->getStatus());
}

if ($result['fraudlabspro_status'] == 'REJECT') {
Expand Down Expand Up @@ -341,6 +353,8 @@ public function processSendRequestToFraudLabsPro($order) {
break;

case 'canceled':
$order->setState(\Magento\Sales\Model\Order::STATE_NEW, true)->save();
$order->setStatus('pending', true)->save();
if ($order->canCancel()) {
$order->cancel()->save();
}
Expand All @@ -353,6 +367,8 @@ public function processSendRequestToFraudLabsPro($order) {
$order->setStatus(\Magento\Sales\Model\Order::STATE_HOLDED, true)->save();
break;
}
$this->_writelog('The updated order state for REJECT Order ' . $orderId . ': ' . $order->getState());
$this->_writelog('The updated order status for REJECT Order ' . $orderId . ': ' . $order->getStatus());
}

if (((strpos($notificationOn, 'approve') !== FALSE) && $result['fraudlabspro_status'] == 'APPROVE') || ((strpos($notificationOn, 'review') !== FALSE) && $result['fraudlabspro_status'] == 'REVIEW') || ((strpos($notificationOn, 'reject') !== FALSE) && $result['fraudlabspro_status'] == 'REJECT')) {
Expand All @@ -369,12 +385,12 @@ public function processSendRequestToFraudLabsPro($order) {

if (!empty($target_url)) {
$this->_zaphttp($target_url, [
'id' => $result['fraudlabspro_id'],
'date_created' => gmdate('Y-m-d H:i:s'),
'flp_status' => $result['fraudlabspro_status'],
'full_name' => $order->getCustomerFirstname() . ' ' . $order->getCustomerLastname(),
'email' => $order->getCustomerEmail(),
'order_id' => $orderId,
'id' => $result['fraudlabspro_id'],
'date_created' => gmdate('Y-m-d H:i:s'),
'flp_status' => $result['fraudlabspro_status'],
'full_name' => $order->getCustomerFirstname() . ' ' . $order->getCustomerLastname(),
'email' => $order->getCustomerEmail(),
'order_id' => $orderId,
]);
}
}
Expand Down Expand Up @@ -481,4 +497,14 @@ private function _unserialize($data){
}
}

private function _writelog($message) {
if (!$this->scopeConfig->getValue('fraudlabspro/active_display/enable_debug_log', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
return;
}
$writer = new \Zend_Log_Writer_Stream(BP . '/var/log/FLP-custom.log');
$logger = new \Zend_Log();
$logger->addWriter($writer);
$logger->info($message);
}

}
4 changes: 2 additions & 2 deletions Ui/Component/Listing/Column/Assessment.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public function prepareDataSource(array $dataSource) {
if(is_null(json_decode($item[$this->getData('name')], true))){
if($item[$this->getData('name')]){
$data = $this->_unserialize($item[$this->getData('name')]);
$item[$this->getData('name')] = $data['fraudlabspro_status'];
$item[$this->getData('name')] = ($data['fraudlabspro_status'] ?? "");
}
} else {
$data = json_decode($item[$this->getData('name')], true);
$item[$this->getData('name')] = $data['fraudlabspro_status'];
$item[$this->getData('name')] = ($data['fraudlabspro_status'] ?? "");
}
} else {
$item[$this->getData('name')] = "";
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hexasoft/module-fraudlabspro",
"description": "FraudLabs Pro Fraud Prevention plugin that screen the order transaction for online frauds. Fraud Prevention extension for Magento 2.",
"version": "2.6.1",
"version": "2.7.0",
"type": "magento2-module",
"require": {
"php": ">=5.5"
Expand Down
5 changes: 5 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
<label>Sync Complete/Canceled Status</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="enable_debug_log" translate="label" type="select" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable Debug Log</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment><![CDATA[Activate debug logging and save the log file in the magento/var/log/ directory.]]></comment>
</field>
</group>
</section>
</system>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Hexasoft_FraudLabsPro" setup_version="2.6.1">
<module name="Hexasoft_FraudLabsPro" setup_version="2.7.0">
<sequence>
<module name="Magento_Sales"/>
</sequence>
Expand Down

0 comments on commit e8c26d4

Please sign in to comment.