Skip to content

Commit

Permalink
Added new Javascript agent.
Browse files Browse the repository at this point in the history
  • Loading branch information
fraudlabspro committed Sep 5, 2022
1 parent ba016f4 commit 259cd68
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 74 deletions.
123 changes: 62 additions & 61 deletions fraudlabspro.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* 2012-2020 FraudLabs Pro.
* 2012-2022 FraudLabs Pro.
*
* NOTICE OF LICENSE
*
Expand Down Expand Up @@ -35,7 +35,7 @@ public function __construct()
{
$this->name = 'fraudlabspro';
$this->tab = 'payment_security';
$this->version = '1.14.1';
$this->version = '1.15.0';
$this->author = 'FraudLabs Pro';
$this->controllers = ['payment', 'validation'];
$this->module_key = 'cdb22a61c7ec8d1f900f6c162ad96caa';
Expand Down Expand Up @@ -176,37 +176,38 @@ public function hookNewOrder($params)

$bill_state = '';

if ($address_invoice->id_state !== null or $address_invoice->id_state != '') {
if ($address_invoice->id_state !== null || $address_invoice->id_state != '') {
$State = new State((int) $address_invoice->id_state);
$bill_state = $State->iso_code;
}

$response = Tools::file_get_contents('https://api.fraudlabspro.com/v1/order/screen?' . http_build_query([
'key' => Configuration::get('FLP_LICENSE_KEY'),
'ip' => $ip,
'first_name' => $address_invoice->firstname,
'last_name' => $address_invoice->lastname,
'bill_city' => $address_invoice->city,
'bill_state' => $bill_state,
'bill_country' => Country::getIsoById((int) $address_invoice->id_country),
'bill_zip_code' => $address_invoice->postcode,
'email_domain' => Tools::substr($customer->email, strpos($customer->email, '@') + 1),
'email_hash' => $this->hastIt($customer->email),
'email' => $customer->email,
'user_phone' => $address_invoice->phone,
'ship_addr' => trim($address_delivery->address1 . ' ' . $address_delivery->address2),
'ship_city' => $address_delivery->city,
'ship_state' => (Tools::getIsset($delivery_state->iso_code)) ? $delivery_state->iso_code : '',
'ship_zip_code' => $address_delivery->postcode,
'ship_country' => Country::getIsoById((int) $address_delivery->id_country),
'amount' => $params['order']->total_paid,
'quantity' => $quantity,
'currency' => $default_currency->iso_code,
'user_order_id' => $params['order']->id,
'flp_checksum' => Context::getContext()->cookie->flp_checksum,
'format' => 'json',
'source' => 'prestashop',
'source_version' => $this->version,
'key' => Configuration::get('FLP_LICENSE_KEY'),
'ip' => $ip,
'first_name' => $address_invoice->firstname,
'last_name' => $address_invoice->lastname,
'bill_city' => $address_invoice->city,
'bill_state' => $bill_state,
'bill_country' => Country::getIsoById((int) $address_invoice->id_country),
'bill_zip_code' => $address_invoice->postcode,
'email_domain' => Tools::substr($customer->email, strpos($customer->email, '@') + 1),
'email_hash' => $this->hastIt($customer->email),
'email' => $customer->email,
'user_phone' => $address_invoice->phone,
'ship_addr' => trim($address_delivery->address1 . ' ' . $address_delivery->address2),
'ship_city' => $address_delivery->city,
'ship_state' => (Tools::getIsset($delivery_state->iso_code)) ? $delivery_state->iso_code : '',
'ship_zip_code' => $address_delivery->postcode,
'ship_country' => Country::getIsoById((int) $address_delivery->id_country),
'amount' => $params['order']->total_paid,
'quantity' => $quantity,
'currency' => $default_currency->iso_code,
'user_order_id' => $params['order']->id,
'device_fingerprint' => (isset($_COOKIE['flp.device'])) ? $_COOKIE['flp.device'] : '',
'flp_checksum' => Context::getContext()->cookie->flp_checksum,
'format' => 'json',
'source' => 'prestashop',
'source_version' => $this->version,
]), false, stream_context_create([
'http' => ['timeout' => 10],
]));
Expand Down Expand Up @@ -377,40 +378,40 @@ public function renderForm()
'required' => true,
],
[
'type' => 'select',
'label' => $this->l('Approve Status'),
'name' => 'FLP_APPROVE_STATUS_ID',
'required' => false,
'options' => [
'query' => array_merge(['id_order_state' => 0], OrderState::getOrderStates((int) $this->context->language->id)),
'id' => 'id_order_state',
'name' => 'name',
],
'desc' => $this->l('Change order to this state if marked as Approve by FraudLabs Pro.'),
'type' => 'select',
'label' => $this->l('Approve Status'),
'name' => 'FLP_APPROVE_STATUS_ID',
'required' => false,
'options' => [
'query' => array_merge(['id_order_state' => 0], OrderState::getOrderStates((int) $this->context->language->id)),
'id' => 'id_order_state',
'name' => 'name',
],
'desc' => $this->l('Change order to this state if marked as Approve by FraudLabs Pro.'),
],
[
'type' => 'select',
'label' => $this->l('Review Status'),
'name' => 'FLP_REVIEW_STATUS_ID',
'required' => false,
'options' => [
'query' => array_merge(['id_order_state' => 0], OrderState::getOrderStates((int) $this->context->language->id)),
'id' => 'id_order_state',
'name' => 'name',
],
'desc' => $this->l('Change order to this state if marked as Review by FraudLabs Pro.'),
'type' => 'select',
'label' => $this->l('Review Status'),
'name' => 'FLP_REVIEW_STATUS_ID',
'required' => false,
'options' => [
'query' => array_merge(['id_order_state' => 0], OrderState::getOrderStates((int) $this->context->language->id)),
'id' => 'id_order_state',
'name' => 'name',
],
'desc' => $this->l('Change order to this state if marked as Review by FraudLabs Pro.'),
],
[
'type' => 'select',
'label' => $this->l('Reject Status'),
'name' => 'FLP_REJECT_STATUS_ID',
'required' => false,
'options' => [
'query' => array_merge(['id_order_state' => 0], OrderState::getOrderStates((int) $this->context->language->id)),
'id' => 'id_order_state',
'name' => 'name',
],
'desc' => $this->l('Change order to this state if marked as Reject by FraudLabs Pro.'),
'type' => 'select',
'label' => $this->l('Reject Status'),
'name' => 'FLP_REJECT_STATUS_ID',
'required' => false,
'options' => [
'query' => array_merge(['id_order_state' => 0], OrderState::getOrderStates((int) $this->context->language->id)),
'id' => 'id_order_state',
'name' => 'name',
],
'desc' => $this->l('Change order to this state if marked as Reject by FraudLabs Pro.'),
],
[
'type' => 'checkbox',
Expand Down Expand Up @@ -455,7 +456,7 @@ public function renderForm()
$helper->table = $this->table;
$lang = new Language((int) Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ?: 0;
$this->fields_form = [];
$helper->id = (int) Tools::getValue('id_carrier');
$helper->identifier = $this->identifier;
Expand Down Expand Up @@ -533,7 +534,7 @@ private function getIP()
if (isset($_SERVER['DEV_MODE'])) {
do {
$ip = mt_rand(0, 255) . '.' . mt_rand(0, 255) . '.' . mt_rand(0, 255) . '.' . mt_rand(0, 255);
} while (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE));
} while (!filter_var($ip, \FILTER_VALIDATE_IP, \FILTER_FLAG_NO_PRIV_RANGE | \FILTER_FLAG_NO_RES_RANGE));

return $ip;
}
Expand All @@ -548,7 +549,7 @@ private function getIP()
continue;
}

if (!filter_var($_SERVER[$header], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
if (!filter_var($_SERVER[$header], \FILTER_VALIDATE_IP, \FILTER_FLAG_NO_PRIV_RANGE | \FILTER_FLAG_NO_RES_RANGE)) {
continue;
}

Expand Down
20 changes: 7 additions & 13 deletions views/templates/hook/footer.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,15 @@
* needs please refer to http://www.prestashop.com for more information.
*
* @author FraudLabs Pro <support@fraudlabspro.com>
* @copyright 2012-2017 FraudLabs Pro
* @copyright 2012-2022 FraudLabs Pro
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of FraudLabs Pro
*}

<script type="text/javascript">
(function(){
function s() {
var e = document.createElement('script');
e.type = 'text/javascript';
e.async = true;
e.src = ('https:' === document.location.protocol ? 'https://' : 'http://') + 'cdn.fraudlabspro.com/s.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(e, s);
}
(window.attachEvent) ? window.attachEvent('onload', s) : window.addEventListener('load', s, false);
})();
<script src="https://cdn.fraudlabspro.com/v3-agent.min.js"></script>
<script>
var agent = new FraudLabsProAgent3();
window.onload = function() {
agent.resolve(function(){});
};
</script>

0 comments on commit 259cd68

Please sign in to comment.