From 839f1d956b29739906f344bec5d2434dc78cab8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89bano=20Penha=20Andrello=20Lopes?= Date: Mon, 29 Jul 2019 08:28:33 -0300 Subject: [PATCH 1/2] 3.4.2: MAG-460: Rebuilt device fingerprint To prevent problems with all kinds of FPC --- CustomerData/Fingerprint.php | 78 +++++++++++++++++++ etc/frontend/di.xml | 10 +++ etc/frontend/sections.xml | 39 ++++++++++ view/frontend/layout/default.xml | 17 +++- view/frontend/templates/fingerprint.phtml | 5 ++ .../web/js/view/signifyd-fingerprint.js | 63 +++++++++++++++ 6 files changed, 209 insertions(+), 3 deletions(-) create mode 100644 CustomerData/Fingerprint.php create mode 100644 etc/frontend/sections.xml create mode 100644 view/frontend/templates/fingerprint.phtml create mode 100644 view/frontend/web/js/view/signifyd-fingerprint.js diff --git a/CustomerData/Fingerprint.php b/CustomerData/Fingerprint.php new file mode 100644 index 00000000..6fc9ed37 --- /dev/null +++ b/CustomerData/Fingerprint.php @@ -0,0 +1,78 @@ +quoteId = $session->getQuoteId(); + $this->deviceHelper = $deviceHelper; + } + + /** + * @return string + */ + public function getDeviceFingerprint() + { + return $this->deviceHelper->generateFingerprint($this->getQuoteId()); + } + + /** + * @return bool + */ + public function getQuoteId() + { + return empty($this->quoteId) ? false : $this->quoteId; + } + + /** + * @return bool + */ + public function isEnabled() + { + if ($this->deviceHelper->isDeviceFingerprintEnabled()) { + return $this->getQuoteId(); + } else { + return false; + } + } + + /** + * @return array + */ + public function getSectionData() + { + $data = ['dataOrderSessionId' => '']; + + if ($this->isEnabled()) { + $data['dataOrderSessionId'] = $this->getDeviceFingerprint(); + } + + return $data; + } +} \ No newline at end of file diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml index 6c4d3b61..99fb452a 100644 --- a/etc/frontend/di.xml +++ b/etc/frontend/di.xml @@ -1,5 +1,6 @@ + @@ -11,4 +12,13 @@ + + + + + + Signifyd\Connect\CustomerData\Fingerprint + + + diff --git a/etc/frontend/sections.xml b/etc/frontend/sections.xml new file mode 100644 index 00000000..527bcfd9 --- /dev/null +++ b/etc/frontend/sections.xml @@ -0,0 +1,39 @@ + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + \ No newline at end of file diff --git a/view/frontend/layout/default.xml b/view/frontend/layout/default.xml index 8bb3dd09..d6ac2f30 100644 --- a/view/frontend/layout/default.xml +++ b/view/frontend/layout/default.xml @@ -1,8 +1,19 @@ - - - + + + + + + + Signifyd_Connect/js/view/signifyd-fingerprint + + + + + + \ No newline at end of file diff --git a/view/frontend/templates/fingerprint.phtml b/view/frontend/templates/fingerprint.phtml new file mode 100644 index 00000000..18f4de91 --- /dev/null +++ b/view/frontend/templates/fingerprint.phtml @@ -0,0 +1,5 @@ +
+ + diff --git a/view/frontend/web/js/view/signifyd-fingerprint.js b/view/frontend/web/js/view/signifyd-fingerprint.js new file mode 100644 index 00000000..06a1ffc8 --- /dev/null +++ b/view/frontend/web/js/view/signifyd-fingerprint.js @@ -0,0 +1,63 @@ +define([ + 'uiComponent', + 'Magento_Customer/js/customer-data', + 'jquery' +], function (Component, customerData, $) { + 'use strict'; + + return Component.extend({ + /** @inheritdoc */ + initialize: function () { + var me = this; + me._super(); + + if (jQuery('.checkout-onepage-success').length > 0) { + customerData.reload('signifyd-fingerprint'); + + } else { + me.data = customerData.get('signifyd-fingerprint'); + me.sent = false; + + me.sent = me.checkSessionId(me.data().dataOrderSessionId); + + if (me.sent === false) { + me.observing = me.data.subscribe(function (newData) { + me.sent = me.checkSessionId(newData.dataOrderSessionId); + }); + } + } + }, + + checkSessionId: function(dataOrderSessionId) { + var me = this; + + if (typeof dataOrderSessionId !== 'undefined' && dataOrderSessionId.length > 0) { + console.log('Sending fingerprint...'); + + me.callScript(dataOrderSessionId); + + if (typeof me.observing != "undefined") { + me.observing.dispose(); + } + + return true; + } else { + console.log('Will not send fingerprint'); + console.log(dataOrderSessionId); + + return false; + } + }, + + callScript: function(dataOrderSessionId) { + var script = document.createElement('script'); + script.setAttribute('async', true); + script.setAttribute('type', 'text/javascript'); + script.setAttribute('id', 'sig-api'); + script.setAttribute('data-order-session-id', dataOrderSessionId); + script.setAttribute('src', 'https://cdn-scripts.signifyd.com/api/script-tag.js'); + + $("body").append(script); + } + }); +}); \ No newline at end of file From fe5fee149aa05697a5c9473aed5827aa2de9e74d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89bano=20Penha=20Andrello=20Lopes?= Date: Mon, 29 Jul 2019 15:10:31 -0300 Subject: [PATCH 2/2] 3.4.2: Change version number --- composer.json | 2 +- etc/module.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 3cfd128c..e81915e3 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "php": ">=5.5.22" }, "type": "magento2-module", - "version": "3.4.0", + "version": "3.4.2", "autoload": { "files": [ "registration.php" diff --git a/etc/module.xml b/etc/module.xml index db6b6039..05b734ce 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -5,7 +5,7 @@ */ --> - +