Skip to end of metadata
Go to start of metadata

General information

This page describes and provides example - methods for the simple-protect - framework, wich will be a part of the magento 2 - plugin.

Be aware that you have to be compliant as described in the specifications of the GDPR

Get information from the database

First of all you have to initialize a database object:

/**
 * Database connection resource
 *
 * @var \Magento\Framework\App\ResourceConnection
 */
protected $databaseResource;

__construct it

/**
 * Constructor
 *
 * @param \Magento\Framework\App\ResourceConnection $resource
 */
public function __construct(
    \Magento\Framework\App\ResourceConnection $resource
)
{

    $this->databaseResource = $resource;
}

and then you can ask the database for information like these

/**
 * Get count of customers orders
 *
 * @param CustomerInterface $oCustomer
 * @return int
 */
protected function getCustomersOrderCount(CustomerInterface $oCustomer)
{
    $db = $this->databaseResource->getConnection();
    $oSelect = $db->select()
        ->from($this->databaseResource->getTableName('sales_order'), ['COUNT(entity_id)'])
        ->where("customer_id = :customerId");
    $iCount = $db->fetchOne($oSelect, ['customerId' => $oCustomer->getId()]);
    if ($iCount === null) {
        return 0;
    }
    return $iCount;
}


Execute PAYONE protect checks

to be able for executing the protect check you have to init and construct the PAYONE protectFunnel

/**
 * PAYONE Protect model providing access to consumerscore and addresscheck requests
 *
 * @var \Payone\Core\Model\SimpleProtect\ProtectFunnel
 */
protected $protectFunnel;


public function __construct(
    \Payone\Core\Model\SimpleProtect\ProtectFunnel $protectFunnel
)
{
    $this->protectFunnel = $protectFunnel;
}


/**
 * Example for addresscheck usage
 *
 * @param  Quote $oQuote
 * @return AddresscheckResponse|bool
 */
protected function executeAddresscheck(Quote $oQuote)
{
    $oAddress = $oQuote->getBillingAddress();
    $sAddresscheckType = AddressCheckType::BASIC;

    return $this->protectFunnel->executeAddresscheck($oAddress, $this->getOperationMode(), $sAddresscheckType);
}

addresscheck

here is a simple method to execute the addresscheck  with the billing address

if you want to perform the addresscheck on the shipping address you have to change the $oAddress - Variable this way

/**
 * getting the shipping address
 */
$oAddress = $oQuote->getShippingAddress();

maybe you want to use another way / type for the addresscheck there are many more options

/**
 * Examples of all the types for addresscheck usage
 */
$sAddresscheckType = AddressCheckType::NONE;
$sAddresscheckType = AddressCheckType::BASIC;
$sAddresscheckType = AddressCheckType::PERSON;
$sAddresscheckType = AddressCheckType::BONIVERSUM_BASIC;
$sAddresscheckType = AddressCheckType::BONIVERSUM_BASIC;


consumerscore

here is a simple method to perform the consumerscore - request

as in the addresscheck described you can also switch the address which you want to check

/**
 * getting the shipping address
 */
$oAddress = $oQuote->getShippingAddress();

all options for the consumerscore are described here

/**
 * Examples of all the options for consumerscore usage
 */    
$sConsumerscoreType = CreditratingCheckType::INFOSCORE_HARD;
$sConsumerscoreType = CreditratingCheckType::INFOSCORE_ALL;
$sConsumerscoreType = CreditratingCheckType::INFOSCORE_ALL_BONI;
$sConsumerscoreType = CreditratingCheckType::BONIVERSUM_VERITA;


/**
 * Example for consumerscore usage
 *
 * @param  Quote $oQuote
 * @return ConsumerscoreResponse|bool
 */
protected function executeConsumerscore(Quote $oQuote)
{
    $oAddress = $oQuote->getBillingAddress();
    $sConsumerscoreType = CreditratingCheckType::INFOSCORE_ALL;

    return $this->protectFunnel->executeConsumerscore($oAddress, $this->getOperationMode(), $sConsumerscoreType, $sAddresscheckType);
}

you can use the result from above like this

/**
 * Check the result of executing the consumerscore
 * @return bool
 */
$oResponse = $this->executeConsumerscore($oQuote);
if ($oResponse instanceof ConsumerscoreResponse && ($oResponse->getStatus() != 'VALID' || $oResponse->getScore() != 'G')) {
    return true;
}

In the above example the call $oResponse->getScore() will give you the value score as described here

Filter on the store view

if you need to have other decisions regarding a store view, you can ask for it with the existing magento objects like

/**
 * Change AddressCheckType for the stores
 * @default AddressCheckType::NONE
 */
$sAddresscheckType = AddressCheckType::NONE;
if ($oQuote->getStore()->getName() == 'new Brands') {
    $sAddresscheckType = AddressCheckType::PERSON;
} else if ($oQuote->getStore()->getCode() == 'old_Brands') {
    $sAddresscheckType = AddressCheckType::BASIC;
}

  • No labels