Fingerprint.php 2.26 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Signifyd\Block;

use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Signifyd\Model\Config;
use Magento\Signifyd\Model\QuoteSession\QuoteSessionInterface;
use Magento\Signifyd\Model\SignifydOrderSessionId;

/**
 * Provides data for Signifyd device fingerprinting script.
 *
 * Signifyd’s device fingerprinting solution uniquely tracks and identifies devices
 * used to transact on your site, increasing your protection from fraud.
 *
 * @api
 * @see https://www.signifyd.com/docs/api/#/reference/device-fingerprint/create-a-case
 * @since 100.2.0
 */
class Fingerprint extends Template
{
    /**
     * @var SignifydOrderSessionId
     */
    private $signifydOrderSessionId;

    /**
     * @var Config
     */
    private $config;

    /**
     * @var QuoteSessionInterface
     */
    private $quoteSession;

    /**
     * @var string
     * @since 100.2.0
     */
    protected $_template = 'Magento_Signifyd::fingerprint.phtml';

    /**
     * @param Context $context
     * @param Config $config
     * @param SignifydOrderSessionId $signifydOrderSessionId
     * @param QuoteSessionInterface $quoteSession
     * @param array $data
     */
    public function __construct(
        Context $context,
        Config $config,
        SignifydOrderSessionId $signifydOrderSessionId,
        QuoteSessionInterface $quoteSession,
        array $data = []
    ) {
        parent::__construct($context, $data);
        $this->signifydOrderSessionId = $signifydOrderSessionId;
        $this->config = $config;
        $this->quoteSession = $quoteSession;
    }

    /**
     * Returns a unique Signifyd order session id.
     *
     * @return string
     * @since 100.2.0
     */
    public function getSignifydOrderSessionId()
    {
        $quoteId = $this->quoteSession->getQuote()->getId();

        return $this->signifydOrderSessionId->get($quoteId);
    }

    /**
     * Checks if module is enabled.
     *
     * @return boolean
     * @since 100.2.0
     */
    public function isModuleActive()
    {
        $storeId = $this->quoteSession->getQuote()->getStoreId();

        return $this->config->isActive($storeId);
    }
}