diff --git a/Block/Adminhtml/Config/Form/Field/KlarnaStoreId.php b/Block/Adminhtml/Config/Form/Field/KlarnaStoreId.php
index e3ed13e5..87df7f82 100644
--- a/Block/Adminhtml/Config/Form/Field/KlarnaStoreId.php
+++ b/Block/Adminhtml/Config/Form/Field/KlarnaStoreId.php
@@ -48,11 +48,10 @@ class KlarnaStoreId extends \Payone\Core\Block\Adminhtml\Config\Form\Field\Field
/**
* Constructor
*
- * @param \Magento\Backend\Block\Template\Context $context
- * @param \Magento\Framework\Data\Form\Element\Factory $elementFactory
- * @param \Payone\Core\Model\Source\TransactionStatus $klarnaCountries
- * @param array $data
- * @return void
+ * @param \Magento\Backend\Block\Template\Context $context
+ * @param \Magento\Framework\Data\Form\Element\Factory $elementFactory
+ * @param \Payone\Core\Model\Source\TransactionStatus $klarnaCountries
+ * @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
diff --git a/Block/Adminhtml/Config/Form/Field/PersonStatusMapping.php b/Block/Adminhtml/Config/Form/Field/PersonStatusMapping.php
new file mode 100644
index 00000000..e6165ac5
--- /dev/null
+++ b/Block/Adminhtml/Config/Form/Field/PersonStatusMapping.php
@@ -0,0 +1,114 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Block\Adminhtml\Config\Form\Field;
+
+/**
+ * Block class for person-status-mapping grid-element
+ */
+class PersonStatusMapping extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
+{
+ /**
+ * Element factory
+ *
+ * @var \Magento\Framework\Data\Form\Element\Factory
+ */
+ protected $elementFactory;
+
+ /**
+ * Person status source class
+ *
+ * @var \Payone\Core\Model\Source\PersonStatus
+ */
+ protected $personStatus;
+
+ /**
+ * Credit score source class
+ *
+ * @var \Payone\Core\Model\Source\CreditScore
+ */
+ protected $creditScore;
+
+ /**
+ * Constructor
+ *
+ * @param \Magento\Backend\Block\Template\Context $context
+ * @param \Magento\Framework\Data\Form\Element\Factory $elementFactory
+ * @param \Payone\Core\Model\Source\PersonStatus $personStatus
+ * @param \Payone\Core\Model\Source\CreditScore $creditScore
+ * @param array $data
+ */
+ public function __construct(
+ \Magento\Backend\Block\Template\Context $context,
+ \Magento\Framework\Data\Form\Element\Factory $elementFactory,
+ \Payone\Core\Model\Source\PersonStatus $personStatus,
+ \Payone\Core\Model\Source\CreditScore $creditScore,
+ array $data = []
+ ) {
+ parent::__construct($context, $data);
+ $this->elementFactory = $elementFactory;
+ $this->personStatus = $personStatus;
+ $this->creditScore = $creditScore;
+ }
+
+ /**
+ * Initialise form fields
+ *
+ * @return void
+ */
+ protected function _construct()
+ {
+ $this->addColumn('personstatus', ['label' => __('Personstatus')]);
+ $this->addColumn('score', ['label' => __('Score')]);
+ $this->addAfter = false;
+ $this->addButtonLabel = __('Add Personstatus Mapping');
+ parent::_construct();
+ }
+
+ /**
+ * Render array cell for prototypeJS template
+ *
+ * @param string $columnName
+ * @return string
+ */
+ public function renderCellTemplate($columnName)
+ {
+ if ($columnName == 'personstatus' && isset($this->_columns[$columnName])) {
+ $aOptions = $this->personStatus->toOptionArray();
+ } elseif ($columnName == 'score' && isset($this->_columns[$columnName])) {
+ $aOptions = $this->creditScore->toOptionArray();
+ } else {
+ return parent::renderCellTemplate($columnName);
+ }
+
+ $oElement = $this->elementFactory->create('select');
+ $oElement->setForm($this->getForm());
+ $oElement->setName($this->_getCellInputElementName($columnName));
+ $oElement->setHtmlId($this->_getCellInputElementId('<%- _id %>', $columnName));
+ $oElement->setValues($aOptions);
+ return str_replace("\n", '', $oElement->getElementHtml());
+ }
+}
diff --git a/Block/Adminhtml/Config/Form/Field/StatusForwarding.php b/Block/Adminhtml/Config/Form/Field/StatusForwarding.php
index 70f8516a..6f123b1a 100644
--- a/Block/Adminhtml/Config/Form/Field/StatusForwarding.php
+++ b/Block/Adminhtml/Config/Form/Field/StatusForwarding.php
@@ -48,11 +48,10 @@ class StatusForwarding extends \Payone\Core\Block\Adminhtml\Config\Form\Field\Fi
/**
* Constructor
*
- * @param \Magento\Backend\Block\Template\Context $context
- * @param \Magento\Framework\Data\Form\Element\Factory $elementFactory
- * @param \Payone\Core\Model\Source\TransactionStatus $transactionStatus
- * @param array $data
- * @return void
+ * @param \Magento\Backend\Block\Template\Context $context
+ * @param \Magento\Framework\Data\Form\Element\Factory $elementFactory
+ * @param \Payone\Core\Model\Source\TransactionStatus $transactionStatus
+ * @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
diff --git a/Block/Adminhtml/Config/Form/Field/StatusMapping.php b/Block/Adminhtml/Config/Form/Field/StatusMapping.php
index 52598879..1256701e 100644
--- a/Block/Adminhtml/Config/Form/Field/StatusMapping.php
+++ b/Block/Adminhtml/Config/Form/Field/StatusMapping.php
@@ -62,12 +62,11 @@ class StatusMapping extends \Magento\Config\Block\System\Config\Form\Field\Field
/**
* Constructor
*
- * @param \Magento\Backend\Block\Template\Context $context
- * @param \Magento\Framework\Data\Form\Element\Factory $elementFactory
- * @param \Magento\Sales\Model\Config\Source\Order\Status $orderStatus
- * @param \Payone\Core\Model\Source\TransactionStatus $transactionStatus
- * @param array $data
- * @return void
+ * @param \Magento\Backend\Block\Template\Context $context
+ * @param \Magento\Framework\Data\Form\Element\Factory $elementFactory
+ * @param \Magento\Sales\Model\Config\Source\Order\Status $orderStatus
+ * @param \Payone\Core\Model\Source\TransactionStatus $transactionStatus
+ * @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
@@ -89,10 +88,10 @@ public function __construct(
*/
protected function _construct()
{
- $this->addColumn('txaction', ['label' => __('Transactionstatus-message')]);
- $this->addColumn('state_status', ['label' => __('Magento-status')]);
- $this->addAfter = false;
- $this->addButtonLabel = __('Add Statusmapping');
+ $this->addColumn('txaction', ['label' => __('Transactionstatus-message')]); // set column name for txaction
+ $this->addColumn('state_status', ['label' => __('Magento-status')]); // set column name for state_status
+ $this->addAfter = false; // dont add "add after" button
+ $this->addButtonLabel = __('Add Statusmapping'); // set the label text of the button
parent::_construct();
}
@@ -105,23 +104,18 @@ protected function _construct()
public function renderCellTemplate($columnName)
{
if ($columnName == 'txaction' && isset($this->_columns[$columnName])) {
- $aOptions = $this->transactionStatus->toOptionArray();
+ $aOptions = $this->transactionStatus->toOptionArray(); // add transction status action options to dropdown
} elseif ($columnName == 'state_status' && isset($this->_columns[$columnName])) {
- $aOptions = $this->orderStatus->toOptionArray();
+ $aOptions = $this->orderStatus->toOptionArray(); // add state_status options to dropdown
} else {
return parent::renderCellTemplate($columnName);
}
$oElement = $this->elementFactory->create('select');
- $oElement->setForm(
- $this->getForm()
- )->setName(
- $this->_getCellInputElementName($columnName)
- )->setHtmlId(
- $this->_getCellInputElementId('<%- _id %>', $columnName)
- )->setValues(
- $aOptions
- );
+ $oElement->setForm($this->getForm());
+ $oElement->setName($this->_getCellInputElementName($columnName));
+ $oElement->setHtmlId($this->_getCellInputElementId('<%- _id %>', $columnName));
+ $oElement->setValues($aOptions);
return str_replace("\n", '', $oElement->getElementHtml());
}
@@ -135,22 +129,21 @@ public function renderCellTemplate($columnName)
public function getArrayRows()
{
if (null !== $this->_arrayRowsCache) {
- return $this->_arrayRowsCache;
+ return $this->_arrayRowsCache; // return cached values if set
}
$result = [];
/** @var \Magento\Framework\Data\Form\Element\AbstractElement */
$element = $this->getElement();
- $aValue = $element->getValue();
- if (!is_array($aValue)) {
- $aValue = unserialize($aValue);
+ $aValue = $element->getValue(); // get values
+ if (!is_array($aValue)) { // values given as array?
+ $aValue = unserialize($aValue); // convert string to array
}
-
if ($aValue && is_array($aValue)) {
foreach ($aValue as $rowId => $row) {
$rowColumnValues = [];
foreach ($row as $key => $value) {
$row[$key] = $value;
- $rowColumnValues[$this->_getCellInputElementId($rowId, $key)] = $row[$key];
+ $rowColumnValues[$this->_getCellInputElementId($rowId, $key)] = $row[$key]; // add value the row
}
$row['_id'] = $rowId;
$row['column_values'] = $rowColumnValues;
@@ -170,9 +163,9 @@ public function getArrayRows()
*/
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
- $this->setElement($element);
- $html = $this->_toHtml();
- $this->_arrayRowsCache = null;
+ $this->setElement($element); // set element
+ $html = $this->_toHtml(); // get render html for the object
+ $this->_arrayRowsCache = null; // reset cache
// doh, the object is used as singleton!
return $html;
}
diff --git a/Block/Adminhtml/Protocol/Api/View.php b/Block/Adminhtml/Protocol/Api/View.php
index 3ce429ca..46d4b757 100644
--- a/Block/Adminhtml/Protocol/Api/View.php
+++ b/Block/Adminhtml/Protocol/Api/View.php
@@ -50,10 +50,9 @@ class View extends \Magento\Backend\Block\Widget\Container
/**
* Constructor
*
- * @param \Magento\Backend\Block\Widget\Context $context
- * @param \Payone\Core\Model\Entities\ApiLogFactory $apiLogFactory
- * @param array $data
- * @return void
+ * @param \Magento\Backend\Block\Widget\Context $context
+ * @param \Payone\Core\Model\Entities\ApiLogFactory $apiLogFactory
+ * @param array $data
*/
public function __construct(
\Magento\Backend\Block\Widget\Context $context,
diff --git a/Block/Adminhtml/Protocol/Transactionstatus/View.php b/Block/Adminhtml/Protocol/Transactionstatus/View.php
index 9325f1c0..e2eb6e42 100644
--- a/Block/Adminhtml/Protocol/Transactionstatus/View.php
+++ b/Block/Adminhtml/Protocol/Transactionstatus/View.php
@@ -49,10 +49,9 @@ class View extends \Magento\Backend\Block\Widget\Container
/**
*
- * @param \Magento\Backend\Block\Widget\Context $context
- * @param \Payone\Core\Model\Entities\TransactionStatusFactory $statusFactory
- * @param array $data
- * @return void
+ * @param \Magento\Backend\Block\Widget\Context $context
+ * @param \Payone\Core\Model\Entities\TransactionStatusFactory $statusFactory
+ * @param array $data
*/
public function __construct(
\Magento\Backend\Block\Widget\Context $context,
diff --git a/Block/Onepage/Debit.php b/Block/Onepage/Debit.php
index 692a47d7..24e8a53c 100644
--- a/Block/Onepage/Debit.php
+++ b/Block/Onepage/Debit.php
@@ -50,9 +50,9 @@ class Debit extends Template
/**
* Constructor
*
+ * @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Framework\View\Element\Template\Context $context
- * @param array $data
- * @return void
+ * @param array $data
*/
public function __construct(
\Magento\Checkout\Model\Session $checkoutSession,
diff --git a/Block/Onepage/Success.php b/Block/Onepage/Success.php
index f053a798..cdd2b9cb 100644
--- a/Block/Onepage/Success.php
+++ b/Block/Onepage/Success.php
@@ -64,11 +64,10 @@ class Success extends Template
/**
* Constructor
*
- * @param \Magento\Checkout\Model\Session $checkoutSession
- * @param \Magento\Framework\View\Element\Template\Context $context
- * @param \Payone\Core\Helper\Payment $paymentHelper
- * @param array $data
- * @return void
+ * @param \Magento\Checkout\Model\Session $checkoutSession
+ * @param \Magento\Framework\View\Element\Template\Context $context
+ * @param \Payone\Core\Helper\Payment $paymentHelper
+ * @param array $data
*/
public function __construct(
\Magento\Checkout\Model\Session $checkoutSession,
diff --git a/Block/Paypal/ExpressButton.php b/Block/Paypal/ExpressButton.php
index 71062f11..516969f0 100644
--- a/Block/Paypal/ExpressButton.php
+++ b/Block/Paypal/ExpressButton.php
@@ -84,10 +84,9 @@ class ExpressButton extends Template implements \Magento\Catalog\Block\ShortcutI
/**
* Constructor
*
- * @param \Magento\Framework\View\Element\Template\Context $context
- * @param \Magento\Framework\Locale\ResolverInterface $localeResolver
- * @param array $data
- * @return void
+ * @param \Magento\Framework\View\Element\Template\Context $context
+ * @param \Magento\Framework\Locale\ResolverInterface $localeResolver
+ * @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
diff --git a/Controller/Adminhtml/Config/Export/Index.php b/Controller/Adminhtml/Config/Export/Index.php
index 5b137d0b..b6a25786 100644
--- a/Controller/Adminhtml/Config/Export/Index.php
+++ b/Controller/Adminhtml/Config/Export/Index.php
@@ -50,10 +50,9 @@ class Index extends Action
/**
* Constructor
*
- * @param \Magento\Backend\App\Action\Context $context
- * @param \Payone\Core\Model\Config\Export $configExport
- * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
- * @return void
+ * @param \Magento\Backend\App\Action\Context $context
+ * @param \Payone\Core\Model\Config\Export $configExport
+ * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
diff --git a/Controller/Adminhtml/Orders/Index.php b/Controller/Adminhtml/Orders/Index.php
index f1453e27..5c6a831a 100644
--- a/Controller/Adminhtml/Orders/Index.php
+++ b/Controller/Adminhtml/Orders/Index.php
@@ -54,9 +54,8 @@ class Index extends Action
/**
* Constructor
*
- * @param Context $context
- * @param PageFactory $resultPageFactory
- * @return void
+ * @param Context $context
+ * @param PageFactory $resultPageFactory
*/
public function __construct(Context $context, PageFactory $resultPageFactory)
{
diff --git a/Controller/Adminhtml/Protocol/Api/Index.php b/Controller/Adminhtml/Protocol/Api/Index.php
index 16344f3a..ad967509 100644
--- a/Controller/Adminhtml/Protocol/Api/Index.php
+++ b/Controller/Adminhtml/Protocol/Api/Index.php
@@ -54,9 +54,8 @@ class Index extends Action
/**
* Constructor
*
- * @param Context $context
- * @param PageFactory $resultPageFactory
- * @return void
+ * @param Context $context
+ * @param PageFactory $resultPageFactory
*/
public function __construct(Context $context, PageFactory $resultPageFactory)
{
diff --git a/Controller/Adminhtml/Protocol/Api/View.php b/Controller/Adminhtml/Protocol/Api/View.php
index b3382a01..18397500 100644
--- a/Controller/Adminhtml/Protocol/Api/View.php
+++ b/Controller/Adminhtml/Protocol/Api/View.php
@@ -53,10 +53,9 @@ class View extends \Magento\Backend\App\Action
/**
* Constructor
*
- * @param \Magento\Backend\App\Action\Context $context
- * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
- * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
- * @return void
+ * @param \Magento\Backend\App\Action\Context $context
+ * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
+ * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
diff --git a/Controller/Adminhtml/Protocol/Transactionstatus/Index.php b/Controller/Adminhtml/Protocol/Transactionstatus/Index.php
index 2b326522..af48be05 100644
--- a/Controller/Adminhtml/Protocol/Transactionstatus/Index.php
+++ b/Controller/Adminhtml/Protocol/Transactionstatus/Index.php
@@ -54,9 +54,8 @@ class Index extends Action
/**
* Constructor
*
- * @param Context $context
- * @param PageFactory $resultPageFactory
- * @return void
+ * @param Context $context
+ * @param PageFactory $resultPageFactory
*/
public function __construct(Context $context, PageFactory $resultPageFactory)
{
diff --git a/Controller/Adminhtml/Protocol/Transactionstatus/View.php b/Controller/Adminhtml/Protocol/Transactionstatus/View.php
index c4e24205..f07c6081 100644
--- a/Controller/Adminhtml/Protocol/Transactionstatus/View.php
+++ b/Controller/Adminhtml/Protocol/Transactionstatus/View.php
@@ -53,10 +53,9 @@ class View extends \Magento\Backend\App\Action
/**
* Constructor
*
- * @param Context $context
- * @param ForwardFactory $resultForwardFactory
- * @param PageFactory $resultPageFactory
- * @return void
+ * @param Context $context
+ * @param ForwardFactory $resultForwardFactory
+ * @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
diff --git a/Controller/Mandate/Download.php b/Controller/Mandate/Download.php
index 7d9198bc..24c2d74a 100644
--- a/Controller/Mandate/Download.php
+++ b/Controller/Mandate/Download.php
@@ -71,12 +71,11 @@ class Download extends \Magento\Framework\App\Action\Action
/**
* Constructor
*
- * @param \Magento\Framework\App\Action\Context $context
- * @param \Magento\Checkout\Model\Session $checkoutSession
- * @param \Payone\Core\Model\Api\Request\Getfile $getfileRequest
- * @param \Payone\Core\Helper\Payment $paymentHelper
- * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
- * @return void
+ * @param \Magento\Framework\App\Action\Context $context
+ * @param \Magento\Checkout\Model\Session $checkoutSession
+ * @param \Payone\Core\Model\Api\Request\Getfile $getfileRequest
+ * @param \Payone\Core\Helper\Payment $paymentHelper
+ * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
diff --git a/Controller/Onepage/Cancel.php b/Controller/Onepage/Cancel.php
index 007f87fd..e671f86f 100644
--- a/Controller/Onepage/Cancel.php
+++ b/Controller/Onepage/Cancel.php
@@ -50,10 +50,9 @@ class Cancel extends \Magento\Framework\App\Action\Action
/**
* Constructor
*
- * @param \Magento\Framework\App\Action\Context $context
- * @param \Magento\Checkout\Model\Session $checkoutSession
- * @param \Magento\Sales\Model\OrderFactory $orderFactory
- * @return void
+ * @param \Magento\Framework\App\Action\Context $context
+ * @param \Magento\Checkout\Model\Session $checkoutSession
+ * @param \Magento\Sales\Model\OrderFactory $orderFactory
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
diff --git a/Controller/Onepage/Debit.php b/Controller/Onepage/Debit.php
index 08ec181b..0453af83 100644
--- a/Controller/Onepage/Debit.php
+++ b/Controller/Onepage/Debit.php
@@ -74,13 +74,12 @@ class Debit extends \Magento\Framework\App\Action\Action
/**
* Constructor
*
- * @param \Magento\Framework\App\Action\Context $context
- * @param \Magento\Checkout\Model\Session $checkoutSession
- * @param \Payone\Core\Model\Api\Request\Managemandate $managemandateRequest
- * @param \Magento\Framework\View\Result\PageFactory $pageFactory
- * @param \Magento\Quote\Api\CartManagementInterface $cartManagement
- * @param \Magento\Checkout\Model\Type\Onepage $typeOnepage
- * @return void
+ * @param \Magento\Framework\App\Action\Context $context
+ * @param \Magento\Checkout\Model\Session $checkoutSession
+ * @param \Payone\Core\Model\Api\Request\Managemandate $managemandateRequest
+ * @param \Magento\Framework\View\Result\PageFactory $pageFactory
+ * @param \Magento\Quote\Api\CartManagementInterface $cartManagement
+ * @param \Magento\Checkout\Model\Type\Onepage $typeOnepage
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
diff --git a/Controller/Onepage/Redirect.php b/Controller/Onepage/Redirect.php
index a1be30f6..bc90a850 100644
--- a/Controller/Onepage/Redirect.php
+++ b/Controller/Onepage/Redirect.php
@@ -41,10 +41,8 @@ class Redirect extends \Magento\Framework\App\Action\Action
/**
* Constructor
*
- * @param \Magento\Framework\App\Action\Context $context
- * @param \Magento\Checkout\Model\Session $checkoutSession
- * @param \Magento\Framework\Url\Helper\Data $urlHelper
- * @return void
+ * @param \Magento\Framework\App\Action\Context $context
+ * @param \Magento\Checkout\Model\Session $checkoutSession
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
diff --git a/Controller/Paypal/Express.php b/Controller/Paypal/Express.php
index 09a291a7..61e742e5 100644
--- a/Controller/Paypal/Express.php
+++ b/Controller/Paypal/Express.php
@@ -79,14 +79,13 @@ class Express extends \Magento\Framework\App\Action\Action
/**
* Constructor
*
- * @param \Magento\Framework\App\Action\Context $context
- * @param \Magento\Checkout\Model\Session $checkoutSession
- * @param \Payone\Core\Model\Api\Request\Genericpayment\PayPalExpress $genericRequest
- * @param \Payone\Core\Model\Methods\Paypal $paypalPayment
- * @param \Magento\Checkout\Helper\Data $checkoutHelper
- * @param \Magento\Customer\Model\Session $customerSession
- * @param \Payone\Core\Helper\Payment $paymentHelper
- * @return void
+ * @param \Magento\Framework\App\Action\Context $context
+ * @param \Magento\Checkout\Model\Session $checkoutSession
+ * @param \Payone\Core\Model\Api\Request\Genericpayment\PayPalExpress $genericRequest
+ * @param \Payone\Core\Model\Methods\Paypal $paypalPayment
+ * @param \Magento\Checkout\Helper\Data $checkoutHelper
+ * @param \Magento\Customer\Model\Session $customerSession
+ * @param \Payone\Core\Helper\Payment $paymentHelper
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
diff --git a/Controller/Paypal/Returned.php b/Controller/Paypal/Returned.php
index d2d1e5a4..63243d70 100644
--- a/Controller/Paypal/Returned.php
+++ b/Controller/Paypal/Returned.php
@@ -57,11 +57,10 @@ class Returned extends \Magento\Framework\App\Action\Action
/**
* Constructor
*
- * @param \Magento\Framework\App\Action\Context $context
- * @param \Magento\Checkout\Model\Session $checkoutSession
- * @param \Payone\Core\Model\Methods\Paypal $paypalPayment
- * @param \Payone\Core\Model\Paypal\ReturnHandler $returnHandler
- * @return void
+ * @param \Magento\Framework\App\Action\Context $context
+ * @param \Magento\Checkout\Model\Session $checkoutSession
+ * @param \Payone\Core\Model\Methods\Paypal $paypalPayment
+ * @param \Payone\Core\Model\Paypal\ReturnHandler $returnHandler
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
diff --git a/Controller/Transactionstatus/Index.php b/Controller/Transactionstatus/Index.php
index 44ab4b24..30013237 100644
--- a/Controller/Transactionstatus/Index.php
+++ b/Controller/Transactionstatus/Index.php
@@ -92,15 +92,14 @@ class Index extends \Magento\Framework\App\Action\Action
/**
* Constructor
*
- * @param \Magento\Framework\App\Action\Context $context
- * @param \Payone\Core\Model\ResourceModel\TransactionStatus $transactionStatus
- * @param \Payone\Core\Helper\Toolkit $toolkitHelper
- * @param \Payone\Core\Helper\Environment $environmentHelper
- * @param \Payone\Core\Helper\Order $orderHelper
- * @param \Payone\Core\Model\TransactionStatus\Mapping $statusMapping
- * @param \Payone\Core\Model\TransactionStatus\Forwarding $statusForwarding
- * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
- * @return void
+ * @param \Magento\Framework\App\Action\Context $context
+ * @param \Payone\Core\Model\ResourceModel\TransactionStatus $transactionStatus
+ * @param \Payone\Core\Helper\Toolkit $toolkitHelper
+ * @param \Payone\Core\Helper\Environment $environmentHelper
+ * @param \Payone\Core\Helper\Order $orderHelper
+ * @param \Payone\Core\Model\TransactionStatus\Mapping $statusMapping
+ * @param \Payone\Core\Model\TransactionStatus\Forwarding $statusForwarding
+ * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
diff --git a/Helper/Api.php b/Helper/Api.php
index e6cbba90..fe91f2db 100644
--- a/Helper/Api.php
+++ b/Helper/Api.php
@@ -94,8 +94,10 @@ public function __construct(
public function sendApiRequest($sRequestUrl)
{
$aParsedRequestUrl = parse_url($sRequestUrl);
+ if ($aParsedRequestUrl === false) {
+ return ["errormessage" => "Payone API request URL could not be parsed."];
+ }
- $aResponse = [];
if (function_exists("curl_init")) {
// php native curl exists so we gonna use it for requesting
$aResponse = $this->connCurlPhp->sendCurlPhpRequest($aParsedRequestUrl);
@@ -122,13 +124,13 @@ protected function formatOutputByResponse($aResponse)
{
$aOutput = [];
- if (is_array($aResponse)) {// correct response existing?
- foreach ($aResponse as $iLinenum => $sLine) {// go through line by line
+ if (is_array($aResponse)) { // correct response existing?
+ foreach ($aResponse as $iLinenum => $sLine) { // go through line by line
$iPos = strpos($sLine, "=");
- if ($iPos > 0) {// is a "=" as delimiter existing?
- $aOutput[substr($sLine, 0, $iPos)] = trim(substr($sLine, $iPos+1));
- } elseif (!empty($sLine)) {// is line not empty?
- $aOutput[$iLinenum] = $sLine;// add the line unedited
+ if ($iPos > 0) { // is a "=" as delimiter existing?
+ $aOutput[substr($sLine, 0, $iPos)] = trim(substr($sLine, $iPos + 1));
+ } elseif (!empty($sLine)) { // is line not empty?
+ $aOutput[$iLinenum] = $sLine; // add the line unedited
}
}
}
@@ -139,13 +141,15 @@ protected function formatOutputByResponse($aResponse)
/**
* Generate the request url out of the params and die api url
*
+ * @param array $aParameters
+ * @param string $sApiUrl
* @return string
*/
public function getRequestUrl($aParameters, $sApiUrl)
{
$sRequestUrl = '';
foreach ($aParameters as $sKey => $mValue) {
- if (is_array($mValue)) {// might be array
+ if (is_array($mValue)) { // might be array
foreach ($mValue as $i => $sSubValue) {
$sRequestUrl .= "&".$sKey."[".$i."]=".urlencode($sSubValue);
}
@@ -168,11 +172,11 @@ public function getRequestUrl($aParameters, $sApiUrl)
public function addPayoneOrderData(SalesOrder $oOrder, $aRequest, $aResponse)
{
if (isset($aResponse['txid'])) {// txid existing?
- $oOrder->setPayoneTxid($aResponse['txid']);// add txid to order entity
+ $oOrder->setPayoneTxid($aResponse['txid']); // add txid to order entity
}
- $oOrder->setPayoneRefnr($aRequest['reference']);// add refnr to order entity
- $oOrder->setPayoneAuthmode($aRequest['request']);// add authmode to order entity
- $oOrder->setPayoneMode($aRequest['mode']);// add payone mode to order entity
+ $oOrder->setPayoneRefnr($aRequest['reference']); // add refnr to order entity
+ $oOrder->setPayoneAuthmode($aRequest['request']); // add authmode to order entity
+ $oOrder->setPayoneMode($aRequest['mode']); // add payone mode to order entity
if (isset($aRequest['mandate_identification'])) {// mandate id existing in request?
$oOrder->setPayoneMandateId($aRequest['mandate_identification']);
} elseif (isset($aResponse['mandate_identification'])) {// mandate id existing in response?
@@ -188,11 +192,11 @@ public function addPayoneOrderData(SalesOrder $oOrder, $aRequest, $aResponse)
*/
public function isInvoiceDataNeeded(PayoneMethod $oPayment)
{
- $sType = $this->getConfigParam('request_type');// auth or preauth?
- $blInvoiceEnabled = (bool)$this->getConfigParam('transmit_enabled', 'invoicing');// invoicing enabled?
+ $sType = $this->getConfigParam('request_type'); // auth or preauth?
+ $blInvoiceEnabled = (bool)$this->getConfigParam('transmit_enabled', 'invoicing'); // invoicing enabled?
if ($oPayment->needsProductInfo() || ($sType == PayoneConfig::REQUEST_TYPE_AUTHORIZATION && $blInvoiceEnabled)) {
- return true;// invoice data needed
+ return true; // invoice data needed
}
- return false;// invoice data not needed
+ return false; // invoice data not needed
}
}
diff --git a/Helper/Base.php b/Helper/Base.php
index dcf63416..07aa3229 100644
--- a/Helper/Base.php
+++ b/Helper/Base.php
@@ -43,8 +43,8 @@ class Base extends \Magento\Framework\App\Helper\AbstractHelper
/**
* Constructor
*
- * @param \Magento\Framework\App\Helper\Context $context
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
+ * @param \Magento\Framework\App\Helper\Context $context
+ * @param \Magento\Store\Model\StoreManagerInterface $storeManager
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
@@ -69,11 +69,8 @@ public function getConfigParam($sKey, $sGroup = 'global', $sSection = 'payone_ge
if (!$sStoreCode) {
$sStoreCode = $this->storeManager->getStore()->getCode();
}
- return $this->scopeConfig->getValue(
- $sSection."/".$sGroup."/".$sKey,
- ScopeInterface::SCOPE_STORE,
- $sStoreCode
- );
+ $sPath = $sSection."/".$sGroup."/".$sKey;
+ return $this->scopeConfig->getValue($sPath, ScopeInterface::SCOPE_STORE, $sStoreCode);
}
/**
diff --git a/Helper/ConfigExport.php b/Helper/ConfigExport.php
index ccf8ff4d..40e1092c 100644
--- a/Helper/ConfigExport.php
+++ b/Helper/ConfigExport.php
@@ -174,6 +174,6 @@ public function getCountries($sPaymentCode, $sStoreCode)
if ($this->getPaymentConfig('allowspecific', $sPaymentCode, $sStoreCode, true) == '1') {
return $this->getPaymentConfig('specificcountry', $sPaymentCode, $sStoreCode, true);
}
- return '';// empty return value if all countries are available
+ return ''; // empty return value if all countries are available
}
}
diff --git a/Helper/Consumerscore.php b/Helper/Consumerscore.php
new file mode 100644
index 00000000..8aee1348
--- /dev/null
+++ b/Helper/Consumerscore.php
@@ -0,0 +1,267 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Helper;
+
+use Magento\Quote\Api\Data\AddressInterface;
+use Magento\Store\Model\ScopeInterface;
+
+/**
+ * Helper class for everything that has to do with the consumerscore request
+ */
+class Consumerscore extends \Payone\Core\Helper\Base
+{
+ const CONFIG_KEY_CONSUMERSCORE_SAMPLE_COUNTER = 'payone_consumerscore_sample_counter';
+
+ /**
+ * Config writer resource
+ *
+ * @var \Magento\Framework\App\Config\Storage\WriterInterface
+ */
+ protected $configWriter;
+
+ /**
+ * PAYONE database helper
+ *
+ * @var \Payone\Core\Helper\Database
+ */
+ protected $databaseHelper;
+
+ /**
+ * Constructor
+ *
+ * @param \Magento\Framework\App\Helper\Context $context
+ * @param \Magento\Store\Model\StoreManagerInterface $storeManager
+ * @param \Magento\Framework\App\Config\Storage\WriterInterface $configWriter
+ * @param \Payone\Core\Helper\Database $databaseHelper
+ */
+ public function __construct(
+ \Magento\Framework\App\Helper\Context $context,
+ \Magento\Store\Model\StoreManagerInterface $storeManager,
+ \Magento\Framework\App\Config\Storage\WriterInterface $configWriter,
+ \Payone\Core\Helper\Database $databaseHelper
+ ) {
+ parent::__construct($context, $storeManager);
+ $this->configWriter = $configWriter;
+ $this->databaseHelper = $databaseHelper;
+ }
+
+ /**
+ * Retrieve the creditrating sample counter from config
+ *
+ * @return int
+ */
+ public function getConsumerscoreSampleCounter()
+ {
+ $iCounter = $this->databaseHelper->getConfigParamWithoutCache(
+ self::CONFIG_KEY_CONSUMERSCORE_SAMPLE_COUNTER,
+ 'creditrating',
+ 'payone_protect'
+ );
+ if (empty($iCounter) || !is_numeric($iCounter)) {
+ $iCounter = 0;
+ }
+ return $iCounter;
+ }
+
+ /**
+ * Store new value for creditrating sample counter in config
+ *
+ * @param $iCount
+ * @return void
+ */
+ public function setConsumerscoreSampleCounter($iCount)
+ {
+ $this->configWriter->save(
+ 'payone_protect/creditrating/'.self::CONFIG_KEY_CONSUMERSCORE_SAMPLE_COUNTER,
+ $iCount,
+ ScopeInterface::SCOPE_STORE,
+ $this->storeManager->getStore()->getId()
+ );
+ }
+
+ /**
+ * Increment creditrating sample counter in config
+ *
+ * @return int Returns the new counter value
+ */
+ public function incrementConsumerscoreSampleCounter()
+ {
+ $iCounter = $this->getConsumerscoreSampleCounter(); // get current sample counter
+ if (empty($iCounter) || !is_numeric($iCounter)) {
+ $iCounter = 0;
+ }
+
+ $iCounter++;
+ $this->setConsumerscoreSampleCounter($iCounter); // set current sample counter
+ return $iCounter;
+ }
+
+ /**
+ * Determine if a consumerscore sample has to be taken
+ *
+ * @return bool
+ */
+ public function isSampleNeeded()
+ {
+ $iFrequency = $this->getConfigParam('sample_mode_frequency', 'creditrating', 'payone_protect');
+ if ((bool)$this->getConfigParam('sample_mode_enabled', 'creditrating', 'payone_protect') && !empty($iFrequency)) {
+ $iCounter = $this->getConsumerscoreSampleCounter(); // get current sample counter
+ if ($iCounter % $iFrequency !== 0) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Return if the consumerscore hint text has to be shown on payment selection
+ *
+ * @return bool
+ */
+ public function canShowPaymentHintText()
+ {
+ if ((bool)$this->getConfigParam('enabled', 'creditrating', 'payone_protect')
+ && (bool)$this->getConfigParam('payment_hint_enabled', 'creditrating', 'payone_protect')
+ && $this->getConfigParam('integration_event', 'creditrating', 'payone_protect') == 'after_payment') {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Return if the consumerscore agreement message has to be shown on payment selection
+ *
+ * @return bool
+ */
+ public function canShowAgreementMessage()
+ {
+ if ((bool)$this->getConfigParam('enabled', 'creditrating', 'payone_protect')
+ && (bool)$this->getConfigParam('agreement_enabled', 'creditrating', 'payone_protect')
+ && $this->getConfigParam('integration_event', 'creditrating', 'payone_protect') == 'after_payment') {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Get worst score
+ *
+ * @param array $aScores
+ * @return string
+ */
+ public function getWorstScore($aScores)
+ {
+ if (array_search('R', $aScores) !== false) { // is there a red score existing?
+ return 'R'; // return red as worst score
+ }
+
+ if (array_search('Y', $aScores) !== false) { // is there a yellow score existing?
+ return 'Y'; // return yellow as worst score
+ }
+ return 'G'; // return green
+ }
+
+ /**
+ * Get the allowed methods for the score and transform it into an array
+ *
+ * @param string $sScore
+ * @return array
+ */
+ public function getAllowedMethodsForScore($sScore)
+ {
+ $sMethods = '';
+ if ($sScore == 'Y') {
+ $sMethods = $this->getConfigParam('allow_payment_methods_yellow', 'creditrating', 'payone_protect');
+ } elseif ($sScore == 'R') {
+ $sMethods = $this->getConfigParam('allow_payment_methods_red', 'creditrating', 'payone_protect');
+ }
+
+ $aMethods = [];
+ if (!empty($sScore)) {
+ $aMethods = explode(',', $sMethods); // config comes as a concatinated string
+ }
+ return $aMethods;
+ }
+
+ /**
+ * Copy the status of old creditrating checks to the new addresses
+ * when the lifetime of the old check was still active
+ *
+ * @param AddressInterface $oAddress
+ * @return void
+ */
+ public function copyOldStatusToNewAddress(AddressInterface $oAddress)
+ {
+ $sOldStatus = $this->databaseHelper->getOldAddressStatus($oAddress); // get old score from db
+ if (!empty($sOldStatus)) {
+ $oAddress->setPayoneProtectScore($sOldStatus)->save(); // add score to quote address object
+ }
+ }
+
+ /**
+ * Determine if the given quote total needs a consumerscore check
+ *
+ * @param double $dTotal
+ * @return bool
+ */
+ public function isCheckNeededForPrice($dTotal)
+ {
+ $dMin = $this->getConfigParam('min_order_total', 'creditrating', 'payone_protect');
+ $dMax = $this->getConfigParam('max_order_total', 'creditrating', 'payone_protect');
+ if (is_numeric($dMin) && is_numeric($dMax) && ($dTotal < $dMin || $dTotal > $dMax)) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Base checks if a creditrating check is needed
+ *
+ * @param string $sIntegrationEvent
+ * @param double $dGrandTotal
+ * @return bool
+ */
+ public function isCreditratingNeeded($sIntegrationEvent, $dGrandTotal)
+ {
+ if ((bool)$this->getConfigParam('enabled', 'creditrating', 'payone_protect') === false) {
+ return false;
+ }
+
+ if ($this->getConfigParam('integration_event', 'creditrating', 'payone_protect') != $sIntegrationEvent) {
+ return false;
+ }
+
+ if ($this->isCheckNeededForPrice($dGrandTotal) === false) {
+ return false;
+ }
+
+ if ($this->isSampleNeeded() === false) {
+ return false;
+ }
+ return true;
+ }
+}
diff --git a/Helper/Customer.php b/Helper/Customer.php
index 3f3954a8..419e4613 100644
--- a/Helper/Customer.php
+++ b/Helper/Customer.php
@@ -99,7 +99,8 @@ public function customerHasGivenBirthday()
/**
* Get the region object for the state and country given by PayPal
*
- * @param array $aResponse
+ * @param string $sCountry
+ * @param string $sState
* @return Region|bool
*/
public function getRegion($sCountry, $sState)
diff --git a/Helper/Database.php b/Helper/Database.php
index 807f3d69..0773a652 100644
--- a/Helper/Database.php
+++ b/Helper/Database.php
@@ -27,6 +27,8 @@
namespace Payone\Core\Helper;
use Magento\Framework\DB\Adapter\AdapterInterface;
+use Magento\Quote\Api\Data\AddressInterface;
+use Magento\Store\Model\ScopeInterface;
/**
* Helper class for everything that has to do with database connections
@@ -176,6 +178,92 @@ public function getSequenceNumber($iTxid)
if ($iCount === null) {
return 0;
}
- return $iCount+1;
+ return $iCount + 1;
+ }
+
+ /**
+ * Helper method to get parameter from the config directly from db without cache
+ *
+ * @param string $sKey
+ * @param string $sGroup
+ * @param string $sSection
+ * @param string $sScopeId
+ * @return string
+ */
+ public function getConfigParamWithoutCache($sKey, $sGroup = 'global', $sSection = 'payone_general', $sScopeId = null)
+ {
+ $sQuery = " SELECT
+ value
+ FROM
+ ".$this->databaseResource->getTableName('core_config_data')."
+ WHERE
+ path = :path AND
+ scope = :scope AND
+ scope_id = :scope_id";
+ $sPath = $sSection."/".$sGroup."/".$sKey;
+ $sScope = ScopeInterface::SCOPE_STORE;
+ if (!$sScopeId) {
+ $sScopeId = $this->storeManager->getStore()->getId();
+ }
+ $sReturn = $this->getDb()->fetchOne($sQuery, ['path' => $sPath, 'scope' => $sScope, 'scope_id' => $sScopeId]);
+ return $sReturn;
+ }
+
+ /**
+ * Get the address status from a previous order address
+ *
+ * @param AddressInterface $oAddress
+ * @param bool $blIsCreditrating
+ * @return string
+ */
+ public function getOldAddressStatus(AddressInterface $oAddress, $blIsCreditrating = true)
+ {
+ $sSelectField = 'payone_protect_score';
+ if ($blIsCreditrating === false) {
+ $sSelectField = 'payone_addresscheck_score';
+ }
+
+ $aParams = [
+ 'firstname' => $oAddress->getFirstname(),
+ 'lastname' => $oAddress->getLastname(),
+ 'street' => $oAddress->getStreet()[0],
+ 'city' => $oAddress->getCity(),
+ 'region' => $oAddress->getRegion(),
+ 'postcode' => $oAddress->getPostcode(),
+ 'country_id' => $oAddress->getCountryId(),
+ ];
+ $sQuery = " SELECT
+ {$sSelectField}
+ FROM
+ {$this->databaseResource->getTableName('quote_address')}
+ WHERE
+ firstname = :firstname AND
+ lastname = :lastname AND
+ street = :street AND
+ city = :city AND
+ region = :region AND
+ postcode = :postcode AND
+ country_id = :country_id";
+ if (!empty($oAddress->getId())) {
+ $sQuery .= " AND address_id != :curr_id";
+ $aParams['curr_id'] = $oAddress->getId();
+ }
+ if (!empty($oAddress->getCustomerId())) {
+ $sQuery .= " AND customer_id = :cust_id";
+ $aParams['cust_id'] = $oAddress->getCustomerId();
+ }
+ if (!empty($oAddress->getAddressType())) {
+ $sQuery .= " AND address_type = :addr_type";
+ $aParams['addr_type'] = $oAddress->getAddressType();
+ }
+ if ($blIsCreditrating === true) {
+ $sQuery .= " AND payone_protect_score != ''";
+ } else {
+ $sQuery .= " AND payone_addresscheck_score != ''";
+ }
+ $sQuery .= " ORDER BY address_id DESC LIMIT 1";
+
+ $sReturn = $this->getDb()->fetchOne($sQuery, $aParams);
+ return $sReturn;
}
}
diff --git a/Helper/HostedIframe.php b/Helper/HostedIframe.php
index 3b499b7a..bbeb6346 100644
--- a/Helper/HostedIframe.php
+++ b/Helper/HostedIframe.php
@@ -70,9 +70,9 @@ protected function getHostedParams()
{
if ($this->aHostedParams === null) {
$this->aHostedParams = [];
- $sHostedParams = $this->getConfigParam('cc_template', 'creditcard');
- if ($sHostedParams) {
- $aHostedParams = unserialize($sHostedParams);
+ $sHostedParams = $this->getConfigParam('cc_template', 'creditcard'); // get params from config
+ if ($sHostedParams) { // params set in config?
+ $aHostedParams = unserialize($sHostedParams); // create array from serialized string
if ($aHostedParams) {
$this->aHostedParams = $aHostedParams;
}
@@ -120,7 +120,7 @@ protected function getFieldConfig()
{
$aFields = [];
$aFields['cardpan'] = $this->getFieldConfigField('cardpan', 'Number');
- if ($this->paymentHelper->isCheckCvcActive() === true) {
+ if ($this->paymentHelper->isCheckCvcActive() === true) { // cvc field activated?
$aFields['cardcvc2'] = $this->getFieldConfigField('cardcvc2', 'CVC');
}
$aFields['cardexpiremonth'] = $this->getFieldConfigField('cardexpiremonth', 'Month');
@@ -153,15 +153,15 @@ protected function getDefaultStyles($aHostedParams)
*/
public function getHostedFieldConfig()
{
- $aHostedParams = $this->getHostedParams();// get hosted params from config
+ $aHostedParams = $this->getHostedParams(); // get hosted params from config
$aFieldConfig = [];
- if (!empty($aHostedParams)) {
- $aFieldConfig['fields'] = $this->getFieldConfig();// generate config for all field types
+ if (!empty($aHostedParams)) { // hosted iframe config existing?
+ $aFieldConfig['fields'] = $this->getFieldConfig(); // generate config for all field types
$aFieldConfig['defaultStyle'] = $this->getDefaultStyles($aHostedParams);
if ($aHostedParams['Errors_active'] == "true") {
- $aFieldConfig['error'] = 'errorOutput';// area to display error-messages (optional)
- $aFieldConfig['language'] = $aHostedParams['Errors_lang'];// has to be defined in javascript
+ $aFieldConfig['error'] = 'errorOutput'; // area to display error-messages (optional)
+ $aFieldConfig['language'] = $aHostedParams['Errors_lang']; // has to be defined in javascript
}
}
return $aFieldConfig;
diff --git a/Helper/Order.php b/Helper/Order.php
index 90e59141..445ddf8f 100644
--- a/Helper/Order.php
+++ b/Helper/Order.php
@@ -92,6 +92,7 @@ public function __construct(
/**
* Return the order related to the given TransactionStatus
*
+ * @param string $sTxid
* @return SalesOrder|null
*/
public function getOrderByTxid($sTxid)
@@ -125,9 +126,9 @@ public function getShippingMethod(Quote $oQuote, Address $oShippingAddress)
}
}
- if (!empty($aRates)) {// more than one shipping method existing?
- ksort($aRates);// sort by price ascending
- return array_shift($aRates);// return the cheapest shipping-method
+ if (!empty($aRates)) { // more than one shipping method existing?
+ ksort($aRates); // sort by price ascending
+ return array_shift($aRates); // return the cheapest shipping-method
}
return false;
}
@@ -157,7 +158,13 @@ public function setShippingMethod(Address $oAddress, Quote $oQuote)
* Fill billing and shipping addresses with the needed information from the response
*
* @param Address $oAddress
- * @param array $aResponse
+ * @param string $sFirstname
+ * @param string $sLastname
+ * @param string $sStreet
+ * @param string $sCity
+ * @param string $sZip
+ * @param string $sCountry
+ * @param string $sState
* @return Address
*/
public function fillSingleAddress(Address $oAddress, $sFirstname, $sLastname, $sStreet, $sCity, $sZip, $sCountry, $sState)
diff --git a/Helper/Toolkit.php b/Helper/Toolkit.php
index 397c5a68..060e3cd8 100644
--- a/Helper/Toolkit.php
+++ b/Helper/Toolkit.php
@@ -132,7 +132,7 @@ public function handleSubstituteReplacement($sText, $aSubstitutionArray, $iMaxLe
if (!empty($sText)) {
$sText = str_replace(array_keys($aSubstitutionArray), array_values($aSubstitutionArray), $sText);
if ($iMaxLength !== false && strlen($sText) > $iMaxLength) {
- $sText = substr($sText, 0, $iMaxLength);// shorten text if too long
+ $sText = substr($sText, 0, $iMaxLength); // shorten text if too long
}
return $sText;
}
@@ -147,7 +147,7 @@ public function handleSubstituteReplacement($sText, $aSubstitutionArray, $iMaxLe
*/
public function getInvoiceAppendix(SalesOrder $oOrder)
{
- $sText = $this->getConfigParam('invoice_appendix', 'invoicing');// get invoice appendix from config
+ $sText = $this->getConfigParam('invoice_appendix', 'invoicing'); // get invoice appendix from config
$aSubstitutionArray = [
'{{order_increment_id}}' => $oOrder->getIncrementId(),
'{{customer_id}}' => $oOrder->getCustomerId(),
@@ -165,7 +165,7 @@ public function getInvoiceAppendix(SalesOrder $oOrder)
*/
public function getNarrativeText(SalesOrder $oOrder, PayoneMethod $oPayment)
{
- $sText = $this->getConfigParam($oPayment->getCode(), 'text');// get narrative text for payment from config
+ $sText = $this->getConfigParam($oPayment->getCode(), 'text'); // get narrative text for payment from config
$aSubstitutionArray = [
'{{order_increment_id}}' => $oOrder->getIncrementId(),
];
@@ -178,7 +178,7 @@ public function getNarrativeText(SalesOrder $oOrder, PayoneMethod $oPayment)
*
* @param double $dPrice price of any sort
* @param int $iDecimals number of digits behind the decimal point
- * @return double
+ * @return string
*/
public function formatNumber($dPrice, $iDecimals = 2)
{
@@ -207,7 +207,7 @@ public static function isUTF8($sString)
public function getAdditionalDataEntry(DataObject $oData, $sKey)
{
// The way to read the form-parameters changed with version 2.0.6
- if (version_compare($this->shopHelper->getMagentoVersion(), '2.0.6', '>=')) {// Magento 2.0.6 and above
+ if (version_compare($this->shopHelper->getMagentoVersion(), '2.0.6', '>=')) { // Magento 2.0.6 and above
$aAdditionalData = $oData->getAdditionalData();
if (isset($aAdditionalData[$sKey])) {
return $aAdditionalData[$sKey];
diff --git a/Model/Api/Invoice.php b/Model/Api/Invoice.php
index 57248c9e..56b1d013 100644
--- a/Model/Api/Invoice.php
+++ b/Model/Api/Invoice.php
@@ -79,8 +79,7 @@ class Invoice
/**
* Constructor
*
- * @param \Payone\Core\Helper\Toolkit $toolkitHelper Toolkit helper
- * @return void
+ * @param \Payone\Core\Helper\Toolkit $toolkitHelper Toolkit helper
*/
public function __construct(\Payone\Core\Helper\Toolkit $toolkitHelper)
{
@@ -100,14 +99,14 @@ public function __construct(\Payone\Core\Helper\Toolkit $toolkitHelper)
*/
protected function addInvoicePosition($sId, $dPrice, $sItemType, $iAmount, $sDesc, $dVat)
{
- $this->oRequest->addParameter('id['.$this->iIndex.']', $sId);// add invoice item id
- $this->oRequest->addParameter('pr['.$this->iIndex.']', $this->toolkitHelper->formatNumber($dPrice) * 100);// expected in smallest unit of currency
- $this->oRequest->addParameter('it['.$this->iIndex.']', $sItemType);// add invoice item type
- $this->oRequest->addParameter('no['.$this->iIndex.']', $iAmount);// add invoice item amount
- $this->oRequest->addParameter('de['.$this->iIndex.']', $sDesc);// add invoice item description
- $this->oRequest->addParameter('va['.$this->iIndex.']', $this->toolkitHelper->formatNumber($dVat * 100, 0));// expected * 100 to also handle vats with decimals
- $this->dAmount += $dPrice * $iAmount;// needed for return of the main method
- $this->iIndex++;// increase index for next item
+ $this->oRequest->addParameter('id['.$this->iIndex.']', $sId); // add invoice item id
+ $this->oRequest->addParameter('pr['.$this->iIndex.']', $this->toolkitHelper->formatNumber($dPrice) * 100); // expected in smallest unit of currency
+ $this->oRequest->addParameter('it['.$this->iIndex.']', $sItemType); // add invoice item type
+ $this->oRequest->addParameter('no['.$this->iIndex.']', $iAmount); // add invoice item amount
+ $this->oRequest->addParameter('de['.$this->iIndex.']', $sDesc); // add invoice item description
+ $this->oRequest->addParameter('va['.$this->iIndex.']', $this->toolkitHelper->formatNumber($dVat * 100, 0)); // expected * 100 to also handle vats with decimals
+ $this->dAmount += $dPrice * $iAmount; // needed for return of the main method
+ $this->iIndex++; // increase index for next item
}
/**
@@ -117,26 +116,26 @@ protected function addInvoicePosition($sId, $dPrice, $sItemType, $iAmount, $sDes
* @param Order $oOrder Order object
* @param array $aPositions Is given with non-complete captures or debits
* @param bool $blDebit Is the call coming from a debit request
- * @return float
+ * @return integer
*/
public function addProductInfo(Base $oRequest, Order $oOrder, $aPositions = false, $blDebit = false)
{
- $this->oRequest = $oRequest;// write request to property for manipulation of the object
- $sInvoiceAppendix = $this->toolkitHelper->getInvoiceAppendix($oOrder);// get invoice appendix
+ $this->oRequest = $oRequest; // write request to property for manipulation of the object
+ $sInvoiceAppendix = $this->toolkitHelper->getInvoiceAppendix($oOrder); // get invoice appendix
if (!empty($sInvoiceAppendix)) {// invoice appendix existing?
- $this->oRequest->addParameter('invoiceappendix', $sInvoiceAppendix);// add appendix to request
+ $this->oRequest->addParameter('invoiceappendix', $sInvoiceAppendix); // add appendix to request
}
- foreach ($oOrder->getAllItems() as $oItem) {// add invoice items for all order items
- if ($oItem->isDummy() === false) {// prevent variant-products of adding 2 items
- $this->addProductItem($oItem, $aPositions);// add product invoice params to request
+ foreach ($oOrder->getAllItems() as $oItem) { // add invoice items for all order items
+ if ($oItem->isDummy() === false) { // prevent variant-products of adding 2 items
+ $this->addProductItem($oItem, $aPositions); // add product invoice params to request
}
}
- $blFirstCapture = true;// Is first capture?
+ $blFirstCapture = true; // Is first capture?
if ($aPositions === false || $blFirstCapture === true || $blDebit === true) {
- $this->addShippingItem($oOrder, $aPositions, $blDebit);// add shipping invoice params to request
- $this->addDiscountItem($oOrder, $aPositions, $blDebit);// add discount invoice params to request
+ $this->addShippingItem($oOrder, $aPositions, $blDebit); // add shipping invoice params to request
+ $this->addDiscountItem($oOrder, $aPositions, $blDebit); // add discount invoice params to request
}
return $this->dAmount;
}
@@ -150,15 +149,15 @@ public function addProductInfo(Base $oRequest, Order $oOrder, $aPositions = fals
*/
protected function addProductItem($oItem, $aPositions)
{
- if ($aPositions === false || array_key_exists($oItem->getProductId(), $aPositions) !== false) {// full or single-invoice?
- $dItemAmount = $oItem->getQtyOrdered();// get ordered item amount
- if ($aPositions !== false && array_key_exists($oItem->getProductId(), $aPositions) !== false) {// product existing in single-invoice?
- $dItemAmount = $aPositions[$oItem->getProductId()]['amount'];// use amount from single-invoice
+ if ($aPositions === false || array_key_exists($oItem->getProductId(), $aPositions) !== false) { // full or single-invoice?
+ $dItemAmount = $oItem->getQtyOrdered(); // get ordered item amount
+ if ($aPositions !== false && array_key_exists($oItem->getProductId(), $aPositions) !== false) { // product existing in single-invoice?
+ $dItemAmount = $aPositions[$oItem->getProductId()]['amount']; // use amount from single-invoice
}
- $dBrutPrice = $oItem->getBasePrice() + ($oItem->getBaseTaxAmount() / $oItem->getQtyOrdered());// cals single item price
- $this->addInvoicePosition($oItem->getSku(), $dBrutPrice, 'goods', $dItemAmount, $oItem->getName(), $oItem->getTaxPercent());
- if ($this->dTax === false) {// is dTax not set yet?
- $this->dTax = $oItem->getTaxPercent();// set the tax for following entities which dont have the vat attached to it
+ $dBrutPrice = $oItem->getBasePrice() + ($oItem->getBaseTaxAmount() / $oItem->getQtyOrdered()); // cals single item price
+ $this->addInvoicePosition($oItem->getSku(), $dBrutPrice, 'goods', $dItemAmount, $oItem->getName(), $oItem->getTaxPercent()); // add invoice params to request
+ if ($this->dTax === false) { // is dTax not set yet?
+ $this->dTax = $oItem->getTaxPercent(); // set the tax for following entities which dont have the vat attached to it
}
}
}
@@ -175,12 +174,12 @@ protected function addShippingItem(Order $oOrder, $aPositions, $blDebit)
{
// shipping costs existing or given for partial captures/debits?
if ($oOrder->getBaseShippingInclTax() != 0 && ($aPositions === false || ($blDebit === false || array_key_exists('oxdelcost', $aPositions) !== false))) {
- $sDelDesc = __('Surcharge').' '.__('Shipping Costs');// default description
- if ($oOrder->getBaseShippingInclTax() < 0) {// negative shipping cost
- $sDelDesc = __('Deduction').' '.__('Shipping Costs');// change item description to deduction
+ $sDelDesc = __('Surcharge').' '.__('Shipping Costs'); // default description
+ if ($oOrder->getBaseShippingInclTax() < 0) { // negative shipping cost
+ $sDelDesc = __('Deduction').' '.__('Shipping Costs'); // change item description to deduction
}
- $sShippingSku = $this->toolkitHelper->getConfigParam('sku', 'costs', 'payone_misc');// get configured shipping SKU
- $this->addInvoicePosition($sShippingSku, $oOrder->getBaseShippingInclTax(), 'shipment', 1, $sDelDesc, $this->dTax);
+ $sShippingSku = $this->toolkitHelper->getConfigParam('sku', 'costs', 'payone_misc'); // get configured shipping SKU
+ $this->addInvoicePosition($sShippingSku, $oOrder->getBaseShippingInclTax(), 'shipment', 1, $sDelDesc, $this->dTax); // add invoice params to request
}
}
@@ -196,20 +195,20 @@ protected function addDiscountItem(Order $oOrder, $aPositions, $blDebit)
{
// discount costs existing or given for partial captures/debis?
if ($oOrder->getBaseDiscountAmount() != 0 && $oOrder->getCouponCode() && ($aPositions === false || ($blDebit === false || array_key_exists('oxvoucherdiscount', $aPositions) !== false))) {
- $dDiscount = $this->toolkitHelper->formatNumber($oOrder->getBaseDiscountAmount());
+ $dDiscount = $this->toolkitHelper->formatNumber($oOrder->getBaseDiscountAmount()); // format discount
if ($aPositions === false) {// full invoice?
// The calculations broken down to single items of Magento2 are unprecise and the Payone API will send an error if
// the calculated positions don't match, so we compensate for rounding-problems here
- $dDiff = ($this->dAmount + $oOrder->getBaseDiscountAmount()) - $oOrder->getGrandTotal();// calc rounding discrepancy
- $dDiscount -= $dDiff;// subtract difference from discount
+ $dDiff = ($this->dAmount + $oOrder->getBaseDiscountAmount()) - $oOrder->getGrandTotal(); // calc rounding discrepancy
+ $dDiscount -= $dDiff; // subtract difference from discount
}
- $sDiscountSku = $this->toolkitHelper->getConfigParam('sku', 'discount', 'payone_misc');// get configured discount SKU
- $sDesc = (string)__('Discount');// default description
+ $sDiscountSku = $this->toolkitHelper->getConfigParam('sku', 'discount', 'payone_misc'); // get configured discount SKU
+ $sDesc = (string)__('Discount'); // default description
if ($oOrder->getCouponCode()) {// was a coupon code used?
- $sDiscountSku = $this->toolkitHelper->getConfigParam('sku', 'voucher', 'payone_misc');// get configured voucher SKU
- $sDesc = (string)__('Coupon').' - '.$oOrder->getCouponCode();// add counpon code to description
+ $sDiscountSku = $this->toolkitHelper->getConfigParam('sku', 'voucher', 'payone_misc'); // get configured voucher SKU
+ $sDesc = (string)__('Coupon').' - '.$oOrder->getCouponCode(); // add counpon code to description
}
- $this->addInvoicePosition($sDiscountSku, $dDiscount, 'voucher', 1, $sDesc, $this->dTax);// add invoice params to request
+ $this->addInvoicePosition($sDiscountSku, $dDiscount, 'voucher', 1, $sDesc, $this->dTax); // add invoice params to request
}
}
}
diff --git a/Model/Api/Request/AddressRequest.php b/Model/Api/Request/AddressRequest.php
index be0a2467..ad5fd340 100644
--- a/Model/Api/Request/AddressRequest.php
+++ b/Model/Api/Request/AddressRequest.php
@@ -48,12 +48,11 @@ abstract class AddressRequest extends Base
/**
* Constructor
*
- * @param \Payone\Core\Helper\Shop $shopHelper
- * @param \Payone\Core\Helper\Environment $environmentHelper
- * @param \Payone\Core\Helper\Api $apiHelper
- * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
- * @param \Payone\Core\Helper\Customer $customerHelper
- * @return void
+ * @param \Payone\Core\Helper\Shop $shopHelper
+ * @param \Payone\Core\Helper\Environment $environmentHelper
+ * @param \Payone\Core\Helper\Api $apiHelper
+ * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
+ * @param \Payone\Core\Helper\Customer $customerHelper
*/
public function __construct(
\Payone\Core\Helper\Shop $shopHelper,
@@ -77,7 +76,7 @@ protected function addAddress($oAddress, $blIsShipping = false)
{
$sPre = '';
if ($blIsShipping === true) {
- $sPre = 'shipping_';// add shipping prefix for shipping addresses
+ $sPre = 'shipping_'; // add shipping prefix for shipping addresses
}
$this->addParameter($sPre.'firstname', $oAddress->getFirstname());
$this->addParameter($sPre.'lastname', $oAddress->getLastname());
@@ -86,7 +85,7 @@ protected function addAddress($oAddress, $blIsShipping = false)
}
$aStreet = $oAddress->getStreet();
- $sStreet = is_array($aStreet) ? implode(' ', $aStreet) : $aStreet;// street may be an array
+ $sStreet = is_array($aStreet) ? implode(' ', $aStreet) : $aStreet; // street may be an array
$this->addParameter($sPre.'street', trim($sStreet));
$this->addParameter($sPre.'zip', $oAddress->getPostcode());
$this->addParameter($sPre.'city', $oAddress->getCity());
diff --git a/Model/Api/Request/Addresscheck.php b/Model/Api/Request/Addresscheck.php
new file mode 100644
index 00000000..1c4a8834
--- /dev/null
+++ b/Model/Api/Request/Addresscheck.php
@@ -0,0 +1,182 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Model\Api\Request;
+
+use Locale;
+
+/**
+ * Class for the PAYONE Server API request "addresscheck"
+ */
+class Addresscheck extends AddressRequest
+{
+ /*
+ * Array of valid countries for addresscheck basic
+ *
+ * @var array
+ */
+ protected $aValidCountrys = [
+ 'BE',
+ 'DK',
+ 'DE',
+ 'FI',
+ 'FR',
+ 'IT',
+ 'CA',
+ 'LU',
+ 'NL',
+ 'NO',
+ 'AT',
+ 'PL',
+ 'PT',
+ 'SE',
+ 'CH',
+ 'SK',
+ 'ES',
+ 'CZ',
+ 'HU',
+ 'US',
+ ];
+
+ /**
+ * Checked addresses resource model
+ *
+ * @var \Payone\Core\Model\ResourceModel\CheckedAddresses
+ */
+ protected $addressesChecked;
+
+ /**
+ * Constructor
+ *
+ * @param \Payone\Core\Helper\Shop $shopHelper
+ * @param \Payone\Core\Helper\Environment $environmentHelper
+ * @param \Payone\Core\Helper\Api $apiHelper
+ * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
+ * @param \Payone\Core\Helper\Customer $customerHelper
+ * @param \Payone\Core\Model\ResourceModel\CheckedAddresses $addressesChecked
+ */
+ public function __construct(
+ \Payone\Core\Helper\Shop $shopHelper,
+ \Payone\Core\Helper\Environment $environmentHelper,
+ \Payone\Core\Helper\Api $apiHelper,
+ \Payone\Core\Model\ResourceModel\ApiLog $apiLog,
+ \Payone\Core\Helper\Customer $customerHelper,
+ \Payone\Core\Model\ResourceModel\CheckedAddresses $addressesChecked
+ ) {
+ parent::__construct($shopHelper, $environmentHelper, $apiHelper, $apiLog, $customerHelper);
+ $this->addressesChecked = $addressesChecked;
+ }
+
+ /**
+ * Get addresscheck type
+ *
+ * @param bool $blIsBillingAddress
+ * @return string
+ */
+ protected function getAddresscheckType($blIsBillingAddress)
+ {
+ $sConfigField = 'check_billing';
+ if ($blIsBillingAddress === false) {
+ $sConfigField = 'check_shipping';
+ }
+ return $this->shopHelper->getConfigParam($sConfigField, 'address_check', 'payone_protect');
+ }
+
+ /**
+ * Check if the addresscheck is available for the given check-type and address-country
+ *
+ * @param string $sAddresscheckType
+ * @param \Magento\Quote\Api\Data\AddressInterface $oAddress
+ * @return bool
+ */
+ protected function validateTypeToCountry($sAddresscheckType, \Magento\Quote\Api\Data\AddressInterface $oAddress)
+ {
+ if ($sAddresscheckType == 'PE' && $oAddress->getCountryId() != 'DE') {
+ //AddressCheck Person only available for germany
+ return false;
+ }
+ if ($sAddresscheckType == 'BA' && array_search($oAddress->getCountryId(), $this->aValidCountrys) === false) {
+ //AddressCheck Basic only available for certain countries
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Check enabled status
+ *
+ * @param bool $blIsBillingAddress
+ * @return bool
+ */
+ protected function isCheckEnabled($blIsBillingAddress)
+ {
+ if (!$this->shopHelper->getConfigParam('enabled', 'address_check', 'payone_protect')) {
+ return false; // address check was disabled
+ }
+ if ($blIsBillingAddress && $this->shopHelper->getConfigParam('check_billing', 'address_check', 'payone_protect') == 'NO') {
+ return false; // address check was disabled for the billing address
+ }
+ if (!$blIsBillingAddress && $this->shopHelper->getConfigParam('check_shipping', 'address_check', 'payone_protect') == 'NO') {
+ return false; // address check was disabled for the shipping address
+ }
+ return true;
+ }
+
+ /**
+ * Send request "addresscheck" to PAYONE server API
+ *
+ * @param \Magento\Quote\Api\Data\AddressInterface $oAddress
+ * @param bool $blIsBillingAddress
+ * @return array|bool
+ */
+ public function sendRequest(\Magento\Quote\Api\Data\AddressInterface $oAddress, $blIsBillingAddress = false)
+ {
+ if (!$this->isCheckEnabled($blIsBillingAddress)) { // check not needed because of configuration
+ return true;
+ }
+
+ $sType = $this->getAddresscheckType($blIsBillingAddress);
+ if (!$this->validateTypeToCountry($sType, $oAddress)) {
+ return ['wrongCountry' => true]; //Simulate successful check
+ }
+
+ $this->addParameter('request', 'addresscheck');
+ $this->addParameter('mode', $this->shopHelper->getConfigParam('mode', 'address_check', 'payone_protect')); //Operationmode live or test
+ $this->addParameter('aid', $this->shopHelper->getConfigParam('aid')); //ID of PayOne Sub-Account
+ $this->addParameter('addresschecktype', $sType);
+ $this->addParameter('language', Locale::getPrimaryLanguage(Locale::getDefault()));
+ $this->addAddress($oAddress);
+
+ if ($this->addressesChecked->wasAddressCheckedBefore($oAddress) === false) {
+ $aResponse = $this->send();
+ if ($aResponse['status'] == 'VALID') {
+ $this->addressesChecked->addCheckedAddress($oAddress, $aResponse);
+ }
+ return $aResponse;
+ }
+ return true;
+ }
+}
diff --git a/Model/Api/Request/Authorization.php b/Model/Api/Request/Authorization.php
index d4e40c21..119688c3 100644
--- a/Model/Api/Request/Authorization.php
+++ b/Model/Api/Request/Authorization.php
@@ -79,15 +79,14 @@ class Authorization extends AddressRequest
/**
* Constructor
*
- * @param \Payone\Core\Helper\Shop $shopHelper
- * @param \Payone\Core\Helper\Environment $environmentHelper
- * @param \Payone\Core\Helper\Api $apiHelper
- * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
- * @param \Payone\Core\Helper\Customer $customerHelper
- * @param \Payone\Core\Model\Api\Invoice $invoiceGenerator
- * @param \Magento\Checkout\Model\Session $checkoutSession
- * @param \Payone\Core\Helper\Toolkit $toolkitHelper
- * @return void
+ * @param \Payone\Core\Helper\Shop $shopHelper
+ * @param \Payone\Core\Helper\Environment $environmentHelper
+ * @param \Payone\Core\Helper\Api $apiHelper
+ * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
+ * @param \Payone\Core\Helper\Customer $customerHelper
+ * @param \Payone\Core\Model\Api\Invoice $invoiceGenerator
+ * @param \Magento\Checkout\Model\Session $checkoutSession
+ * @param \Payone\Core\Helper\Toolkit $toolkitHelper
*/
public function __construct(
\Payone\Core\Helper\Shop $shopHelper,
@@ -116,20 +115,20 @@ public function __construct(
*/
public function sendRequest(PayoneMethod $oPayment, Order $oOrder, $dAmount)
{
- $this->setOrderId($oOrder->getRealOrderId());// save order id to object for later use
+ $this->setOrderId($oOrder->getRealOrderId()); // save order id to object for later use
- $this->addParameter('request', $oPayment->getAuthorizationMode());// add request type
- $this->addParameter('mode', $oPayment->getOperationMode());// add mode ( live or test )
- $this->addParameter('customerid', $oOrder->getCustomerId());// add customer id
- $this->addParameter('aid', $this->shopHelper->getConfigParam('aid'));// add sub account id
- $this->setAuthorizationParameters($oPayment, $oOrder, $dAmount);// set authorization params
+ $this->addParameter('request', $oPayment->getAuthorizationMode()); // add request type
+ $this->addParameter('mode', $oPayment->getOperationMode()); // add mode ( live or test )
+ $this->addParameter('customerid', $oOrder->getCustomerId()); // add customer id
+ $this->addParameter('aid', $this->shopHelper->getConfigParam('aid')); // add sub account id
+ $this->setAuthorizationParameters($oPayment, $oOrder, $dAmount); // set authorization params
if ($oPayment->hasCustomConfig()) {// if payment type doesnt use the global settings
- $this->addCustomParameters($oPayment);// add custom connection settings
+ $this->addCustomParameters($oPayment); // add custom connection settings
}
- $aResponse = $this->send();// send request to PAYONE Server API
+ $aResponse = $this->send(); // send request to PAYONE Server API
- $this->apiHelper->addPayoneOrderData($oOrder, $this->getParameters(), $aResponse);// add payone data to order
+ $this->apiHelper->addPayoneOrderData($oOrder, $this->getParameters(), $aResponse); // add payone data to order
return $aResponse;
}
@@ -143,15 +142,15 @@ public function sendRequest(PayoneMethod $oPayment, Order $oOrder, $dAmount)
*/
protected function setUserParameters(PayoneMethod $oPayment, Order $oOrder)
{
- $oQuote = $this->checkoutSession->getQuote();// get quote from session
- $oCustomer = $oQuote->getCustomer();// get customer object from quote
+ $oQuote = $this->checkoutSession->getQuote(); // get quote from session
+ $oCustomer = $oQuote->getCustomer(); // get customer object from quote
$this->addUserDataParameters($oOrder->getBillingAddress(), $oPayment, $oCustomer->getGender(), $oOrder->getCustomerEmail(), $oCustomer->getDob());
$oShipping = $oOrder->getShippingAddress(); // get shipping address from order
if ($oShipping) {// shipping address existing?
- $this->addAddress($oShipping, true);// add regular shipping address
+ $this->addAddress($oShipping, true); // add regular shipping address
} elseif ($oPayment->getCode() == PayoneConfig::METHOD_PAYPAL && $this->shopHelper->getConfigParam('bill_as_del_address', PayoneConfig::METHOD_PAYPAL, 'payone_payment')) {
- $this->addAddress($oOrder->getBillingAddress(), true);// add billing address as shipping address
+ $this->addAddress($oOrder->getBillingAddress(), true); // add billing address as shipping address
}
}
@@ -165,22 +164,22 @@ protected function setUserParameters(PayoneMethod $oPayment, Order $oOrder)
*/
protected function setAuthorizationParameters(PayoneMethod $oPayment, Order $oOrder, $dAmount)
{
- $sRefNr = $this->shopHelper->getConfigParam('ref_prefix').$oOrder->getIncrementId();// ref_prefix to prevent duplicate refnumbers in testing environments
- $sRefNr = $oPayment->formatReferenceNumber($sRefNr);// some payment methods have refnr regulations
- $this->addParameter('reference', $sRefNr);// add ref-nr to request
- $this->addParameter('amount', number_format($dAmount, 2, '.', '')*100);// add price to request
- $this->addParameter('currency', $oOrder->getOrderCurrencyCode());// add currency to request
+ $sRefNr = $this->shopHelper->getConfigParam('ref_prefix').$oOrder->getIncrementId(); // ref_prefix to prevent duplicate refnumbers in testing environments
+ $sRefNr = $oPayment->formatReferenceNumber($sRefNr); // some payment methods have refnr regulations
+ $this->addParameter('reference', $sRefNr); // add ref-nr to request
+ $this->addParameter('amount', number_format($dAmount, 2, '.', '') * 100); // add price to request
+ $this->addParameter('currency', $oOrder->getOrderCurrencyCode()); // add currency to request
if ($this->shopHelper->getConfigParam('transmit_ip') == '1') {// is IP transmission needed?
- $sIp = $this->environmentHelper->getRemoteIp();// get remote IP
+ $sIp = $this->environmentHelper->getRemoteIp(); // get remote IP
if ($sIp != '') {// is IP not empty
- $this->addParameter('ip', $sIp);// add IP address to the request
+ $this->addParameter('ip', $sIp); // add IP address to the request
}
}
- $this->setUserParameters($oPayment, $oOrder);// add user data - addresses etc.
- $this->setPaymentParameters($oPayment, $oOrder);// add payment specific parameters
+ $this->setUserParameters($oPayment, $oOrder); // add user data - addresses etc.
+ $this->setPaymentParameters($oPayment, $oOrder); // add payment specific parameters
if ($this->apiHelper->isInvoiceDataNeeded($oPayment)) {//
- $this->invoiceGenerator->addProductInfo($this, $oOrder);// add invoice parameters
+ $this->invoiceGenerator->addProductInfo($this, $oOrder); // add invoice parameters
}
}
@@ -193,15 +192,15 @@ protected function setAuthorizationParameters(PayoneMethod $oPayment, Order $oOr
*/
protected function setPaymentParameters(PayoneMethod $oPayment, Order $oOrder)
{
- $this->addParameter('clearingtype', $oPayment->getClearingtype());// add payment type to request
+ $this->addParameter('clearingtype', $oPayment->getClearingtype()); // add payment type to request
$sNarrativeText = $this->toolkitHelper->getNarrativeText($oOrder, $oPayment);
if (!empty($sNarrativeText)) {// narrative text existing?
- $this->addParameter('narrative_text', $sNarrativeText);// add narrative text parameter
+ $this->addParameter('narrative_text', $sNarrativeText); // add narrative text parameter
}
- $aPaymentParams = $oPayment->getPaymentSpecificParameters($oOrder);// get payment params specific to the payment type
- $this->aParameters = array_merge($this->aParameters, $aPaymentParams);// merge payment params with other params
+ $aPaymentParams = $oPayment->getPaymentSpecificParameters($oOrder); // get payment params specific to the payment type
+ $this->aParameters = array_merge($this->aParameters, $aPaymentParams); // merge payment params with other params
if ($oPayment->needsRedirectUrls() === true) {// does the used payment type need redirect urls?
- $this->addRedirectUrls($oPayment);// add needed redirect urls
+ $this->addRedirectUrls($oPayment); // add needed redirect urls
}
}
@@ -214,9 +213,9 @@ protected function setPaymentParameters(PayoneMethod $oPayment, Order $oOrder)
protected function addCustomParameters(PayoneMethod $oPayment)
{
foreach ($this->aCustomParamMap as $sParamName => $sConfigName) {// add all custom parameters
- $sCustomConfig = $oPayment->getCustomConfigParam($sConfigName);// get custom config param
+ $sCustomConfig = $oPayment->getCustomConfigParam($sConfigName); // get custom config param
if (!empty($sCustomConfig)) {// only add if the param is configured
- $this->addParameter($sParamName, $sCustomConfig);// add custom param to request
+ $this->addParameter($sParamName, $sCustomConfig); // add custom param to request
}
}
}
diff --git a/Model/Api/Request/Base.php b/Model/Api/Request/Base.php
index 4d654431..351eefa7 100644
--- a/Model/Api/Request/Base.php
+++ b/Model/Api/Request/Base.php
@@ -93,11 +93,10 @@ abstract class Base
/**
* Constructor
*
- * @param \Payone\Core\Helper\Shop $shopHelper
- * @param \Payone\Core\Helper\Environment $environmentHelper
- * @param \Payone\Core\Helper\Api $apiHelper
- * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
- * @return void
+ * @param \Payone\Core\Helper\Shop $shopHelper
+ * @param \Payone\Core\Helper\Environment $environmentHelper
+ * @param \Payone\Core\Helper\Api $apiHelper
+ * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
*/
public function __construct(
\Payone\Core\Helper\Shop $shopHelper,
@@ -120,14 +119,14 @@ public function __construct(
*/
protected function initRequest()
{
- $this->addParameter('mid', $this->shopHelper->getConfigParam('mid'));// PayOne Merchant ID
- $this->addParameter('portalid', $this->shopHelper->getConfigParam('portalid'));// PayOne Portal ID
- $this->addParameter('key', md5($this->shopHelper->getConfigParam('key')));// PayOne Portal Key
- $this->addParameter('encoding', $this->environmentHelper->getEncoding());// Encoding
- $this->addParameter('integrator_name', 'Magento2');// Shop-system
- $this->addParameter('integrator_version', $this->shopHelper->getMagentoVersion());// Shop version
- $this->addParameter('solution_name', 'fatchip');// Company developing the module
- $this->addParameter('solution_version', PayoneConfig::MODULE_VERSION);// Module version
+ $this->addParameter('mid', $this->shopHelper->getConfigParam('mid')); // PayOne Merchant ID
+ $this->addParameter('portalid', $this->shopHelper->getConfigParam('portalid')); // PayOne Portal ID
+ $this->addParameter('key', md5($this->shopHelper->getConfigParam('key'))); // PayOne Portal Key
+ $this->addParameter('encoding', $this->environmentHelper->getEncoding()); // Encoding
+ $this->addParameter('integrator_name', 'Magento2'); // Shop-system
+ $this->addParameter('integrator_version', $this->shopHelper->getMagentoVersion()); // Shop version
+ $this->addParameter('solution_name', 'fatchip'); // Company developing the module
+ $this->addParameter('solution_version', PayoneConfig::MODULE_VERSION); // Module version
}
/**
@@ -141,7 +140,7 @@ protected function initRequest()
public function addParameter($sKey, $sValue, $blAddAsNullIfEmpty = false)
{
if ($blAddAsNullIfEmpty === true && empty($sValue)) {
- $sValue = 'NULL';// add value as string NULL - needed in certain situations
+ $sValue = 'NULL'; // add value as string NULL - needed in certain situations
}
$this->aParameters[$sKey] = $sValue;
}
@@ -243,16 +242,16 @@ protected function validateParameters()
protected function send($blOnlyGetUrl = false)
{
if (!$this->validateParameters()) {// all base parameters existing?
- $aResponse['errormessage'] = "Payone API Setup Data not complete (API-URL, MID, AID, PortalID, Key, Mode)";
- return $aResponse;
+ return ["errormessage" => "Payone API Setup Data not complete (API-URL, MID, AID, PortalID, Key, Mode)"];
}
+
$sRequestUrl = $this->apiHelper->getRequestUrl($this->getParameters(), $this->sApiUrl);
if ($blOnlyGetUrl === true) {// sometimes you only need the request url
return $sRequestUrl;
}
- $aResponse = $this->apiHelper->sendApiRequest($sRequestUrl);// send request to PAYONE
- $this->apiLog->addApiLogEntry($this, $aResponse, $aResponse['status']);// log request to db
+ $aResponse = $this->apiHelper->sendApiRequest($sRequestUrl); // send request to PAYONE
+ $this->apiLog->addApiLogEntry($this, $aResponse, $aResponse['status']); // log request to db
return $aResponse;
}
}
diff --git a/Model/Api/Request/Capture.php b/Model/Api/Request/Capture.php
index 304bf787..5ce677db 100644
--- a/Model/Api/Request/Capture.php
+++ b/Model/Api/Request/Capture.php
@@ -45,12 +45,11 @@ class Capture extends Base
/**
* Constructor
*
- * @param \Payone\Core\Helper\Shop $shopHelper
- * @param \Payone\Core\Helper\Environment $environmentHelper
- * @param \Payone\Core\Helper\Api $apiHelper
- * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
- * @param \Payone\Core\Helper\Database $databaseHelper
- * @return void
+ * @param \Payone\Core\Helper\Shop $shopHelper
+ * @param \Payone\Core\Helper\Environment $environmentHelper
+ * @param \Payone\Core\Helper\Api $apiHelper
+ * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
+ * @param \Payone\Core\Helper\Database $databaseHelper
*/
public function __construct(
\Payone\Core\Helper\Shop $shopHelper,
@@ -79,12 +78,12 @@ public function sendRequest(PayoneMethod $oPayment, InfoInterface $oPaymentInfo,
$this->setOrderId($oOrder->getRealOrderId());
$this->addParameter('request', 'capture'); // Request method
- $this->addParameter('mode', $oPayment->getOperationMode());// PayOne Portal Operation Mode (live or test)
+ $this->addParameter('mode', $oPayment->getOperationMode()); // PayOne Portal Operation Mode (live or test)
$this->addParameter('language', Locale::getPrimaryLanguage(Locale::getDefault()));
// Total order sum in smallest currency unit
- $this->addParameter('amount', number_format($dAmount, 2, '.', '')*100);
- $this->addParameter('currency', $oOrder->getOrderCurrencyCode());// Currency
+ $this->addParameter('amount', number_format($dAmount, 2, '.', '') * 100);
+ $this->addParameter('currency', $oOrder->getOrderCurrencyCode()); // Currency
$this->addParameter('txid', $iTxid); // PayOne Transaction ID
$this->addParameter('sequencenumber', $this->databaseHelper->getSequenceNumber($iTxid));
diff --git a/Model/Api/Request/Consumerscore.php b/Model/Api/Request/Consumerscore.php
new file mode 100644
index 00000000..22417175
--- /dev/null
+++ b/Model/Api/Request/Consumerscore.php
@@ -0,0 +1,110 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Model\Api\Request;
+
+use Locale;
+use Magento\Quote\Api\Data\AddressInterface;
+
+/**
+ * Class for the PAYONE Server API request "consumerscore"
+ */
+class Consumerscore extends AddressRequest
+{
+
+ /**
+ * Object of CheckedAddresses resource
+ *
+ * @var \Payone\Core\Model\ResourceModel\CheckedAddresses
+ */
+ protected $addressesChecked;
+
+ /**
+ * Constructor
+ *
+ * @param \Payone\Core\Helper\Shop $shopHelper
+ * @param \Payone\Core\Helper\Environment $environmentHelper
+ * @param \Payone\Core\Helper\Api $apiHelper
+ * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
+ * @param \Payone\Core\Helper\Customer $customerHelper
+ * @param \Payone\Core\Model\ResourceModel\CheckedAddresses $addressesChecked
+ */
+ public function __construct(
+ \Payone\Core\Helper\Shop $shopHelper,
+ \Payone\Core\Helper\Environment $environmentHelper,
+ \Payone\Core\Helper\Api $apiHelper,
+ \Payone\Core\Model\ResourceModel\ApiLog $apiLog,
+ \Payone\Core\Helper\Customer $customerHelper,
+ \Payone\Core\Model\ResourceModel\CheckedAddresses $addressesChecked
+ ) {
+ parent::__construct($shopHelper, $environmentHelper, $apiHelper, $apiLog, $customerHelper);
+ $this->addressesChecked = $addressesChecked;
+ }
+
+ /**
+ * Check enabled status
+ *
+ * @return bool
+ */
+ protected function isCheckEnabled()
+ {
+ if (!$this->shopHelper->getConfigParam('enabled', 'creditrating', 'payone_protect')) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Send request "addresscheck" to PAYONE server API
+ *
+ * @param AddressInterface $oAddress
+ * @return array|bool
+ */
+ public function sendRequest(AddressInterface $oAddress)
+ {
+ if (!$this->isCheckEnabled() || $oAddress->getCountryId() != 'DE') {
+ return true;
+ }
+
+ $this->addParameter('request', 'consumerscore');
+ $this->addParameter('mode', $this->shopHelper->getConfigParam('mode', 'creditrating', 'payone_protect')); //Operationmode live or test
+ $this->addParameter('aid', $this->shopHelper->getConfigParam('aid')); //ID of PayOne Sub-Account
+ $this->addParameter('addresschecktype', $this->shopHelper->getConfigParam('addresscheck', 'creditrating', 'payone_protect'));
+ $this->addParameter('consumerscoretype', $this->shopHelper->getConfigParam('type', 'creditrating', 'payone_protect'));
+ $this->addParameter('language', Locale::getPrimaryLanguage(Locale::getDefault()));
+
+ $this->addAddress($oAddress);
+ if ($this->addressesChecked->wasAddressCheckedBefore($oAddress, true) === false) {
+ $aResponse = $this->send();
+ if ($aResponse['status'] == 'VALID') {
+ $this->addressesChecked->addCheckedAddress($oAddress, $aResponse, true);
+ }
+
+ return $aResponse;
+ }
+ return true;
+ }
+}
diff --git a/Model/Api/Request/Debit.php b/Model/Api/Request/Debit.php
index 891b4435..127ba34c 100644
--- a/Model/Api/Request/Debit.php
+++ b/Model/Api/Request/Debit.php
@@ -52,13 +52,12 @@ class Debit extends Base
/**
* Constructor
*
- * @param \Payone\Core\Helper\Shop $shopHelper
- * @param \Payone\Core\Helper\Environment $environmentHelper
- * @param \Payone\Core\Helper\Api $apiHelper
- * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
- * @param \Payone\Core\Helper\Database $databaseHelper
- * @param \Payone\Core\Helper\Toolkit $toolkitHelper
- * @return void
+ * @param \Payone\Core\Helper\Shop $shopHelper
+ * @param \Payone\Core\Helper\Environment $environmentHelper
+ * @param \Payone\Core\Helper\Api $apiHelper
+ * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
+ * @param \Payone\Core\Helper\Database $databaseHelper
+ * @param \Payone\Core\Helper\Toolkit $toolkitHelper
*/
public function __construct(
\Payone\Core\Helper\Shop $shopHelper,
@@ -86,19 +85,19 @@ public function sendRequest(PayoneMethod $oPayment, InfoInterface $oPaymentInfo,
$oOrder = $oPaymentInfo->getOrder();
$iTxid = $oPaymentInfo->getParentTransactionId();
if (strpos($iTxid, '-') !== false) {
- $iTxid = substr($iTxid, 0, strpos($iTxid, '-'));// clean the txid from the magento-suffixes
+ $iTxid = substr($iTxid, 0, strpos($iTxid, '-')); // clean the txid from the magento-suffixes
}
$this->setOrderId($oOrder->getRealOrderId());
$this->addParameter('request', 'debit'); // Request method
- $this->addParameter('mode', $oPayment->getOperationMode());// PayOne Portal Operation Mode (live or test)
+ $this->addParameter('mode', $oPayment->getOperationMode()); // PayOne Portal Operation Mode (live or test)
$this->addParameter('txid', $iTxid); // PayOne Transaction ID
$this->addParameter('sequencenumber', $this->databaseHelper->getSequenceNumber($iTxid));
// Total order sum in smallest currency unit
- $this->addParameter('amount', number_format((-1 * $dAmount), 2, '.', '')*100);
- $this->addParameter('currency', $oOrder->getOrderCurrencyCode());// Currency
+ $this->addParameter('amount', number_format((-1 * $dAmount), 2, '.', '') * 100);
+ $this->addParameter('currency', $oOrder->getOrderCurrencyCode()); // Currency
$this->addParameter('transactiontype', 'GT');
$sRefundAppendix = $this->getRefundAppendix($oOrder, $oPayment);
diff --git a/Model/Api/Request/Genericpayment/PayPalExpress.php b/Model/Api/Request/Genericpayment/PayPalExpress.php
index e53f81d9..8cc1d81e 100644
--- a/Model/Api/Request/Genericpayment/PayPalExpress.php
+++ b/Model/Api/Request/Genericpayment/PayPalExpress.php
@@ -48,10 +48,10 @@ public function sendRequest(Quote $oQuote, Paypal $oPayment, $sWorkorderId = fal
{
$this->addParameter('request', 'genericpayment');
$this->addParameter('mode', $oPayment->getOperationMode());
- $this->addParameter('aid', $this->shopHelper->getConfigParam('aid'));// ID of PayOne Sub-Account
+ $this->addParameter('aid', $this->shopHelper->getConfigParam('aid')); // ID of PayOne Sub-Account
$this->addParameter('clearingtype', 'wlt');
$this->addParameter('wallettype', 'PPE');
- $this->addParameter('amount', number_format($oQuote->getGrandTotal(), 2, '.', '')*100);
+ $this->addParameter('amount', number_format($oQuote->getGrandTotal(), 2, '.', '') * 100);
$this->addParameter('currency', $oQuote->getQuoteCurrencyCode());
$this->addParameter('narrative_text', 'Test');
diff --git a/Model/Api/Request/Getfile.php b/Model/Api/Request/Getfile.php
index 0209da29..cebdfa79 100644
--- a/Model/Api/Request/Getfile.php
+++ b/Model/Api/Request/Getfile.php
@@ -43,7 +43,7 @@ public function sendRequest(Order $oOrder)
{
$sReturn = false;
$sStatus = 'ERROR';
- $sResponse = '';
+ $aResponse = [];
$this->addParameter('request', 'getfile'); // Request method
$this->addParameter('file_reference', $oOrder->getPayoneMandateId());
@@ -65,14 +65,15 @@ public function sendRequest(Order $oOrder)
'content' => http_build_query($this->aParameters),
],
];
- $oContext = stream_context_create($aOptions);
+ $oContext = stream_context_create($aOptions);
$sMandate = file_get_contents($this->sApiUrl, false, $oContext);
if ($sMandate !== false) {
$sReturn = $sMandate;
$sStatus = 'SUCCESS';
- $sResponse = serialize(['file' => $oOrder->getPayoneMandateId().'.pdf']);
+ $aResponse['file'] = $oOrder->getPayoneMandateId().'.pdf';
}
+ $this->apiLog->addApiLogEntry($this, $aResponse, $sStatus); // log request to db
return $sReturn;
}
}
diff --git a/Model/Api/Request/Managemandate.php b/Model/Api/Request/Managemandate.php
index 972b0b26..9fedf4dc 100644
--- a/Model/Api/Request/Managemandate.php
+++ b/Model/Api/Request/Managemandate.php
@@ -45,13 +45,12 @@ class Managemandate extends AddressRequest
/**
* Constructor
*
- * @param \Payone\Core\Helper\Shop $shopHelper
- * @param \Payone\Core\Helper\Environment $environmentHelper
- * @param \Payone\Core\Helper\Api $apiHelper
- * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
- * @param \Payone\Core\Helper\Customer $customerHelper
- * @param \Payone\Core\Helper\Database $databaseHelper
- * @return void
+ * @param \Payone\Core\Helper\Shop $shopHelper
+ * @param \Payone\Core\Helper\Environment $environmentHelper
+ * @param \Payone\Core\Helper\Api $apiHelper
+ * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
+ * @param \Payone\Core\Helper\Customer $customerHelper
+ * @param \Payone\Core\Helper\Database $databaseHelper
*/
public function __construct(
\Payone\Core\Helper\Shop $shopHelper,
@@ -77,8 +76,8 @@ public function sendRequest(PayoneMethod $oPayment, Quote $oQuote)
$oCustomer = $oQuote->getCustomer();
$this->addParameter('request', 'managemandate'); // Request method
- $this->addParameter('mode', $oPayment->getOperationMode());// PayOne Portal Operation Mode (live or test)
- $this->addParameter('aid', $this->shopHelper->getConfigParam('aid'));// ID of PayOne Sub-Account
+ $this->addParameter('mode', $oPayment->getOperationMode()); // PayOne Portal Operation Mode (live or test)
+ $this->addParameter('aid', $this->shopHelper->getConfigParam('aid')); // ID of PayOne Sub-Account
$this->addParameter('clearingtype', 'elv');
$this->addParameter('customerid', $oCustomer->getId());
diff --git a/Model/ChecksumCheck.php b/Model/ChecksumCheck.php
index 6fb442db..bdc17d69 100644
--- a/Model/ChecksumCheck.php
+++ b/Model/ChecksumCheck.php
@@ -111,11 +111,11 @@ protected function getFilesToCheck()
if (file_exists($this->getBasePath().'composer.json')) {// does composer.json exist here?
$this->handleComposerJson($this->getBasePath().'composer.json'); // Read module information from the composer.json
}
- if ($this->blGotModuleInfo === true) {// was composer.json readable?
+ if ($this->blGotModuleInfo === true) { // was composer.json readable?
$sRequestUrl = $this->sVersionCheckUrl.'?module='.$this->sModuleId.'&version='.$this->sModuleVersion;
- $sResponse = file_get_contents($sRequestUrl);// request info from fatchip checksum server
+ $sResponse = file_get_contents($sRequestUrl); // request info from fatchip checksum server
if (!empty($sResponse)) {// Did the server answer?
- $aFiles = json_decode($sResponse);// Decode the json encoded answer from the server
+ $aFiles = json_decode($sResponse); // Decode the json encoded answer from the server
}
}
return $aFiles;
@@ -167,7 +167,6 @@ protected function getCheckResults($aChecksums)
/**
* Main method executing checksum check
*
- * @param bool $blOutput
* @return string
*/
public function checkChecksumXml()
diff --git a/Model/Config/Export.php b/Model/Config/Export.php
index b239d73c..1fcbf769 100644
--- a/Model/Config/Export.php
+++ b/Model/Config/Export.php
@@ -26,7 +26,7 @@
namespace Payone\Core\Model\Config;
-use Magento\Store\Model\Store;
+use Magento\Store\Api\Data\StoreInterface;
/**
* Generator class for the config export
@@ -68,28 +68,37 @@ class Export extends \Payone\Core\Model\Export\Xml
*/
protected $paymentHelper;
+ /**
+ * PAYONE addresscheck model
+ *
+ * @var \Payone\Core\Model\Risk\Addresscheck
+ */
+ protected $addresscheck;
+
/**
* Constructor
*
- * @param \Payone\Core\Helper\ConfigExport $configExportHelper
- * @param \Payone\Core\Model\ChecksumCheck $checksumCheck
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
- * @param \Payone\Core\Helper\Payment $paymentHelper
- * @param \Payone\Core\Helper\Shop $shopHelper
- * @return void
+ * @param \Payone\Core\Helper\ConfigExport $configExportHelper
+ * @param \Payone\Core\Model\ChecksumCheck $checksumCheck
+ * @param \Magento\Store\Model\StoreManagerInterface $storeManager
+ * @param \Payone\Core\Helper\Payment $paymentHelper
+ * @param \Payone\Core\Helper\Shop $shopHelper
+ * @param \Payone\Core\Model\Risk\Addresscheck $addresscheck
*/
public function __construct(
\Payone\Core\Helper\ConfigExport $configExportHelper,
\Payone\Core\Model\ChecksumCheck $checksumCheck,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Payone\Core\Helper\Payment $paymentHelper,
- \Payone\Core\Helper\Shop $shopHelper
+ \Payone\Core\Helper\Shop $shopHelper,
+ \Payone\Core\Model\Risk\Addresscheck $addresscheck
) {
parent::__construct($shopHelper);
$this->configExportHelper = $configExportHelper;
$this->checksumCheck = $checksumCheck;
$this->storeManager = $storeManager;
$this->paymentHelper = $paymentHelper;
+ $this->addresscheck = $addresscheck;
}
/**
@@ -183,6 +192,64 @@ protected function addShopClearingtypeConfig($sStoreCode)
$this->writeToXml('', 2);
}
+ /**
+ * Add addresscheck config to xml
+ *
+ * @param string $sStoreCode
+ * @return void
+ */
+ protected function addAddresscheckConfig($sStoreCode)
+ {
+ $this->writeToXml('', 3);
+ $this->writeNode("active", $this->configExportHelper->getConfigParam('enabled', 'address_check', 'payone_protect', $sStoreCode), 4);
+ $this->writeNode("mode", $this->configExportHelper->getConfigParam('mode', 'address_check', 'payone_protect', $sStoreCode), 4);
+ $this->writeNode("min_order_total", $this->configExportHelper->getConfigParam('min_order_total', 'address_check', 'payone_protect', $sStoreCode), 4);
+ $this->writeNode("max_order_total", $this->configExportHelper->getConfigParam('max_order_total', 'address_check', 'payone_protect', $sStoreCode), 4);
+ $this->writeNode("checkbilling", $this->configExportHelper->getConfigParam('check_billing', 'address_check', 'payone_protect', $sStoreCode), 4);
+ $this->writeNode("checkshipping", $this->configExportHelper->getConfigParam('check_shipping', 'address_check', 'payone_protect', $sStoreCode), 4);
+ $this->writeToXml('', 4);
+ $aMapping = $this->addresscheck->getPersonstatusMapping();
+ foreach ($aMapping as $sPersonstatus => $sScore) {
+ $this->writeNode($sPersonstatus, $sScore, 5);
+ }
+ $this->writeToXml('', 4);
+ $this->writeToXml('', 3);
+ }
+
+ /**
+ * Add consumerscore config to xml
+ *
+ * @param string $sStoreCode
+ * @return void
+ */
+ protected function addConsumerscore($sStoreCode)
+ {
+ $this->writeToXml('', 3);
+ $this->writeNode("active", $this->configExportHelper->getConfigParam('enabled', 'creditrating', 'payone_protect', $sStoreCode), 4);
+ $this->writeNode("mode", $this->configExportHelper->getConfigParam('mode', 'creditrating', 'payone_protect', $sStoreCode), 4);
+ $this->writeNode("min_order_total", $this->configExportHelper->getConfigParam('min_order_total', 'creditrating', 'payone_protect', $sStoreCode), 4);
+ $this->writeNode("max_order_total", $this->configExportHelper->getConfigParam('max_order_total', 'creditrating', 'payone_protect', $sStoreCode), 4);
+ $this->writeNode("consumerscoretype", $this->configExportHelper->getConfigParam('type', 'creditrating', 'payone_protect', $sStoreCode), 4);
+ $this->writeNode("red", $this->configExportHelper->getConfigParam('allow_payment_methods_red', 'creditrating', 'payone_protect', $sStoreCode), 4);
+ $this->writeNode("yellow", $this->configExportHelper->getConfigParam('allow_payment_methods_yellow', 'creditrating', 'payone_protect', $sStoreCode), 4);
+ $this->writeNode("duetime", $this->configExportHelper->getConfigParam('result_lifetime', 'creditrating', 'payone_protect', $sStoreCode), 4);
+ $this->writeToXml('', 3);
+ }
+
+ /**
+ * Add shop protect config to xml
+ *
+ * @param string $sStoreCode
+ * @return void
+ */
+ protected function addProtectConfig($sStoreCode)
+ {
+ $this->writeToXml('', 2);
+ $this->addAddresscheckConfig($sStoreCode);
+ $this->addConsumerscore($sStoreCode);
+ $this->writeToXml('', 2);
+ }
+
/**
* Add shop misc config to xml
*
@@ -206,11 +273,11 @@ protected function addShopMiscConfig($sStoreCode)
/**
* Write single shop config to xml
*
- * @param string $sStoreCode
- * @param Store $oStore
+ * @param string $sStoreCode
+ * @param StoreInterface $oStore
* @return void
*/
- protected function addSingleShopConfig($sStoreCode, Store $oStore)
+ protected function addSingleShopConfig($sStoreCode, StoreInterface $oStore)
{
$this->writeToXml('', 1);
$this->writeNode("code", $sStoreCode, 2);
@@ -218,6 +285,7 @@ protected function addSingleShopConfig($sStoreCode, Store $oStore)
$this->addShopSystemConfig();
$this->addShopGlobalConfig($sStoreCode);
$this->addShopClearingtypeConfig($sStoreCode);
+ $this->addProtectConfig($sStoreCode);
$this->addShopMiscConfig($sStoreCode);
$this->writeToXml('', 1);
}
diff --git a/Model/ConfigProvider.php b/Model/ConfigProvider.php
index c44a3147..ec093dea 100644
--- a/Model/ConfigProvider.php
+++ b/Model/ConfigProvider.php
@@ -84,19 +84,26 @@ class ConfigProvider extends \Magento\Payment\Model\CcGenericConfigProvider
* @var \Magento\Framework\Escaper
*/
protected $escaper;
+
+ /**
+ * PAYONE request helper
+ *
+ * @var \Payone\Core\Helper\Consumerscore
+ */
+ protected $consumerscoreHelper;
/**
* Constructor
*
- * @param \Magento\Payment\Model\CcConfig $ccConfig
- * @param \Magento\Payment\Helper\Data $dataHelper
- * @param \Payone\Core\Helper\Country $countryHelper
- * @param \Payone\Core\Helper\Customer $customerHelper
- * @param \Payone\Core\Helper\Payment $paymentHelper
- * @param \Payone\Core\Helper\HostedIframe $hostedIframeHelper
- * @param \Payone\Core\Helper\Request $requestHelper
- * @param \Magento\Framework\Escaper $escaper
- * @return void
+ * @param \Magento\Payment\Model\CcConfig $ccConfig
+ * @param \Magento\Payment\Helper\Data $dataHelper
+ * @param \Payone\Core\Helper\Country $countryHelper
+ * @param \Payone\Core\Helper\Customer $customerHelper
+ * @param \Payone\Core\Helper\Payment $paymentHelper
+ * @param \Payone\Core\Helper\HostedIframe $hostedIframeHelper
+ * @param \Payone\Core\Helper\Request $requestHelper
+ * @param \Magento\Framework\Escaper $escaper
+ * @param \Payone\Core\Helper\Consumerscore $consumerscoreHelper
*/
public function __construct(
\Magento\Payment\Model\CcConfig $ccConfig,
@@ -106,7 +113,8 @@ public function __construct(
\Payone\Core\Helper\Payment $paymentHelper,
\Payone\Core\Helper\HostedIframe $hostedIframeHelper,
\Payone\Core\Helper\Request $requestHelper,
- \Magento\Framework\Escaper $escaper
+ \Magento\Framework\Escaper $escaper,
+ \Payone\Core\Helper\Consumerscore $consumerscoreHelper
) {
parent::__construct($ccConfig, $dataHelper);
$this->dataHelper = $dataHelper;
@@ -116,6 +124,7 @@ public function __construct(
$this->hostedIframeHelper = $hostedIframeHelper;
$this->requestHelper = $requestHelper;
$this->escaper = $escaper;
+ $this->consumerscoreHelper = $consumerscoreHelper;
}
/**
@@ -159,6 +168,14 @@ public function getConfig()
'idealBankGroups' => Ideal::getBankGroups(),
'customerHasGivenGender' => $this->customerHelper->customerHasGivenGender(),
'customerHasGivenBirthday' => $this->customerHelper->customerHasGivenBirthday(),
+ 'addresscheckEnabled' => (int)$this->requestHelper->getConfigParam('enabled', 'address_check', 'payone_protect'),
+ 'addresscheckBillingEnabled' => $this->requestHelper->getConfigParam('check_billing', 'address_check', 'payone_protect') == 'NO' ? 0 : 1,
+ 'addresscheckShippingEnabled' => $this->requestHelper->getConfigParam('check_shipping', 'address_check', 'payone_protect') == 'NO' ? 0 : 1,
+ 'addresscheckConfirmCorrection' => (int)$this->requestHelper->getConfigParam('confirm_address_correction', 'address_check', 'payone_protect'),
+ 'canShowPaymentHintText' => $this->consumerscoreHelper->canShowPaymentHintText(),
+ 'paymentHintText' => $this->requestHelper->getConfigParam('payment_hint_text', 'creditrating', 'payone_protect'),
+ 'canShowAgreementMessage' => $this->consumerscoreHelper->canShowAgreementMessage(),
+ 'agreementMessage' => $this->requestHelper->getConfigParam('agreement_message', 'creditrating', 'payone_protect'),
],
],
]);
diff --git a/Model/Entities/TransactionStatus.php b/Model/Entities/TransactionStatus.php
index 2b78c01d..43090b15 100644
--- a/Model/Entities/TransactionStatus.php
+++ b/Model/Entities/TransactionStatus.php
@@ -75,7 +75,7 @@ protected function getUnserializedArray($sKey, $blSort = false)
$sRequest = $this->getData($sKey);
if ($sRequest) {
if (Toolkit::isUTF8($sRequest)) {
- $sRequest = utf8_decode($sRequest);// needed for unserializing the array
+ $sRequest = utf8_decode($sRequest); // needed for unserializing the array
}
$aRequest = unserialize($sRequest);
if (is_array($aRequest)) {
diff --git a/Model/Export/Xml.php b/Model/Export/Xml.php
index bbd1f71d..6357fbab 100644
--- a/Model/Export/Xml.php
+++ b/Model/Export/Xml.php
@@ -70,8 +70,6 @@ class Xml
* Constructor
*
* @param \Payone\Core\Helper\Shop $shopHelper
- *
- * @return void
*/
public function __construct(\Payone\Core\Helper\Shop $shopHelper)
{
diff --git a/Model/Methods/BaseMethod.php b/Model/Methods/BaseMethod.php
index bdb846ec..f15ee1eb 100644
--- a/Model/Methods/BaseMethod.php
+++ b/Model/Methods/BaseMethod.php
@@ -195,24 +195,23 @@ abstract class BaseMethod extends \Magento\Payment\Model\Method\AbstractMethod
/**
* Constructor
*
- * @param \Magento\Framework\Model\Context $context
- * @param \Magento\Framework\Registry $registry
- * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
- * @param \Magento\Framework\Api\AttributeValueFactory $customAttrFactory
- * @param \Magento\Payment\Helper\Data $paymentData
- * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
- * @param \Magento\Payment\Model\Method\Logger $logger
- * @param \Payone\Core\Helper\Toolkit $toolkitHelper
- * @param \Payone\Core\Helper\Shop $shopHelper
- * @param \Magento\Framework\Url $url
- * @param \Magento\Checkout\Model\Session $checkoutSession
- * @param \Payone\Core\Model\Api\Request\Debit $debitRequest
- * @param \Payone\Core\Model\Api\Request\Capture $captureRequest
- * @param \Payone\Core\Model\Api\Request\Authorization $authorizationRequest
- * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
- * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
- * @param array $data
- * @return void
+ * @param \Magento\Framework\Model\Context $context
+ * @param \Magento\Framework\Registry $registry
+ * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
+ * @param \Magento\Framework\Api\AttributeValueFactory $customAttrFactory
+ * @param \Magento\Payment\Helper\Data $paymentData
+ * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
+ * @param \Magento\Payment\Model\Method\Logger $logger
+ * @param \Payone\Core\Helper\Toolkit $toolkitHelper
+ * @param \Payone\Core\Helper\Shop $shopHelper
+ * @param \Magento\Framework\Url $url
+ * @param \Magento\Checkout\Model\Session $checkoutSession
+ * @param \Payone\Core\Model\Api\Request\Debit $debitRequest
+ * @param \Payone\Core\Model\Api\Request\Capture $captureRequest
+ * @param \Payone\Core\Model\Api\Request\Authorization $authorizationRequest
+ * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
+ * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
+ * @param array $data
*/
public function __construct(
\Magento\Framework\Model\Context $context,
@@ -250,7 +249,7 @@ public function __construct(
*/
public function getInstructions()
{
- return trim($this->getConfigData('instructions'));// return description text
+ return trim($this->getConfigData('instructions')); // return description text
}
/**
@@ -262,9 +261,9 @@ public function getConfigPaymentAction()
{
$sRequestType = $this->getAuthorizationMode();
if ($sRequestType == PayoneConfig::REQUEST_TYPE_PREAUTHORIZATION) {
- return AbstractMethod::ACTION_AUTHORIZE;// only create order
+ return AbstractMethod::ACTION_AUTHORIZE; // only create order
} elseif ($sRequestType == PayoneConfig::REQUEST_TYPE_AUTHORIZATION) {
- return AbstractMethod::ACTION_AUTHORIZE_CAPTURE;// create order and capture
+ return AbstractMethod::ACTION_AUTHORIZE_CAPTURE; // create order and capture
}
}
@@ -277,9 +276,9 @@ public function getConfigPaymentAction()
*/
public function authorize(InfoInterface $payment, $amount)
{
- $oReturn = parent::authorize($payment, $amount);// execute Magento parent authorization
- $this->sendPayoneAuthorization($payment, $amount);// send auth request to PAYONE
- return $oReturn;// return magento parent auth value
+ $oReturn = parent::authorize($payment, $amount); // execute Magento parent authorization
+ $this->sendPayoneAuthorization($payment, $amount); // send auth request to PAYONE
+ return $oReturn; // return magento parent auth value
}
/**
@@ -291,9 +290,9 @@ public function authorize(InfoInterface $payment, $amount)
*/
public function refund(InfoInterface $payment, $amount)
{
- $oReturn = parent::refund($payment, $amount);// execute Magento parent refund
- $this->sendPayoneDebit($payment, $amount);// send debit request to PAYONE
- return $oReturn;// return magento parent refund value
+ $oReturn = parent::refund($payment, $amount); // execute Magento parent refund
+ $this->sendPayoneDebit($payment, $amount); // send debit request to PAYONE
+ return $oReturn; // return magento parent refund value
}
/**
@@ -305,13 +304,13 @@ public function refund(InfoInterface $payment, $amount)
*/
public function capture(InfoInterface $payment, $amount)
{
- $oReturn = parent::capture($payment, $amount);// execute Magento parent capture
+ $oReturn = parent::capture($payment, $amount); // execute Magento parent capture
if ($payment->getParentTransactionId()) {// does the order already have a transaction?
- $this->sendPayoneCapture($payment, $amount);// is probably admin invoice capture
+ $this->sendPayoneCapture($payment, $amount); // is probably admin invoice capture
} else {
- $this->sendPayoneAuthorization($payment, $amount);// is probably frontend checkout capture
+ $this->sendPayoneAuthorization($payment, $amount); // is probably frontend checkout capture
}
- return $oReturn;// return magento parent capture value
+ return $oReturn; // return magento parent capture value
}
/**
@@ -326,12 +325,12 @@ public function canUseForCountry($country)
$iAllowSpecific = $this->shopHelper->getConfigParam('allowspecific');
$aAvailableCountries = explode(',', $this->shopHelper->getConfigParam('specificcountry'));
if ($this->hasCustomConfig()) {// check for non-global configuration
- $iAllowSpecific = $this->getCustomConfigParam('allowspecific');// only specific countries allowed?
- $aAvailableCountries = explode(',', $this->getCustomConfigParam('specificcountry'));// get allowed countries
+ $iAllowSpecific = $this->getCustomConfigParam('allowspecific'); // only specific countries allowed?
+ $aAvailableCountries = explode(',', $this->getCustomConfigParam('specificcountry')); // get allowed countries
}
if ($iAllowSpecific == 1 && !in_array($country, $aAvailableCountries)) {// only specific but not included
- return false;// cant use for given country
+ return false; // cant use for given country
}
- return true;// can use for given country
+ return true; // can use for given country
}
}
diff --git a/Model/Methods/Klarna.php b/Model/Methods/Klarna.php
index a5dd0269..b9531852 100644
--- a/Model/Methods/Klarna.php
+++ b/Model/Methods/Klarna.php
@@ -116,7 +116,7 @@ public function getPaymentSpecificParameters(Order $oOrder)
* Returns formatted birthday if possible
*
* @param DataObject $data
- * @return string|bool
+ * @return string|false
*/
protected function getFormattedBirthday(DataObject $data)
{
diff --git a/Model/Methods/PayoneMethod.php b/Model/Methods/PayoneMethod.php
index 9c2809a3..7a55a69a 100644
--- a/Model/Methods/PayoneMethod.php
+++ b/Model/Methods/PayoneMethod.php
@@ -111,7 +111,7 @@ protected function sendPayoneCapture(InfoInterface $payment, $amount)
protected function sendPayoneAuthorization(InfoInterface $payment, $amount)
{
$oOrder = $payment->getOrder();
- $this->checkoutSession->unsPayoneRedirectUrl();// remove redirect url from session
+ $this->checkoutSession->unsPayoneRedirectUrl(); // remove redirect url from session
$aResponse = $this->authorizationRequest->sendRequest($this, $oOrder, $amount);
$this->handleResponse($aResponse);
if ($aResponse['status'] == 'ERROR') {// request returned an error
@@ -154,7 +154,7 @@ public function getOperationMode()
*/
public function getPaymentSpecificParameters(Order $oOrder)
{
- return [];// filled in child classes
+ return []; // filled in child classes
}
/**
@@ -272,7 +272,7 @@ public function getSubType()
*/
public function getSubTypeSpecificParameters(Order $oOrder)
{
- return [];// filled in child classes
+ return []; // filled in child classes
}
/**
diff --git a/Model/PayoneConfig.php b/Model/PayoneConfig.php
index 2de48404..d474f4a1 100644
--- a/Model/PayoneConfig.php
+++ b/Model/PayoneConfig.php
@@ -32,7 +32,7 @@
abstract class PayoneConfig
{
/* Module version */
- const MODULE_VERSION = '1.2.7';
+ const MODULE_VERSION = '1.3.1';
/* Authorization request types */
const REQUEST_TYPE_PREAUTHORIZATION = 'preauthorization';
@@ -58,8 +58,8 @@ abstract class PayoneConfig
const TRANSACTIONSTATUS_REMINDER = 'reminder';
const TRANSACTIONSTATUS_VAUTHORIZATION = 'vauthorization';
const TRANSACTIONSTATUS_VSETTLEMENT = 'vsettlement';
- const TRANSACTIONSTATUS_TRANSFER= 'transfer';
- const TRANSACTIONSTATUS_INVOICE= 'invoice';
+ const TRANSACTIONSTATUS_TRANSFER = 'transfer';
+ const TRANSACTIONSTATUS_INVOICE = 'invoice';
/* Payment method codes */
const METHOD_CREDITCARD = 'payone_creditcard';
diff --git a/Model/Paypal/ReturnHandler.php b/Model/Paypal/ReturnHandler.php
index a46d84c8..0e8c66e6 100644
--- a/Model/Paypal/ReturnHandler.php
+++ b/Model/Paypal/ReturnHandler.php
@@ -80,13 +80,12 @@ class ReturnHandler
/**
* Constructor
*
- * @param \Magento\Checkout\Model\Session $checkoutSession
- * @param \Payone\Core\Model\Api\Request\Genericpayment\PayPalExpress $genericRequest
- * @param \Payone\Core\Model\Methods\Paypal $paypalPayment
- * @param \Magento\Quote\Api\CartManagementInterface $cartManagement
- * @param \Payone\Core\Helper\Order $orderHelper
- * @param \Payone\Core\Helper\Checkout $checkoutHelper
- * @return void
+ * @param \Magento\Checkout\Model\Session $checkoutSession
+ * @param \Payone\Core\Model\Api\Request\Genericpayment\PayPalExpress $genericRequest
+ * @param \Payone\Core\Model\Methods\Paypal $paypalPayment
+ * @param \Magento\Quote\Api\CartManagementInterface $cartManagement
+ * @param \Payone\Core\Helper\Order $orderHelper
+ * @param \Payone\Core\Helper\Checkout $checkoutHelper
*/
public function __construct(
\Magento\Checkout\Model\Session $checkoutSession,
diff --git a/Model/Plugins/BillingAddressManagement.php b/Model/Plugins/BillingAddressManagement.php
new file mode 100644
index 00000000..a4d67a4a
--- /dev/null
+++ b/Model/Plugins/BillingAddressManagement.php
@@ -0,0 +1,80 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Model\Plugins;
+
+use Magento\Quote\Api\Data\AddressInterface;
+use Magento\Quote\Model\BillingAddressManagement as BillingAddressManagementOrig;
+
+/**
+ * Plugin for Magentos BillingAddressManagement class
+ */
+class BillingAddressManagement
+{
+ /**
+ * Quote repository.
+ *
+ * @var \Magento\Quote\Api\CartRepositoryInterface
+ */
+ protected $quoteRepository;
+
+ /**
+ * PAYONE addresscheck request model
+ *
+ * @var \Payone\Core\Model\Risk\Addresscheck
+ */
+ protected $addresscheck;
+
+ /**
+ * Constructor
+ *
+ * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
+ * @param \Payone\Core\Model\Risk\Addresscheck $addresscheck
+ */
+ public function __construct(
+ \Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
+ \Payone\Core\Model\Risk\Addresscheck $addresscheck
+ ) {
+ $this->quoteRepository = $quoteRepository;
+ $this->addresscheck = $addresscheck;
+ }
+
+ /**
+ * This writes the addresscheck score to the quote address
+ *
+ * @param BillingAddressManagementOrig $oSource
+ * @param int $sCartId
+ * @param AddressInterface $oAddress
+ * @param bool $useForShipping
+ * @return array
+ */
+ public function beforeAssign(BillingAddressManagementOrig $oSource, $sCartId, AddressInterface $oAddress, $useForShipping = false)
+ {
+ $oQuote = $this->quoteRepository->getActive($sCartId);
+ $oAddress = $this->addresscheck->handleAddressManagement($oAddress, $oQuote);
+ return [$sCartId, $oAddress, $useForShipping];
+ }
+}
diff --git a/Model/Plugins/MethodList.php b/Model/Plugins/MethodList.php
new file mode 100644
index 00000000..097bf9c3
--- /dev/null
+++ b/Model/Plugins/MethodList.php
@@ -0,0 +1,177 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Model\Plugins;
+
+use Magento\Payment\Model\MethodList as OrigMethodList;
+use Magento\Payment\Model\MethodInterface;
+use Magento\Quote\Api\Data\AddressInterface;
+use Payone\Core\Model\Source\CreditratingIntegrationEvent as Event;
+
+/**
+ * Plugin for Magentos MethodList class
+ */
+class MethodList
+{
+ /**
+ * PAYONE consumerscore request model
+ *
+ * @var \Payone\Core\Model\Api\Request\Consumerscore
+ */
+ protected $consumerscore;
+
+ /**
+ * Consumerscore helper
+ *
+ * @var \Payone\Core\Helper\Consumerscore
+ */
+ protected $consumerscoreHelper;
+
+ /**
+ * Checkout session
+ *
+ * @var \Magento\Checkout\Model\Session
+ */
+ protected $checkoutSession;
+
+ /**
+ * Constructor
+ *
+ * @param \Payone\Core\Model\Api\Request\Consumerscore $consumerscore
+ * @param \Payone\Core\Helper\Consumerscore $consumerscoreHelper
+ * @param \Magento\Checkout\Model\Session $checkoutSession
+ */
+ public function __construct(
+ \Payone\Core\Model\Api\Request\Consumerscore $consumerscore,
+ \Payone\Core\Helper\Consumerscore $consumerscoreHelper,
+ \Magento\Checkout\Model\Session $checkoutSession
+ ) {
+ $this->consumerscore = $consumerscore;
+ $this->consumerscoreHelper = $consumerscoreHelper;
+ $this->checkoutSession = $checkoutSession;
+ }
+
+ /**
+ * Filter methods by the worst score
+ *
+ * @param MethodInterface[] $aPaymentMethods
+ * @param string $sWorstScore
+ * @return MethodInterface[]
+ */
+ protected function filterMethodsByScore($aPaymentMethods, $sWorstScore)
+ {
+ $aRedMethods = $this->consumerscoreHelper->getAllowedMethodsForScore('R');
+ $aYellowMethods = array_merge($aRedMethods, $this->consumerscoreHelper->getAllowedMethodsForScore('Y'));
+
+ $aReturnMethods = [];
+ foreach ($aPaymentMethods as $oMethod) {
+ if ($sWorstScore == 'Y' && array_search($oMethod->getCode(), $aYellowMethods) !== false) {
+ $aReturnMethods[] = $oMethod;
+ }
+
+ if ($sWorstScore == 'R' && array_search($oMethod->getCode(), $aRedMethods) !== false) {
+ $aReturnMethods[] = $oMethod;
+ }
+ }
+ return $aReturnMethods;
+ }
+
+ /**
+ * Execute a consumerscore request to PAYONE or load an old score if its lifetime is still active
+ *
+ * @param AddressInterface $oShipping
+ * @return string
+ */
+ protected function getScoreByCreditrating(AddressInterface $oShipping)
+ {
+ $aResponse = $this->consumerscore->sendRequest($oShipping);
+ if ($aResponse === true) {// creditrating not executed because of a previous check
+ $this->consumerscoreHelper->copyOldStatusToNewAddress($oShipping);
+ }
+
+ if (isset($aResponse['score'])) {
+ $oShipping->setPayoneProtectScore($aResponse['score'])->save();
+ }
+
+ $sScore = $oShipping->getPayoneProtectScore();
+ return $sScore;
+ }
+
+ /**
+ * Get parameter from config
+ *
+ * @param string $sParam
+ * @param bool $blIsAddresscheck
+ * @return string
+ */
+ protected function getConfigParam($sParam, $blIsAddresscheck = false)
+ {
+ $sGroup = 'creditrating';
+ if ($blIsAddresscheck === true) {
+ $sGroup = 'address_check';
+ }
+ return $this->consumerscoreHelper->getConfigParam($sParam, $sGroup, 'payone_protect');
+ }
+
+ /**
+ * Get quote object from session
+ *
+ * @return \Magento\Quote\Model\Quote
+ */
+ protected function getQuote()
+ {
+ return $this->checkoutSession->getQuote();
+ }
+
+ /**
+ *
+ * @param OrigMethodList $subject
+ * @param MethodInterface[] $aPaymentMethods
+ * @return MethodInterface[]
+ */
+ public function afterGetAvailableMethods(OrigMethodList $subject, $aPaymentMethods)
+ {
+ $oQuote = $this->getQuote();
+ $oShipping = $oQuote->getShippingAddress();
+
+ $aScores = [];
+ if ($this->getConfigParam('enabled', true)) {// is addresscheck active
+ $aScores[] = $oShipping->getPayoneAddresscheckScore();
+ }
+
+ $dTotal = $this->getQuote()->getGrandTotal();
+ if ($this->consumerscoreHelper->isCreditratingNeeded(Event::BEFORE_PAYMENT, $dTotal) === true) {
+ $aScores[] = $this->getScoreByCreditrating($oShipping);
+ }
+
+ $sScore = $this->consumerscoreHelper->getWorstScore($aScores);
+ if ($sScore != 'G') { // no need to filter
+ $aPaymentMethods = $this->filterMethodsByScore($aPaymentMethods, $sScore);
+ }
+
+ return $aPaymentMethods;
+ }
+}
diff --git a/Model/Plugins/ShippingAddressManagement.php b/Model/Plugins/ShippingAddressManagement.php
new file mode 100644
index 00000000..f1778cd7
--- /dev/null
+++ b/Model/Plugins/ShippingAddressManagement.php
@@ -0,0 +1,79 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Model\Plugins;
+
+use Magento\Quote\Api\Data\AddressInterface;
+use Magento\Quote\Model\ShippingAddressManagement as ShippingAddressManagementOrig;
+
+/**
+ * Plugin for Magentos ShippingAddressManagement class
+ */
+class ShippingAddressManagement
+{
+ /**
+ * Quote repository.
+ *
+ * @var \Magento\Quote\Api\CartRepositoryInterface
+ */
+ protected $quoteRepository;
+
+ /**
+ * PAYONE addresscheck request model
+ *
+ * @var \Payone\Core\Model\Risk\Addresscheck
+ */
+ protected $addresscheck;
+
+ /**
+ * Constructor
+ *
+ * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
+ * @param \Payone\Core\Model\Risk\Addresscheck $addresscheck
+ */
+ public function __construct(
+ \Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
+ \Payone\Core\Model\Risk\Addresscheck $addresscheck
+ ) {
+ $this->quoteRepository = $quoteRepository;
+ $this->addresscheck = $addresscheck;
+ }
+
+ /**
+ * This writes the addresscheck score to the quote address
+ *
+ * @param ShippingAddressManagementOrig $oSource
+ * @param int $sCartId
+ * @param AddressInterface $oAddress
+ * @return array
+ */
+ public function beforeAssign(ShippingAddressManagementOrig $oSource, $sCartId, AddressInterface $oAddress)
+ {
+ $oQuote = $this->quoteRepository->getActive($sCartId);
+ $oAddress = $this->addresscheck->handleAddressManagement($oAddress, $oQuote, false);
+ return [$sCartId, $oAddress];
+ }
+}
diff --git a/Model/ResourceModel/CheckedAddresses.php b/Model/ResourceModel/CheckedAddresses.php
new file mode 100644
index 00000000..dc189283
--- /dev/null
+++ b/Model/ResourceModel/CheckedAddresses.php
@@ -0,0 +1,195 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Model\ResourceModel;
+
+use Magento\Quote\Api\Data\AddressInterface;
+
+/**
+ * CheckedAddresses resource model
+ */
+class CheckedAddresses extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
+{
+ /**
+ * Shop helper object
+ *
+ * @var \Payone\Core\Helper\Shop
+ */
+ protected $shopHelper;
+
+ /**
+ * All parameters used for the address hash
+ *
+ * @var array
+ */
+ protected $aHashParams = [
+ 'firstname',
+ 'lastname',
+ 'company',
+ 'street',
+ 'zip',
+ 'city',
+ 'country',
+ 'state',
+ ];
+
+ /**
+ * Class constructor
+ *
+ * @param \Magento\Framework\Model\ResourceModel\Db\Context $context
+ * @param \Payone\Core\Helper\Shop $shopHelper
+ * @param string $connectionName
+ */
+ public function __construct(
+ \Magento\Framework\Model\ResourceModel\Db\Context $context,
+ \Payone\Core\Helper\Shop $shopHelper,
+ $connectionName = null
+ ) {
+ parent::__construct($context, $connectionName);
+ $this->shopHelper = $shopHelper;
+ }
+
+ /**
+ * Initialize connection and table
+ *
+ * @return void
+ */
+ protected function _construct()
+ {
+ $this->_init('payone_checked_addresses', 'address_hash');
+ }
+
+ /**
+ * Get address array for hash creation
+ *
+ * @param AddressInterface $oAddress
+ * @return array
+ */
+ protected function getAddressArray(AddressInterface $oAddress)
+ {
+ return [
+ 'firstname' => $oAddress->getFirstname(),
+ 'lastname' => $oAddress->getLastname(),
+ 'company' => $oAddress->getCompany(),
+ 'street' => $oAddress->getStreet()[0],
+ 'zip' => $oAddress->getPostcode(),
+ 'city' => $oAddress->getCity(),
+ 'country' => $oAddress->getCountryId(),
+ 'state' => $oAddress->getRegionCode(),
+ ];
+ }
+
+ /**
+ * Generate a unique hash of an address
+ *
+ * @param AddressInterface $oAddress
+ * @param array $aResponse
+ * @return string
+ */
+ protected function getHashFromAddress(AddressInterface $oAddress, $aResponse = false)
+ {
+ $aAddressArray = $this->getAddressArray($oAddress); // collect data from the address object
+
+ $sAddress = '';
+ foreach ($this->aHashParams as $sParamKey) {
+ $sParamValue = isset($aAddressArray[$sParamKey]) ? $aAddressArray[$sParamKey] : false;
+ if ($sParamValue) {
+ if ($aResponse !== false && array_key_exists($sParamKey, $aResponse) !== false && $aResponse[$sParamKey] != $sParamValue) {
+ //take the corrected value from the address-check
+ $sParamValue = $aResponse[$sParamKey];
+ }
+ $sAddress .= $sParamValue;
+ }
+ }
+ $sHash = md5($sAddress); // generate hash from address for identification
+
+ return $sHash;
+ }
+
+ /**
+ * Save Api-log entry to database
+ *
+ * @param AddressInterface $oAddress
+ * @param array $aResponse
+ * @param bool $blIsBonicheck
+ * @return $this
+ */
+ public function addCheckedAddress(AddressInterface $oAddress, $aResponse, $blIsBonicheck = false)
+ {
+ $sHash = $this->getHashFromAddress($oAddress, $aResponse); // generate hash from given address
+ $this->getConnection()->insert(
+ $this->getMainTable(),
+ [
+ 'address_hash' => $sHash,
+ 'is_bonicheck' => $blIsBonicheck
+ ]
+ );
+ return $this;
+ }
+
+ /**
+ * Check and return if this exact address has been checked before
+ *
+ * @param AddressInterface $oAddress
+ * @param bool $blIsBonicheck
+ * @return bool
+ */
+ public function wasAddressCheckedBefore(AddressInterface $oAddress, $blIsBonicheck = false)
+ {
+ $sHash = $this->getHashFromAddress($oAddress);
+ $oDb = $this->getConnection();
+ $sQuery = " SELECT
+ checkdate
+ FROM
+ {$this->getMainTable()}
+ WHERE
+ address_hash = :hash AND
+ is_bonicheck = :isBoni";
+ $aParams = [
+ 'hash' => $sHash,
+ 'isBoni' => $blIsBonicheck
+ ];
+
+ $sGroup = 'address_check';
+ if ($blIsBonicheck === true) {
+ $sGroup = 'creditrating';
+ }
+
+ $sLifetime = $this->shopHelper->getConfigParam('result_lifetime', $sGroup, 'payone_protect');
+ if (!empty($sLifetime) && is_numeric($sLifetime)) {
+ $sQuery .= " AND checkdate > DATE_SUB(NOW(), INTERVAL :lifetime DAY)";
+ $aParams['lifetime'] = $sLifetime;
+ } else {
+ return false; // no lifetime = check every time
+ }
+
+ $sDate = $oDb->fetchOne($sQuery, $aParams);
+ if ($sDate != false) {
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/Model/ResourceModel/TransactionStatus.php b/Model/ResourceModel/TransactionStatus.php
index 4cbc3a71..ee7783ed 100644
--- a/Model/ResourceModel/TransactionStatus.php
+++ b/Model/ResourceModel/TransactionStatus.php
@@ -52,10 +52,9 @@ class TransactionStatus extends \Magento\Framework\Model\ResourceModel\Db\Abstra
/**
* Constructor
*
- * @param \Magento\Framework\Model\ResourceModel\Db\Context $context
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
- * @param string $connectionName
- * @return void
+ * @param \Magento\Framework\Model\ResourceModel\Db\Context $context
+ * @param \Magento\Store\Model\StoreManagerInterface $storeManager
+ * @param string $connectionName
*/
public function __construct(
\Magento\Framework\Model\ResourceModel\Db\Context $context,
@@ -108,7 +107,7 @@ public function addTransactionLogEntry(Context $oContext, Order $oOrder = null)
$aRequest = $oContext->getRequest()->getPostValue();
$sRawStatus = serialize($aRequest);
if (!Toolkit::isUTF8($sRawStatus)) {
- $sRawStatus = utf8_encode($sRawStatus);// needed for serializing the array
+ $sRawStatus = utf8_encode($sRawStatus); // needed for serializing the array
}
$sOrderId = $oOrder !== null ? $oOrder->getIncrementId() : '';
$this->getConnection()->insert(
diff --git a/Model/Risk/Addresscheck.php b/Model/Risk/Addresscheck.php
new file mode 100644
index 00000000..4bc21e7e
--- /dev/null
+++ b/Model/Risk/Addresscheck.php
@@ -0,0 +1,394 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Model\Risk;
+
+use Magento\Quote\Api\Data\AddressInterface;
+use Magento\Quote\Model\Quote;
+use Magento\Framework\Exception\LocalizedException;
+
+/**
+ * Model for calling the addresscheck request
+ */
+class Addresscheck
+{
+ /**
+ * Response from the PAYONE addresscheck request
+ *
+ * @var array
+ */
+ protected $aResponse = null;
+
+ /**
+ * Determines if the request was NOT executed because the lifetime of the last was still valid
+ *
+ * @var bool
+ */
+ protected $blIsLifetimeValid;
+
+ /**
+ * Saves if the address was corrected
+ *
+ * @var bool
+ */
+ protected $addressCorrected;
+
+ /**
+ * PAYONE addresscheck request model
+ *
+ * @var \Payone\Core\Model\Api\Request\Addresscheck
+ */
+ protected $addresscheck;
+
+ /**
+ * PAYONE database helper
+ *
+ * @var \Payone\Core\Helper\Database
+ */
+ protected $databaseHelper;
+
+ /**
+ * PAYONE toolkit helper
+ *
+ * @var \Payone\Core\Helper\Toolkit
+ */
+ protected $toolkitHelper;
+
+ /**
+ * Checkout session
+ *
+ * @var \Magento\Checkout\Model\Session
+ */
+ protected $checkoutSession;
+
+ /**
+ * Constructor
+ *
+ * @param \Payone\Core\Model\Api\Request\Addresscheck $addresscheck
+ * @param \Payone\Core\Helper\Database $databaseHelper
+ * @param \Payone\Core\Helper\Toolkit $toolkitHelper
+ * @param \Magento\Checkout\Model\Session $checkoutSession
+ */
+ public function __construct(
+ \Payone\Core\Model\Api\Request\Addresscheck $addresscheck,
+ \Payone\Core\Helper\Database $databaseHelper,
+ \Payone\Core\Helper\Toolkit $toolkitHelper,
+ \Magento\Checkout\Model\Session $checkoutSession
+ ) {
+ $this->addresscheck = $addresscheck;
+ $this->databaseHelper = $databaseHelper;
+ $this->toolkitHelper = $toolkitHelper;
+ $this->checkoutSession = $checkoutSession;
+ }
+
+ /**
+ * Return if check was not executed because the lifetime of the last check was still valid
+ *
+ * @return bool
+ */
+ public function isLifetimeStillValid()
+ {
+ return $this->blIsLifetimeValid;
+ }
+
+ /**
+ * Return addressCorrected property
+ *
+ * @return bool
+ */
+ public function isAddressCorrected()
+ {
+ return $this->addressCorrected;
+ }
+
+ /**
+ * Get addresscheck config parameter
+ *
+ * @param string $sParam
+ * @return string
+ */
+ public function getConfigParam($sParam)
+ {
+ return $this->databaseHelper->getConfigParam($sParam, 'address_check', 'payone_protect');
+ }
+
+ /**
+ * Correct a single address field if needed
+ *
+ * @param AddressInterface $oAddress
+ * @param array $aResponse
+ * @param string $sArrayKey
+ * @param string $sPropertyName
+ * @return AddressInterface
+ */
+ protected function correctSingleField(AddressInterface $oAddress, $aResponse, $sArrayKey, $sPropertyName)
+ {
+ if (isset($aResponse[$sArrayKey]) && $aResponse[$sArrayKey] != $oAddress->getData($sPropertyName)) {
+ $oAddress->setData($sPropertyName, $aResponse[$sArrayKey]);
+ $this->addressCorrected = true;
+ }
+
+ return $oAddress;
+ }
+
+ /**
+ * Change the address according to the response
+ *
+ * @param AddressInterface $oAddress
+ * @return AddressInterface
+ */
+ public function correctAddress(AddressInterface $oAddress)
+ {
+ $aResponse = $this->getResponse($oAddress);
+ if (!is_array($aResponse)) {
+ return $oAddress;
+ }
+
+ $this->addressCorrected = false;
+ $oAddress = $this->correctSingleField($oAddress, $aResponse, 'firstname', 'firstname');
+ $oAddress = $this->correctSingleField($oAddress, $aResponse, 'lastname', 'lastname');
+ $oAddress = $this->correctSingleField($oAddress, $aResponse, 'zip', 'postcode');
+ $oAddress = $this->correctSingleField($oAddress, $aResponse, 'city', 'city');
+
+ if (isset($aResponse['street'])) {
+ $sStreet = $oAddress->getStreet();
+ if (is_array($sStreet)) {
+ $sStreet = implode(' ', $sStreet);
+ }
+
+ if ($aResponse['street'] != $sStreet) {
+ $oAddress->setStreet($aResponse['street']);
+ $this->addressCorrected = true;
+ }
+ }
+
+ return $oAddress;
+ }
+
+ /**
+ * Check if the addresscheck needs to be executed for this quote
+ *
+ * @param bool $isBillingAddress
+ * @param bool $isVirtual
+ * @param double $dTotal
+ * @return bool
+ */
+ public function isCheckNeededForQuote($isBillingAddress, $isVirtual, $dTotal)
+ {
+ $dMinBasketValue = $this->getConfigParam('min_order_total');
+ if (!empty($dMinBasketValue) && is_numeric($dMinBasketValue) && $dTotal < $dMinBasketValue) {
+ return false;
+ }
+
+ $dMaxBasketValue = $this->getConfigParam('max_order_total');
+ if (!empty($dMaxBasketValue) && is_numeric($dMaxBasketValue) && $dTotal > $dMaxBasketValue) {
+ return false;
+ }
+
+ $blCheckVirtual = (bool)$this->getConfigParam('check_billing_for_virtual_order');
+ if ($isBillingAddress === true && $isVirtual === true && $blCheckVirtual === false) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns the personstatus mapping from addresscheck admin config
+ *
+ * @return array
+ */
+ public function getPersonstatusMapping()
+ {
+ $aReturnMappings = [];
+
+ $sMappings = $this->getConfigParam('mapping_personstatus');
+ $aMappings = unserialize($sMappings);
+ if (!is_array($aMappings)) {
+ $aMappings = [];
+ }
+
+ foreach ($aMappings as $aMapping) {
+ $aReturnMappings[$aMapping['personstatus']] = $aMapping['score'];
+ }
+
+ return $aReturnMappings;
+ }
+
+ /**
+ * Get formatted invalid message
+ *
+ * @param string $sCustomermessage
+ * @return string
+ */
+ public function getInvalidMessage($sCustomermessage)
+ {
+ $sInvalidMessage = $this->getConfigParam('message_response_invalid');
+ if (!empty($sInvalidMessage)) {
+ $aSubstitutionArray = [
+ '{{payone_customermessage}}' => __($sCustomermessage),
+ ];
+ return $this->toolkitHelper->handleSubstituteReplacement($sInvalidMessage, $aSubstitutionArray, 255);
+ }
+
+ return __($sCustomermessage);
+ }
+
+ /**
+ * Return error message
+ *
+ * @return string
+ */
+ public function getErrorMessage()
+ {
+ $sErrorMessage = $this->getConfigParam('stop_checkout_message');
+ if (empty($sErrorMessage)) { // add default errormessage if none is configured
+ $sErrorMessage = 'An error occured during the addresscheck.';
+ }
+ return $sErrorMessage;
+ }
+
+ /**
+ * Get error message by the given response
+ *
+ * @param array $aResponse
+ * @return string
+ */
+ public function getErrorMessageByResponse($aResponse)
+ {
+ $sErrorMessage = false;
+ if ($aResponse['status'] == 'INVALID') {
+ $sErrorMessage = $this->getInvalidMessage($aResponse['customermessage']);
+ } elseif ($aResponse['status'] == 'ERROR') {
+ if ($this->getConfigParam('handle_response_error') == 'stop_checkout') {
+ $sErrorMessage = $this->getErrorMessage();
+ }
+ }
+ return $sErrorMessage;
+ }
+
+ /**
+ * Execute addresscheck and return the response
+ *
+ * @param AddressInterface $oAddress
+ * @return array
+ */
+
+ /**
+ *
+ * @param AddressInterface $oAddress
+ * @return type
+ * @throws LocalizedException
+ */
+ protected function handleAddresscheck(AddressInterface $oAddress)
+ {
+ $aResponse = $this->getResponse($oAddress);
+ if (is_array($aResponse)) {
+ $sErrorMessage = $this->getErrorMessageByResponse($aResponse);
+ if (!empty($sErrorMessage)) {
+ throw new LocalizedException(__($sErrorMessage));
+ }
+ }
+ return $aResponse;
+ }
+
+ /**
+ * Get score from session or from a new addresscheck and add it to the address
+ *
+ * @param AddressInterface $oAddress
+ * @param Quote $oQuote
+ * @param bool $blIsBillingAddress
+ * @return AddressInterface
+ */
+ public function handleAddressManagement(AddressInterface $oAddress, Quote $oQuote, $blIsBillingAddress = true)
+ {
+ $sScore = $this->checkoutSession->getPayoneBillingAddresscheckScore();
+ if ($blIsBillingAddress === false) {
+ $sScore = $this->checkoutSession->getPayoneShippingAddresscheckScore();
+ }
+ $this->checkoutSession->unsPayoneBillingAddresscheckScore();
+ $this->checkoutSession->unsPayoneShippingAddresscheckScore();
+
+ if (!$sScore && empty($oAddress->getPayoneAddresscheckScore())) {
+ if ($this->isCheckNeededForQuote(false, $oQuote->isVirtual(), $oQuote->getSubtotal())) {
+ $aResponse = $this->handleAddresscheck($oAddress);
+ if (isset($aResponse['status']) && $aResponse['status'] == 'VALID') {
+ $oAddress = $this->correctAddress($oAddress);
+ }
+ $sScore = $this->getScore($oAddress);
+ }
+ }
+ if ($sScore) {
+ $oAddress->setPayoneAddresscheckScore($sScore);
+ }
+ return $oAddress;
+ }
+
+ /**
+ * Get score from response or an old saved score from the database
+ *
+ * @param AddressInterface $oAddress
+ * @return string
+ */
+ public function getScore(AddressInterface $oAddress)
+ {
+ $aResponse = $this->getResponse($oAddress);
+
+ $sScore = 'G';
+ if (isset($aResponse['status']) && $aResponse['status'] == 'INVALID') {
+ $sScore = 'R';
+ } elseif (isset($aResponse['personstatus'])) {
+ $sPersonStatus = $aResponse['personstatus'];
+ if ($sPersonStatus != 'NONE') {
+ $aMapping = $this->getPersonstatusMapping();
+ if (array_key_exists($sPersonStatus, $aMapping)) {
+ $sScore = $aMapping[$sPersonStatus];
+ }
+ }
+ } elseif ($this->isLifetimeStillValid()) {
+ $sScore = $this->databaseHelper->getOldAddressStatus($oAddress, false);
+ }
+ return $sScore;
+ }
+
+ /**
+ * Perform the PAYONE addresscheck request and return the response
+ *
+ * @param AddressInterface $oAddress
+ * @param bool $blIsBillingAddress
+ * @return array|bool
+ */
+ public function getResponse(AddressInterface $oAddress, $blIsBillingAddress = false)
+ {
+ if ($this->aResponse === null) {
+ $this->aResponse = $this->addresscheck->sendRequest($oAddress, $blIsBillingAddress);
+ if ($this->aResponse === true) {
+ $this->blIsLifetimeValid = true;
+ }
+ }
+ return $this->aResponse;
+ }
+}
diff --git a/Model/Source/AddressCheckType.php b/Model/Source/AddressCheckType.php
new file mode 100644
index 00000000..a3e0da01
--- /dev/null
+++ b/Model/Source/AddressCheckType.php
@@ -0,0 +1,62 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Model\Source;
+
+use Magento\Framework\Option\ArrayInterface;
+
+/**
+ * Source class for existing BankaccountCheck types
+ */
+class AddressCheckType implements ArrayInterface
+{
+ const NONE = 'NO';
+ const BASIC = 'BA';
+ const PERSON = 'PE';
+
+ /**
+ * Return existing address check types
+ *
+ * @return array
+ */
+ public function toOptionArray()
+ {
+ return [
+ [
+ 'value' => self::NONE,
+ 'label' => __('None'),
+ ],
+ [
+ 'value' => self::BASIC,
+ 'label' => __('Basic')
+ ],
+ [
+ 'value' => self::PERSON,
+ 'label' => __('Person')
+ ]
+ ];
+ }
+}
diff --git a/Model/Source/CreditScore.php b/Model/Source/CreditScore.php
new file mode 100644
index 00000000..75adf9c9
--- /dev/null
+++ b/Model/Source/CreditScore.php
@@ -0,0 +1,63 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Model\Source;
+
+use Magento\Framework\Option\ArrayInterface;
+
+/**
+ * Source class for credit score states
+ */
+class CreditScore implements ArrayInterface
+{
+ const GREEN = 'G';
+ const YELLOW = 'Y';
+ const RED = 'R';
+
+ /**
+ * Return existing credit score states
+ *
+ * @return array
+ */
+ public function toOptionArray()
+ {
+ return [
+ [
+ 'value' => self::GREEN,
+ 'label' => __('Green'),
+ ],
+ [
+ 'value' => self::YELLOW,
+ 'label' => __('Yellow'),
+ ],
+ [
+ 'value' => self::RED,
+ 'label' => __('Red'),
+ ],
+
+ ];
+ }
+}
diff --git a/Model/Source/CreditratingCheckType.php b/Model/Source/CreditratingCheckType.php
new file mode 100644
index 00000000..e39b7cf8
--- /dev/null
+++ b/Model/Source/CreditratingCheckType.php
@@ -0,0 +1,62 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Model\Source;
+
+use Magento\Framework\Option\ArrayInterface;
+
+/**
+ * Source class for existing CreditratingCheckType types
+ */
+class CreditratingCheckType implements ArrayInterface
+{
+ const INFOSCORE_HARD = 'IH';
+ const INFOSCORE_ALL = 'IA';
+ const INFOSCORE_ALL_BONI = 'IB';
+
+ /**
+ * Return existing address check types
+ *
+ * @return array
+ */
+ public function toOptionArray()
+ {
+ return [
+ [
+ 'value' => self::INFOSCORE_HARD,
+ 'label' => __('Infoscore (hard criteria)'),
+ ],
+ [
+ 'value' => self::INFOSCORE_ALL,
+ 'label' => __('Infoscore (all criteria)')
+ ],
+ [
+ 'value' => self::INFOSCORE_ALL_BONI,
+ 'label' => __('Infoscore (all criteria with boni-score)')
+ ]
+ ];
+ }
+}
diff --git a/Model/Source/CreditratingIntegrationEvent.php b/Model/Source/CreditratingIntegrationEvent.php
new file mode 100644
index 00000000..24d6c584
--- /dev/null
+++ b/Model/Source/CreditratingIntegrationEvent.php
@@ -0,0 +1,57 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Model\Source;
+
+use Magento\Framework\Option\ArrayInterface;
+
+/**
+ * Source class for credit score states
+ */
+class CreditratingIntegrationEvent implements ArrayInterface
+{
+ const BEFORE_PAYMENT = 'before_payment';
+ const AFTER_PAYMENT = 'after_payment';
+
+ /**
+ * Return existing credit score states
+ *
+ * @return array
+ */
+ public function toOptionArray()
+ {
+ return [
+ [
+ 'value' => self::BEFORE_PAYMENT,
+ 'label' => __('Before Payment Selection'),
+ ],
+ [
+ 'value' => self::AFTER_PAYMENT,
+ 'label' => __('After Payment Selection'),
+ ],
+ ];
+ }
+}
diff --git a/Model/Source/HandleResponseError.php b/Model/Source/HandleResponseError.php
new file mode 100644
index 00000000..5ac9e8e2
--- /dev/null
+++ b/Model/Source/HandleResponseError.php
@@ -0,0 +1,57 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Model\Source;
+
+use Magento\Framework\Option\ArrayInterface;
+
+/**
+ * Source class for existing address check response handling
+ */
+class HandleResponseError implements ArrayInterface
+{
+ const CONTINUE_CHECKOUT = 'continue_checkout';
+ const STOP_CHECKOUT = 'stop_checkout';
+
+ /**
+ * Return existing address check types
+ *
+ * @return array
+ */
+ public function toOptionArray()
+ {
+ return [
+ [
+ 'value' => self::CONTINUE_CHECKOUT,
+ 'label' => __('Continue Checkout'),
+ ],
+ [
+ 'value' => self::STOP_CHECKOUT,
+ 'label' => __('Stop Checkout')
+ ]
+ ];
+ }
+}
diff --git a/Model/Source/KlarnaCountry.php b/Model/Source/KlarnaCountry.php
index 939ab3df..11180716 100644
--- a/Model/Source/KlarnaCountry.php
+++ b/Model/Source/KlarnaCountry.php
@@ -50,8 +50,7 @@ class KlarnaCountry implements ArrayInterface
/**
* Constructor
*
- * @param \Payone\Core\Helper\Country $countryHelper
- * @return void
+ * @param \Payone\Core\Helper\Country $countryHelper
*/
public function __construct(\Payone\Core\Helper\Country $countryHelper)
{
diff --git a/Model/Source/PersonStatus.php b/Model/Source/PersonStatus.php
new file mode 100644
index 00000000..dd3c0569
--- /dev/null
+++ b/Model/Source/PersonStatus.php
@@ -0,0 +1,103 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Model\Source;
+
+use Magento\Framework\Option\ArrayInterface;
+
+/**
+ * Source class for person status states
+ */
+class PersonStatus implements ArrayInterface
+{
+ const NONE = 'NONE'; //NONE: no verification of personal data carried out
+ const PAB = 'PAB'; //PAB: first name & surname unknown
+ const PHB = 'PHB'; //PHB: surname known
+ const PKI = 'PKI'; //PKI: ambiguity in name and address
+ const PNP = 'PNP'; //PNP: address cannot be checked, e.g. fake name used
+ const PNZ = 'PNZ'; //PNZ: cannot be delivered (any longer)
+ const PPB = 'PPB'; //PPB: first name & surname unknown
+ const PPF = 'PPF'; //PPF: postal address details incorrect
+ const PPV = 'PPV'; //PPV: person deceased
+ const PUG = 'PUG'; //PUG: postal address details correct but building unknown
+ const PUZ = 'PUZ'; //PUZ: person has moved, address not corrected
+ const UKN = 'UKN'; //UKN: unknown return values are mapped to UKN
+
+ /**
+ * Return existing person status states
+ *
+ * @return array
+ */
+ public function toOptionArray()
+ {
+ return [
+ [
+ 'value' => self::NONE,
+ 'label' => __(self::NONE),
+ ],
+ [
+ 'value' => self::PPB,
+ 'label' => __(self::PPB),
+ ],
+ [
+ 'value' => self::PHB,
+ 'label' => __(self::PHB),
+ ],
+ [
+ 'value' => self::PAB,
+ 'label' => __(self::PAB),
+ ],
+ [
+ 'value' => self::PKI,
+ 'label' => __(self::PKI),
+ ],
+ [
+ 'value' => self::PNZ,
+ 'label' => __(self::PNZ),
+ ],
+ [
+ 'value' => self::PPV,
+ 'label' => __(self::PPV),
+ ],
+ [
+ 'value' => self::PPF,
+ 'label' => __(self::PPF),
+ ],
+ [
+ 'value' => self::PUG,
+ 'label' => __(self::PUG),
+ ],
+ [
+ 'value' => self::PUZ,
+ 'label' => __(self::PUZ),
+ ],
+ [
+ 'value' => self::UKN,
+ 'label' => __(self::UKN),
+ ],
+ ];
+ }
+}
diff --git a/Model/Source/SepaCountry.php b/Model/Source/SepaCountry.php
index e137011a..68bfd1e7 100644
--- a/Model/Source/SepaCountry.php
+++ b/Model/Source/SepaCountry.php
@@ -54,8 +54,7 @@ class SepaCountry implements ArrayInterface
/**
* Constructor
*
- * @param \Payone\Core\Helper\Country $countryHelper
- * @return void
+ * @param \Payone\Core\Helper\Country $countryHelper
*/
public function __construct(\Payone\Core\Helper\Country $countryHelper)
{
diff --git a/Model/TransactionStatus/Forwarding.php b/Model/TransactionStatus/Forwarding.php
index 58a9894a..ca5ab02a 100644
--- a/Model/TransactionStatus/Forwarding.php
+++ b/Model/TransactionStatus/Forwarding.php
@@ -41,8 +41,7 @@ class Forwarding
/**
* Constructor
*
- * @param \Payone\Core\Helper\Config $configHelper
- * @return void
+ * @param \Payone\Core\Helper\Config $configHelper
*/
public function __construct(\Payone\Core\Helper\Config $configHelper)
{
diff --git a/Model/TransactionStatus/Mapping.php b/Model/TransactionStatus/Mapping.php
index e0814e10..d394056c 100644
--- a/Model/TransactionStatus/Mapping.php
+++ b/Model/TransactionStatus/Mapping.php
@@ -50,9 +50,8 @@ class Mapping
/**
* Constructor
*
- * @param \Payone\Core\Helper\Payment $paymentHelper
- * @param \Payone\Core\Helper\Database $databaseHelper
- * @return void
+ * @param \Payone\Core\Helper\Payment $paymentHelper
+ * @param \Payone\Core\Helper\Database $databaseHelper
*/
public function __construct(
\Payone\Core\Helper\Payment $paymentHelper,
diff --git a/Model/UiComponent/DataProvider.php b/Model/UiComponent/DataProvider.php
index 4c8942d7..cc04d926 100644
--- a/Model/UiComponent/DataProvider.php
+++ b/Model/UiComponent/DataProvider.php
@@ -46,17 +46,16 @@ class DataProvider extends \Magento\Framework\View\Element\UiComponent\DataProvi
/**
* Constructor
*
- * @param string $name
- * @param string $primaryFieldName
- * @param string $requestFieldName
- * @param Reporting $reporting
- * @param SearchCriteriaBuilder $searchCritBuilder
- * @param RequestInterface $request
- * @param FilterBuilder $filterBuilder
- * @param \Payone\Core\Helper\Database $databaseHelper
- * @param array $meta
- * @param array $data
- * @return void
+ * @param string $name
+ * @param string $primaryFieldName
+ * @param string $requestFieldName
+ * @param Reporting $reporting
+ * @param SearchCriteriaBuilder $searchCritBuilder
+ * @param RequestInterface $request
+ * @param FilterBuilder $filterBuilder
+ * @param \Payone\Core\Helper\Database $databaseHelper
+ * @param array $meta
+ * @param array $data
*/
public function __construct(
$name,
@@ -70,7 +69,7 @@ public function __construct(
array $meta = [],
array $data = []
) {
- $this->databaseHelper = $databaseHelper;// needs to be in front of constructor, doesnt work otherwise for no apparent reason
+ $this->databaseHelper = $databaseHelper; // needs to be in front of constructor, doesnt work otherwise for no apparent reason
parent::__construct($name, $primaryFieldName, $requestFieldName, $reporting, $searchCritBuilder, $request, $filterBuilder, $meta, $data);
}
diff --git a/Model/WebApi/Addresscheck.php b/Model/WebApi/Addresscheck.php
new file mode 100644
index 00000000..552708b0
--- /dev/null
+++ b/Model/WebApi/Addresscheck.php
@@ -0,0 +1,199 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Model\WebApi;
+
+use Payone\Core\Model\WebApi\AddresscheckResponse;
+use Magento\Quote\Api\Data\AddressInterface;
+
+/**
+ * Web API model for the PAYONE addresscheck
+ */
+class Addresscheck
+{
+ /**
+ * PAYONE addresscheck request model
+ *
+ * @var \Payone\Core\Model\Risk\Addresscheck
+ */
+ protected $addresscheck;
+
+ /**
+ * Factory for the response object
+ *
+ * @var \Payone\Core\Model\WebApi\AddresscheckResponseFactory
+ */
+ protected $responseFactory;
+
+ /**
+ * Checkout session object
+ *
+ * @var \Magento\Checkout\Model\Session
+ */
+ protected $checkoutSession;
+
+ /**
+ * Constructor
+ *
+ * @param \Payone\Core\Model\Risk\Addresscheck $addresscheck
+ * @param \Payone\Core\Model\WebApi\AddresscheckResponseFactory $responseFactory
+ * @param \Magento\Checkout\Model\Session $checkoutSession
+ */
+ public function __construct(
+ \Payone\Core\Model\Risk\Addresscheck $addresscheck,
+ \Payone\Core\Model\WebApi\AddresscheckResponseFactory $responseFactory,
+ \Magento\Checkout\Model\Session $checkoutSession
+ ) {
+ $this->addresscheck = $addresscheck;
+ $this->responseFactory = $responseFactory;
+ $this->checkoutSession = $checkoutSession;
+ }
+
+ /**
+ * Generate the confirm message from the given address
+ *
+ * @param AddressInterface $addressData
+ * @return string
+ */
+ protected function getConfirmMessage(AddressInterface $addressData)
+ {
+ $sMessage = __('Address corrected. Please confirm.')."\n\n";
+ $sMessage .= $addressData->getFirstname().' '.$addressData->getLastname()."\n";
+
+ $mStreet = $addressData->getStreet();
+ if (is_array($mStreet)) { // address can be string
+ $sMessage .= $mStreet[0]."\n"; // add first line of address array
+ } else {
+ $sMessage .= $mStreet."\n"; // add string directly
+ }
+ $sMessage .= $addressData->getPostcode().' '.$addressData->getCity();
+
+ return $sMessage;
+ }
+
+ /**
+ * Add the score to the correct session variable
+ *
+ * @param AddressInterface $oAddress
+ * @param bool $blIsBillingAddress
+ * @return void
+ */
+ protected function addScoreToSession(AddressInterface $oAddress, $blIsBillingAddress)
+ {
+ $sScore = $this->addresscheck->getScore($oAddress);
+ if ($blIsBillingAddress === true) { // is billing address?
+ $this->checkoutSession->setPayoneBillingAddresscheckScore($sScore);
+ } else {
+ $this->checkoutSession->setPayoneShippingAddresscheckScore($sScore);
+ }
+ }
+
+ /**
+ * Set error message if checkout is configured to stop on error or set success = true instead
+ *
+ * @param AddresscheckResponse $oResponse
+ * @return AddresscheckResponse
+ */
+ protected function handleErrorCase(AddresscheckResponse $oResponse)
+ {
+ $sHandleError = $this->addresscheck->getConfigParam('handle_response_error');
+ if ($sHandleError == 'stop_checkout') {
+ $oResponse->setData('errormessage', __($this->addresscheck->getErrorMessage())); // stop checkout with errormsg
+ } elseif ($sHandleError == 'continue_checkout') {
+ $oResponse->setData('success', true); // continue anyways
+ }
+ return $oResponse;
+ }
+
+ /**
+ * Handle the response according to its return status
+ *
+ * @param AddresscheckResponse $oResponse
+ * @param AddressInterface $oAddress
+ * @param array $aResponse
+ * @return AddresscheckResponse
+ */
+ protected function handleResponse(AddresscheckResponse $oResponse, AddressInterface $oAddress, $aResponse)
+ {
+ if ($aResponse['status'] == 'VALID') { // data was checked successfully
+ $oAddress = $this->addresscheck->correctAddress($oAddress);
+ if ($this->addresscheck->isAddressCorrected() === true) { // was address changed?
+ $oResponse->setData('correctedAddress', $oAddress);
+ $oResponse->setData('confirmMessage', $this->getConfirmMessage($oAddress));
+ }
+ $oResponse->setData('success', true);
+ } elseif ($aResponse['status'] == 'INVALID') { // given data invalid
+ $oResponse->setData('errormessage', $this->addresscheck->getInvalidMessage($aResponse['customermessage']));
+ } elseif ($aResponse['status'] == 'ERROR') { // an error occured in the API
+ $oResponse = $this->handleErrorCase($oResponse);
+ }
+ return $oResponse;
+ }
+
+ /**
+ * Send addresscheck request and handle the response object
+ *
+ * @param AddresscheckResponse $oResponse
+ * @param AddressInterface $oAddress
+ * @param bool $blIsBillingAddress
+ * @return AddresscheckResponse
+ */
+ protected function handleAddresscheck(
+ AddresscheckResponse $oResponse,
+ AddressInterface $oAddress,
+ $blIsBillingAddress
+ ) {
+ $aResponse = $this->addresscheck->getResponse($oAddress, $blIsBillingAddress);
+ if (is_array($aResponse)) { // is a real response existing?
+ $this->addScoreToSession($oAddress, $blIsBillingAddress);
+ $oResponse = $this->handleResponse($oResponse, $oAddress, $aResponse);
+ } elseif ($aResponse === true) { // check lifetime still valid, set success to true
+ $oResponse->setData('success', true);
+ }
+ return $oResponse;
+ }
+
+ /**
+ * PAYONE addresscheck
+ * The full class-paths must be given here otherwise the Magento 2 WebApi
+ * cant handle this with its fake type system!
+ *
+ * @param \Magento\Quote\Api\Data\AddressInterface $addressData
+ * @param bool $isBillingAddress
+ * @param bool $isVirtual
+ * @param double $dTotal
+ * @return \Payone\Core\Model\WebApi\AddresscheckResponse
+ */
+ public function checkAddress(\Magento\Quote\Api\Data\AddressInterface $addressData, $isBillingAddress, $isVirtual, $dTotal)
+ {
+ $oResponse = $this->responseFactory->create();
+ $oResponse->setData('success', false); // set success to false as default, set to true later if true
+ if ($this->addresscheck->isCheckNeededForQuote($isBillingAddress, $isVirtual, $dTotal)) {
+ $oResponse = $this->handleAddresscheck($oResponse, $addressData, $isBillingAddress);
+ }
+ return $oResponse;
+ }
+}
diff --git a/Model/WebApi/AddresscheckResponse.php b/Model/WebApi/AddresscheckResponse.php
new file mode 100644
index 00000000..de7c1663
--- /dev/null
+++ b/Model/WebApi/AddresscheckResponse.php
@@ -0,0 +1,73 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Model\WebApi;
+
+/**
+ * Object for addresscheck WebApi response
+ */
+class AddresscheckResponse extends \Magento\Framework\Api\AbstractExtensibleObject
+{
+ /**
+ * Returns the shipping carrier title.
+ *
+ * @return bool
+ */
+ public function getSuccess()
+ {
+ return $this->_get('success');
+ }
+
+ /**
+ * Returns the corrected address
+ *
+ * @return \Magento\Quote\Api\Data\AddressInterface
+ */
+ public function getCorrectedAddress()
+ {
+ return $this->_get('correctedAddress');
+ }
+
+ /**
+ * Returns errormessage
+ *
+ * @return string
+ */
+ public function getErrormessage()
+ {
+ return $this->_get('errormessage');
+ }
+
+ /**
+ * Return confirm message
+ *
+ * @return string
+ */
+ public function getConfirmMessage()
+ {
+ return $this->_get('confirmMessage');
+ }
+}
diff --git a/Observer/AddPaypalExpressButtons.php b/Observer/AddPaypalExpressButtons.php
index 5a25b943..d39743fd 100644
--- a/Observer/AddPaypalExpressButtons.php
+++ b/Observer/AddPaypalExpressButtons.php
@@ -45,8 +45,7 @@ class AddPaypalExpressButtons implements ObserverInterface
/**
* Constructor
*
- * @param Payment $paymentHelper
- * @return void
+ * @param Payment $paymentHelper
*/
public function __construct(Payment $paymentHelper)
{
diff --git a/Observer/CheckoutSubmitBefore.php b/Observer/CheckoutSubmitBefore.php
new file mode 100644
index 00000000..c0788fd7
--- /dev/null
+++ b/Observer/CheckoutSubmitBefore.php
@@ -0,0 +1,211 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Observer;
+
+use Magento\Framework\Event\ObserverInterface;
+use Magento\Framework\Event\Observer;
+use Magento\Framework\Exception\LocalizedException;
+use Magento\Quote\Model\Quote;
+use Magento\Quote\Api\Data\AddressInterface;
+use Payone\Core\Model\Source\CreditratingIntegrationEvent as Event;
+
+/**
+ * Event class to set the orderstatus to new and pending
+ */
+class CheckoutSubmitBefore implements ObserverInterface
+{
+ /**
+ * PAYONE consumerscore request model
+ *
+ * @var \Payone\Core\Model\Api\Request\Consumerscore
+ */
+ protected $consumerscore;
+
+ /**
+ * Consumerscore helper
+ *
+ * @var \Payone\Core\Helper\Consumerscore
+ */
+ protected $consumerscoreHelper;
+
+ /**
+ * Constructor
+ *
+ * @param \Payone\Core\Model\Api\Request\Consumerscore $consumerscore
+ * @param \Payone\Core\Helper\Consumerscore $consumerscoreHelper
+ */
+ public function __construct(
+ \Payone\Core\Model\Api\Request\Consumerscore $consumerscore,
+ \Payone\Core\Helper\Consumerscore $consumerscoreHelper
+ ) {
+ $this->consumerscore = $consumerscore;
+ $this->consumerscoreHelper = $consumerscoreHelper;
+ }
+
+ /**
+ * Get parameter from config
+ *
+ * @param string $sParam
+ * @param bool $blIsAddresscheck
+ * @return string
+ */
+ protected function getConfigParam($sParam, $blIsAddresscheck = false)
+ {
+ $sGroup = 'creditrating';
+ if ($blIsAddresscheck === true) {
+ $sGroup = 'address_check';
+ }
+ return $this->consumerscoreHelper->getConfigParam($sParam, $sGroup, 'payone_protect');
+ }
+
+ /**
+ * Determine if creditrating is needed
+ *
+ * @param Quote $oQuote
+ * @return bool
+ */
+ protected function isCreditratingNeeded(Quote $oQuote)
+ {
+ if (!$this->consumerscoreHelper->isCreditratingNeeded(Event::AFTER_PAYMENT, $oQuote->getGrandTotal())) {
+ return false;
+ }
+
+ $oMethodInstance = $oQuote->getPayment()->getMethodInstance();
+ $sPaymentCode = $oMethodInstance->getCode();
+ $sPaymentTypesToCheck = $this->getConfigParam('enabled_for_payment_methods');
+ $aPaymentTypesToCheck = explode(',', $sPaymentTypesToCheck);
+ if (array_search($sPaymentCode, $aPaymentTypesToCheck) === false) {
+ return false;
+ }
+
+ if ($oMethodInstance->getInfoInstance()->getAdditionalInformation('payone_boni_agreement') === false) {
+ return false; // agreement checkbox was not checked by the customer
+ }
+
+ return true;
+ }
+
+ /**
+ * Determine if the payment type can be used with this score
+ *
+ * @param Quote $oQuote
+ * @param string $sScore
+ * @return bool
+ */
+ protected function isPaymentApplicableForScore(Quote $oQuote, $sScore)
+ {
+ if ($sScore == 'G') {
+ return true;
+ }
+
+ $sPaymentCode = $oQuote->getPayment()->getMethodInstance()->getCode();
+
+ $aYellowMethods = $this->consumerscoreHelper->getAllowedMethodsForScore('Y');
+ $aRedMethods = $this->consumerscoreHelper->getAllowedMethodsForScore('R');
+
+ if ($sScore == 'Y' && (array_search($sPaymentCode, $aYellowMethods) !== false ||
+ array_search($sPaymentCode, $aRedMethods) !== false)) {
+ return true;
+ } elseif ($sScore == 'R' && array_search($sPaymentCode, $aRedMethods) !== false) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @param array $aResponse
+ * @return bool
+ */
+ protected function checkoutNeedsToBeStopped($aResponse)
+ {
+ if (!$aResponse || (isset($aResponse['status']) && $aResponse['status'] == 'ERROR'
+ && $this->getConfigParam('handle_response_error') == 'stop_checkout')) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Filter payment methods by the creditrating result if applicable
+ *
+ * @param AddressInterface $oBilling
+ * @return void
+ * @throws LocalizedException
+ */
+ protected function getScoreByCreditrating(AddressInterface $oBilling)
+ {
+ $aResponse = $this->consumerscore->sendRequest($oBilling);
+ if ($aResponse === true) { // creditrating not executed because of a previous check
+ $this->consumerscoreHelper->copyOldStatusToNewAddress($oBilling);
+ }
+
+ if ($this->checkoutNeedsToBeStopped($aResponse)) {
+ $sErrorMsg = $this->getConfigParam('stop_checkout_message');
+ if (empty($sErrorMsg)) {
+ $sErrorMsg = 'An error occured during the credit check.';
+ }
+ throw new LocalizedException(__($sErrorMsg));
+ }
+
+ if (isset($aResponse['score'])) {
+ $oBilling->setPayoneProtectScore($aResponse['score'])->save();
+ }
+
+ $sScore = $oBilling->getPayoneProtectScore();
+ return $sScore;
+ }
+
+ /**
+ * Execute certain tasks after the payment is placed and thus the order is placed
+ *
+ * @param Observer $observer
+ * @return void
+ */
+ public function execute(Observer $observer)
+ {
+ $oQuote = $observer->getQuote();
+ $oBilling = $oQuote->getBillingAddress();
+ $oShipping = $oQuote->getShippingAddress();
+
+ $aScores = [];
+ if ($this->getConfigParam('enabled', true)) { // is addresscheck active
+ $aScores[] = $oBilling->getPayoneAddresscheckScore();
+ $aScores[] = $oShipping->getPayoneAddresscheckScore();
+ }
+
+ if ($this->isCreditratingNeeded($oQuote) === true) {
+ $aScores[] = $this->getScoreByCreditrating($oBilling);
+ }
+
+ $sScore = $this->consumerscoreHelper->getWorstScore($aScores);
+ $blSuccess = $this->isPaymentApplicableForScore($oQuote, $sScore);
+ if ($blSuccess === false) {
+ throw new LocalizedException(__('An error occured during the credit check.'));
+ }
+ }
+}
diff --git a/Observer/OrderPaymentPlaceEnd.php b/Observer/OrderPaymentPlaceEnd.php
index b4fca944..a0d9f3e2 100644
--- a/Observer/OrderPaymentPlaceEnd.php
+++ b/Observer/OrderPaymentPlaceEnd.php
@@ -1,54 +1,87 @@
-.
- *
- * PHP version 5
- *
- * @category Payone
- * @package Payone_Magento2_Plugin
- * @author FATCHIP GmbH
- * @copyright 2003 - 2016 Payone GmbH
- * @license GNU Lesser General Public License
- * @link http://www.payone.de
- */
-
-namespace Payone\Core\Observer;
-
-use Magento\Sales\Model\Order;
-use Magento\Framework\Event\ObserverInterface;
-use Magento\Framework\Event\Observer;
-
-/**
- * Event class to set the orderstatus to new and pending
- */
-class OrderPaymentPlaceEnd implements ObserverInterface
-{
- /**
- * Set order status
- *
- * @param Observer $observer
- * @return void
- */
- public function execute(Observer $observer)
- {
- $oPayment = $observer->getEvent()->getPayment();
- $oPaymentInstance = $oPayment->getMethodInstance();
- if (stripos($oPaymentInstance->getCode(), 'payone') !== false) {
- $oOrder = $oPayment->getOrder();
- $oOrder->setState(Order::STATE_NEW);
- $oOrder->setStatus($oPaymentInstance->getConfigData('order_status'));
- }
- }
-}
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Observer;
+
+use Magento\Sales\Model\Order;
+use Magento\Framework\Event\ObserverInterface;
+use Magento\Framework\Event\Observer;
+use Payone\Core\Helper\Consumerscore;
+
+/**
+ * Event class to set the orderstatus to new and pending
+ */
+class OrderPaymentPlaceEnd implements ObserverInterface
+{
+ /**
+ * PAYONE payment helper
+ *
+ * @var Consumerscore
+ */
+ protected $consumerscoreHelper;
+
+ /**
+ * Constructor
+ *
+ * @param Consumerscore $consumerscoreHelper
+ */
+ public function __construct(Consumerscore $consumerscoreHelper)
+ {
+ $this->consumerscoreHelper = $consumerscoreHelper;
+ }
+
+ /**
+ * Handle order status
+ *
+ * @param Observer $observer
+ * @return void
+ */
+ protected function handleOrderStatus(Observer $observer)
+ {
+ $oPayment = $observer->getEvent()->getPayment();
+ $oPaymentInstance = $oPayment->getMethodInstance();
+ if (stripos($oPaymentInstance->getCode(), 'payone') !== false) {
+ $oOrder = $oPayment->getOrder();
+ $oOrder->setState(Order::STATE_NEW);
+ $oOrder->setStatus($oPaymentInstance->getConfigData('order_status'));
+ }
+ }
+
+ /**
+ * Execute certain tasks after the payment is placed and thus the order is placed
+ *
+ * @param Observer $observer
+ * @return void
+ */
+ public function execute(Observer $observer)
+ {
+ // set status to new - pending on new orders
+ $this->handleOrderStatus($observer);
+
+ // increment counter for every order, needed for the A/B test feature
+ $this->consumerscoreHelper->incrementConsumerscoreSampleCounter();
+ }
+}
diff --git a/Observer/PaymentMethodAssignData.php b/Observer/PaymentMethodAssignData.php
new file mode 100644
index 00000000..8cf4b160
--- /dev/null
+++ b/Observer/PaymentMethodAssignData.php
@@ -0,0 +1,68 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Observer;
+
+use Magento\Framework\Event\ObserverInterface;
+use Magento\Framework\Event\Observer;
+use Payone\Core\Helper\Toolkit;
+
+/**
+ * Event class to set the orderstatus to new and pending
+ */
+class PaymentMethodAssignData implements ObserverInterface
+{
+ /**
+ * PAYONE toolkit helper
+ *
+ * @var \Payone\Core\Helper\Toolkit
+ */
+ protected $toolkitHelper;
+
+ /**
+ * Constructor
+ *
+ * @param Toolkit $toolkitHelper
+ */
+ public function __construct(Toolkit $toolkitHelper)
+ {
+ $this->toolkitHelper = $toolkitHelper;
+ }
+
+ /**
+ * Execute certain tasks after the payment is placed and thus the order is placed
+ *
+ * @param Observer $observer
+ * @return void
+ */
+ public function execute(Observer $observer)
+ {
+ $blBoniAgreement = $this->toolkitHelper->getAdditionalDataEntry($observer->getData('data'), 'payone_boni_agreement');
+ if ($blBoniAgreement !== null) {
+ $observer->getPaymentModel()->setAdditionalInformation('payone_boni_agreement', (bool)$blBoniAgreement);
+ }
+ }
+}
diff --git a/Setup/BaseSchema.php b/Setup/BaseSchema.php
new file mode 100644
index 00000000..c4b697e9
--- /dev/null
+++ b/Setup/BaseSchema.php
@@ -0,0 +1,65 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Setup;
+
+use Magento\Framework\Setup\SchemaSetupInterface;
+
+/**
+ * Base class for installing or updating all PAYONE specific tables
+ */
+class BaseSchema
+{
+ /**
+ * This method will add a new table into the shop database
+ *
+ * @param SchemaSetupInterface $installer
+ * @param array $aTableData
+ * @return void
+ */
+ protected function addTable(SchemaSetupInterface $installer, $aTableData)
+ {
+ $oConnection = $installer->getConnection();
+ $sRealTableName = $installer->getTable($aTableData['title']);
+ if (!$oConnection->isTableExists($sRealTableName)) {
+ $table = $oConnection->newTable($sRealTableName);
+
+ foreach ($aTableData['columns'] as $sColumnName => $aColumnData) {
+ $table->addColumn($sColumnName, $aColumnData['type'], $aColumnData['length'], $aColumnData['option']);
+ }
+
+ if (!empty($aTableData['indexes'])) {
+ foreach ($aTableData['indexes'] as $sIndex) {
+ $table->addIndex($installer->getIdxName($aTableData['title'], $sIndex), $sIndex);
+ }
+ }
+
+ $table->setComment($aTableData['comment']);
+
+ $oConnection->createTable($table);
+ }
+ }
+}
diff --git a/Setup/InstallData.php b/Setup/InstallData.php
index 9775869b..9cde266d 100644
--- a/Setup/InstallData.php
+++ b/Setup/InstallData.php
@@ -45,8 +45,7 @@ class InstallData implements \Magento\Framework\Setup\InstallDataInterface
/**
* Constructor
*
- * @param SalesSetupFactory $salesSetupFactory
- * @return void
+ * @param SalesSetupFactory $salesSetupFactory
*/
public function __construct(SalesSetupFactory $salesSetupFactory)
{
diff --git a/Setup/InstallSchema.php b/Setup/InstallSchema.php
index cd17e54b..3d032ecb 100644
--- a/Setup/InstallSchema.php
+++ b/Setup/InstallSchema.php
@@ -33,7 +33,7 @@
/**
* Class for installing all PAYONE specific tables
*/
-class InstallSchema implements InstallSchemaInterface
+class InstallSchema extends BaseSchema implements InstallSchemaInterface
{
/**
* Install method
@@ -66,32 +66,4 @@ protected function getTablesToAdd()
\Payone\Core\Setup\Tables\Transactionstatus::getData()
];
}
-
- /**
- * This method will add a new table into the shop database
- *
- * @param SchemaSetupInterface $installer
- * @param array $aTableData
- * @return void
- */
- protected function addTable(SchemaSetupInterface $installer, $aTableData)
- {
- $oConnection = $installer->getConnection();
- $sRealTableName = $installer->getTable($aTableData['title']);
- if (!$oConnection->isTableExists($sRealTableName)) {
- $table = $oConnection->newTable($sRealTableName);
-
- foreach ($aTableData['columns'] as $sColumnName => $aColumnData) {
- $table->addColumn($sColumnName, $aColumnData['type'], $aColumnData['length'], $aColumnData['option']);
- }
-
- foreach ($aTableData['indexes'] as $sIndex) {
- $table->addIndex($installer->getIdxName($aTableData['title'], $sIndex), $sIndex);
- }
-
- $table->setComment($aTableData['comment']);
-
- $oConnection->createTable($table);
- }
- }
}
diff --git a/Setup/Tables/CheckedAddresses.php b/Setup/Tables/CheckedAddresses.php
new file mode 100644
index 00000000..c88954be
--- /dev/null
+++ b/Setup/Tables/CheckedAddresses.php
@@ -0,0 +1,79 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Setup\Tables;
+
+use Magento\Framework\DB\Ddl\Table;
+
+/**
+ * Class defining the data needed to create the payone_checked_addresses table
+ */
+class CheckedAddresses
+{
+ const TABLE_CHECKED_ADDRESSES = 'payone_checked_addresses';
+
+ /**
+ * Table data needed to create the new table payone_checked_addresses
+ *
+ * @var array
+ */
+ protected static $aTableData = [
+ 'title' => self::TABLE_CHECKED_ADDRESSES,
+ 'columns' => [
+ 'id' => [
+ 'type' => Table::TYPE_INTEGER,
+ 'length' => null,
+ 'option' => ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
+ ],
+ 'address_hash' => [
+ 'type' => Table::TYPE_TEXT,
+ 'length' => 32,
+ 'option' => [],
+ ],
+ 'checkdate' => [
+ 'type' => Table::TYPE_TIMESTAMP,
+ 'length' => null,
+ 'option' => ['nullable' => false, 'default' => Table::TIMESTAMP_INIT],
+ ],
+ 'is_bonicheck' => [
+ 'type' => Table::TYPE_SMALLINT,
+ 'length' => null,
+ 'option' => ['unsigned' => true, 'nullable' => false]
+ ],
+ ],
+ 'comment' => 'Log of the checked addresses'
+ ];
+
+ /**
+ * Return the table data needed to create this table
+ *
+ * @return array
+ */
+ public static function getData()
+ {
+ return self::$aTableData;
+ }
+}
diff --git a/Setup/Tables/Transactionstatus.php b/Setup/Tables/Transactionstatus.php
index 03ad2002..2281b8a1 100644
--- a/Setup/Tables/Transactionstatus.php
+++ b/Setup/Tables/Transactionstatus.php
@@ -134,7 +134,7 @@ class Transactionstatus
'cardpan' => ['type' => Table::TYPE_TEXT, 'length' => 32, 'option' => []],
'clearing_bankaccountholder' => ['type' => Table::TYPE_TEXT, 'length' => 255, 'option' => []],
'clearing_bankaccount' => ['type' => Table::TYPE_TEXT, 'length' => 32, 'option' => []],
- 'clearing_bankcode' => ['type' => Table::TYPE_TEXT, 'length' => 32, 'option' => [],],
+ 'clearing_bankcode' => ['type' => Table::TYPE_TEXT, 'length' => 32, 'option' => []],
'clearing_bankname' => ['type' => Table::TYPE_TEXT, 'length' => 255, 'option' => []],
'clearing_bankbic' => ['type' => Table::TYPE_TEXT, 'length' => 32, 'option' => []],
'clearing_bankiban' => ['type' => Table::TYPE_TEXT, 'length' => 32, 'option' => []],
diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php
new file mode 100644
index 00000000..671b7b29
--- /dev/null
+++ b/Setup/UpgradeSchema.php
@@ -0,0 +1,75 @@
+.
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+
+namespace Payone\Core\Setup;
+
+use Magento\Framework\Setup\ModuleContextInterface;
+use Magento\Framework\Setup\SchemaSetupInterface;
+use Magento\Framework\Setup\UpgradeSchemaInterface;
+use Magento\Framework\DB\Ddl\Table;
+
+/**
+ * Magento script for updating the database after the initial installation
+ */
+class UpgradeSchema extends BaseSchema implements UpgradeSchemaInterface
+{
+ /**
+ * Upgrade method
+ *
+ * @param SchemaSetupInterface $setup
+ * @param ModuleContextInterface $context
+ * @return void
+ */
+ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
+ {
+ if (version_compare($context->getVersion(), '1.3.0', '<')) {// pre update version is lower than 1.3.0
+ $this->addTable($setup, \Payone\Core\Setup\Tables\CheckedAddresses::getData());
+
+ $setup->getConnection()->addColumn(
+ $setup->getTable('quote_address'),
+ 'payone_addresscheck_score',
+ [
+ 'type' => Table::TYPE_TEXT,
+ 'length' => 1,
+ 'nullable' => false,
+ 'default' => '',
+ 'comment' => 'AddressCheck Person Status Score (G, Y, R)'
+ ]
+ );
+ $setup->getConnection()->addColumn(
+ $setup->getTable('quote_address'),
+ 'payone_protect_score',
+ [
+ 'type' => Table::TYPE_TEXT,
+ 'length' => 1,
+ 'nullable' => false,
+ 'default' => '',
+ 'comment' => 'Consumerscore Status Score (G, Y, R)'
+ ]
+ );
+ }
+ }
+}
diff --git a/Ui/Component/Listing/Column/ViewAction.php b/Ui/Component/Listing/Column/ViewAction.php
index 2097127e..abe57dd8 100644
--- a/Ui/Component/Listing/Column/ViewAction.php
+++ b/Ui/Component/Listing/Column/ViewAction.php
@@ -46,12 +46,11 @@ class ViewAction extends Column
/**
* Constructor
*
- * @param ContextInterface $context
- * @param UiComponentFactory $uiComponentFactory
- * @param UrlInterface $urlBuilder
- * @param array $components
- * @param array $data
- * @return void
+ * @param ContextInterface $context
+ * @param UiComponentFactory $uiComponentFactory
+ * @param UrlInterface $urlBuilder
+ * @param array $components
+ * @param array $data
*/
public function __construct(
ContextInterface $context,
diff --git a/etc/adminhtml/menu.xml b/etc/adminhtml/menu.xml
index 0ee2cbe9..5a1e6340 100644
--- a/etc/adminhtml/menu.xml
+++ b/etc/adminhtml/menu.xml
@@ -31,7 +31,8 @@
-
+
+
diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml
index 07174d3a..cdc5d12b 100644
--- a/etc/adminhtml/system.xml
+++ b/etc/adminhtml/system.xml
@@ -226,7 +226,169 @@
-
+
+
+ payone
+ Payone_Core::payone_configuration_protect
+
+
+
+
+ Magento\Config\Model\Config\Source\Yesno
+
+
+
+ Payone\Core\Model\Source\Mode
+
+
+
+ Payone\Core\Model\Source\AddressCheckType
+
+
+
+ Payone\Core\Model\Source\AddressCheckType
+
+
+
+ Magento\Config\Model\Config\Source\Yesno
+
+
+
+ Consumer must confirm corrections to their address
+ Magento\Config\Model\Config\Source\Yesno
+
+
+
+ Payone\Core\Block\Adminhtml\Config\Form\Field\PersonStatusMapping
+ Magento\Config\Model\Config\Backend\Serialized\ArraySerialized
+
+
+
+ Placeholder: {{payone_customermessage}} (Message from Payone-Addresscheck
+
+
+
+ Action in case Addresscheck responds with ERROR
+ Payone\Core\Model\Source\HandleResponseError
+
+
+
+
+ stop_checkout
+
+
+
+
+
+
+
+
+
+
+ Result lifetime in days
+
+
+
+
+
+
+ Magento\Config\Model\Config\Source\Yesno
+
+
+
+ Payone\Core\Model\Source\Mode
+
+
+
+ Payone\Core\Model\Source\CreditratingIntegrationEvent
+
+
+
+
+ after_payment
+
+ Magento\Payment\Model\Config\Source\Allmethods
+
+
+
+
+ after_payment
+
+ Magento\Config\Model\Config\Source\Yesno
+
+
+
+
+ after_payment
+ 1
+
+
+
+
+
+ after_payment
+
+ Magento\Config\Model\Config\Source\Yesno
+
+
+
+
+ after_payment
+ 1
+
+
+
+
+ Payone\Core\Model\Source\CreditratingCheckType
+
+
+
+ Payone\Core\Model\Source\AddressCheckType
+
+
+
+ Magento\Payment\Model\Config\Source\Allmethods
+
+
+
+ Magento\Payment\Model\Config\Source\Allmethods
+
+
+
+ Activate to perform Creditrating check every n-th order
+ Magento\Config\Model\Config\Source\Yesno
+
+
+
+ Perform creditrating for 1 out of n orders.
+
+ 1
+
+
+
+
+ Action in case Creditrating check responds with ERROR
+ Payone\Core\Model\Source\HandleResponseError
+
+
+
+
+ stop_checkout
+
+
+
+
+
+
+
+
+
+
+ Result lifetime in days
+
+
+
+
payone
Payone_Core::payone_configuration_misc
diff --git a/etc/config.xml b/etc/config.xml
index 83049138..d85f526f 100644
--- a/etc/config.xml
+++ b/etc/config.xml
@@ -215,6 +215,44 @@
a:30:{s:11:"Number_type";s:3:"tel";s:12:"Number_count";s:2:"30";s:10:"Number_max";s:2:"16";s:13:"Number_iframe";s:8:"standard";s:12:"Number_style";s:8:"standard";s:8:"CVC_type";s:3:"tel";s:9:"CVC_count";s:2:"30";s:7:"CVC_max";s:1:"4";s:10:"CVC_iframe";s:8:"standard";s:9:"CVC_style";s:8:"standard";s:10:"Month_type";s:6:"select";s:11:"Month_count";s:1:"3";s:9:"Month_max";s:1:"2";s:12:"Month_iframe";s:6:"custom";s:11:"Month_width";s:5:"120px";s:12:"Month_height";s:4:"20px";s:11:"Month_style";s:8:"standard";s:9:"Year_type";s:6:"select";s:10:"Year_count";s:1:"5";s:8:"Year_max";s:1:"4";s:11:"Year_iframe";s:6:"custom";s:10:"Year_width";s:5:"120px";s:11:"Year_height";s:4:"20px";s:10:"Year_style";s:8:"standard";s:14:"Standard_input";s:108:"width:223px;height:30px;padding: 0 9px;font-size:14px;font-family:'Helvetica Neue',Verdana,Arial,sans-serif;";s:18:"Standard_selection";s:12:"width:100px;";s:12:"Iframe_width";s:5:"365px";s:13:"Iframe_height";s:4:"30px";s:13:"Errors_active";s:5:"false";s:11:"Errors_lang";s:2:"de";}
+
+
+ 0
+ live
+ NO
+ NO
+ 0
+ 0
+
+
+ continue_checkout
+
+
+
+
+
+
+ 0
+ live
+ before_payment
+
+ 0
+
+ 0
+
+ IH
+ NO
+
+
+ 0
+
+ continue_checkout
+
+
+
+
+
+
1
diff --git a/etc/di.xml b/etc/di.xml
index 11a0a978..5f647e41 100644
--- a/etc/di.xml
+++ b/etc/di.xml
@@ -55,4 +55,13 @@
+
+
+
+
+
+
+
+
+
diff --git a/etc/events.xml b/etc/events.xml
index 26c65bb6..d8b69a8b 100644
--- a/etc/events.xml
+++ b/etc/events.xml
@@ -28,4 +28,10 @@
+
+
+
+
+
+
diff --git a/etc/module.xml b/etc/module.xml
index 8be4c84d..2702186f 100644
--- a/etc/module.xml
+++ b/etc/module.xml
@@ -25,5 +25,5 @@
*/
-->
-
+
diff --git a/etc/webapi.xml b/etc/webapi.xml
new file mode 100644
index 00000000..d533531c
--- /dev/null
+++ b/etc/webapi.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ %cart_id%
+
+
+
diff --git a/i18n/de_DE.csv b/i18n/de_DE.csv
index a0924c20..17143f8b 100644
--- a/i18n/de_DE.csv
+++ b/i18n/de_DE.csv
@@ -142,6 +142,7 @@
"Credit rating","Bonitätsprüfung"
"Creditrating-Checktype","Bonitätscheck-Typ"
+"Combine credit rating with address check","Bonitätsprüfung mit Adressprüfung verbinden"
"Infoscore (hard criteria)","Infoscore (Harte Merkmale)"
"Infoscore (all criteria)","Infoscore (Alle Merkmale)"
"Infoscore (all criteria with boni-score)","Infoscore (Alle Merkmale + Boniscore)"
@@ -461,14 +462,6 @@
"ADDRESS_CORRECTABLE","Adresse korigierbar"
"ADDRESS_NONE_CORRECTABLE","Adresse nicht korigierbar"
-"PPB","Vor- & Nachname bekannt (PPB)"
-"PHB","Nachname bekannt (PHB)"
-"PAB","Vor- & Nachname nicht bekannt (PAB)"
-"PKI","Mehrdeutigkeit bei Name zu Anschrift (PKI)"
-"PNZ","Nicht zustellbar (PNZ)"
-"PPV","Person verstorben (PPV)"
-"PPF","Adresse postalisch falsch (PPF)"
-
"DEBITPAYMENT","Lastschrift"
"CREDITCARD","Kreditkarte"
"ADVANCEPAYMENT","Vorkasse"
@@ -1013,3 +1006,15 @@
"(DD.MM.YYYY)","(TT.MM.YYYY)"
"SEPA debit note","SEPA-Lastschrift"
+
+"NONE","Keine Prüfung der Adressdaten durchgeführt (NONE)"
+"PPB","Vor- & Nachname bekannt (PPB)"
+"PHB","Nachname bekannt (PHB)"
+"PAB","Vor- & Nachname nicht bekannt (PAB)"
+"PKI","Mehrdeutigkeit bei Name zu Anschrift (PKI)"
+"PNZ","Nicht zustellbar (PNZ)"
+"PPV","Person verstorben (PPV)"
+"PPF","Adresse postalisch falsch (PPF)"
+"PUG","Adresse postalisch korrekt, aber Gebäude unbekannt (PUG)"
+"PUZ","Person ist umgezogen, Adresse nicht korrigiert (PUZ)"
+"UKN","Unbekannte Rückgabewerte werden mit UKN abgebildet (UKN)"
diff --git a/i18n/en_US.csv b/i18n/en_US.csv
index 2c626ea3..dac5b8e7 100644
--- a/i18n/en_US.csv
+++ b/i18n/en_US.csv
@@ -27,3 +27,15 @@
"FCPO_CC_ROW_CC_CVC","CVC security code"
"FCPO_CC_ROW_CC_Month","Validity-month"
"FCPO_CC_ROW_CC_Year","Validity-year"
+
+"NONE","No verification of personal data carried out (NONE)"
+"PPB","First- & lastname is known (PPB)"
+"PHB","Lastname is known (PHB)"
+"PAB","First name & surname unknown (PAB)"
+"PKI","Ambiguity in name and address (PKI)"
+"PNZ","Cannot be delivered (any longer) (PNZ)"
+"PPV","Person deceased (PPV)"
+"PPF","Postal address details incorrect (PPF)"
+"PUG","Postal address details correct but building unknown (PUG)"
+"PUZ","Person has moved, address not corrected (PUZ)"
+"UKN","Unknown return values are mapped to UKN (UKN)"
diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml
index 25a44467..f694adc7 100644
--- a/view/frontend/layout/checkout_index_index.xml
+++ b/view/frontend/layout/checkout_index_index.xml
@@ -39,6 +39,17 @@
-
-
-
+
-
+
-
+
-
+
- Payone_Core/js/view/boni-agreement
+ - 200
+ - beforeMethods
+ - beforeMethods
+ - checkoutProvider
+
+
+
-
-
-
diff --git a/view/frontend/requirejs-config.js b/view/frontend/requirejs-config.js
new file mode 100644
index 00000000..29dc94fb
--- /dev/null
+++ b/view/frontend/requirejs-config.js
@@ -0,0 +1,40 @@
+/**
+ * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with PAYONE Magento 2 Connector. If not, see .
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+/*jshint browser:true jquery:true*/
+/*global alert*/
+var config = {
+ config: {
+ mixins: {
+ 'Magento_Checkout/js/view/shipping': {
+ 'Payone_Core/js/view/shipping-mixin': true
+ },
+ 'Magento_Checkout/js/view/billing-address': {
+ 'Payone_Core/js/view/billing-address-mixin': true
+ },
+ 'Magento_Checkout/js/view/payment/default': {
+ 'Payone_Core/js/view/payment/default-mixin': true
+ }
+ }
+ }
+};
diff --git a/view/frontend/web/js/action/addresscheck.js b/view/frontend/web/js/action/addresscheck.js
new file mode 100644
index 00000000..1e1d4259
--- /dev/null
+++ b/view/frontend/web/js/action/addresscheck.js
@@ -0,0 +1,81 @@
+/**
+ * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with PAYONE Magento 2 Connector. If not, see .
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+/*jshint browser:true jquery:true*/
+/*global alert*/
+define([
+ 'jquery',
+ 'Magento_Checkout/js/model/url-builder',
+ 'mage/storage',
+ 'Magento_Checkout/js/model/full-screen-loader',
+ 'Magento_Checkout/js/model/quote',
+ 'Magento_Customer/js/model/customer'
+], function ($, urlBuilder, storage, fullScreenLoader, quote, customer) {
+ 'use strict';
+
+ /** Override default place order action and add agreement_ids to request */
+ return function (addressData, isBillingAddress, baseView, type) {
+ var serviceUrl;
+
+ if (!customer.isLoggedIn()) {
+ serviceUrl = urlBuilder.createUrl('/guest-carts/:quoteId/payone-addresscheck', {
+ quoteId: quote.getQuoteId()
+ });
+ } else {
+ serviceUrl = urlBuilder.createUrl('/carts/mine/payone-addresscheck', {});
+ }
+ var request = {
+ addressData: addressData,
+ isBillingAddress: isBillingAddress,
+ isVirtual: quote.isVirtual(),
+ dTotal: window.checkoutConfig.quoteData.subtotal
+ };
+
+ fullScreenLoader.startLoader();
+
+ return storage.post(
+ serviceUrl,
+ JSON.stringify(request)
+ ).done(
+ function (response) {
+ if (response.success == true) {
+ if (response.corrected_address != null) {
+ if (!window.checkoutConfig.payment.payone.addresscheckConfirmCorrection || confirm(response.confirm_message)) {
+ baseView.payoneUpdateAddress(response.corrected_address);
+ }
+ }
+ baseView.payoneContinue(type);
+ } else {
+ alert(response.errormessage);
+ }
+ fullScreenLoader.stopLoader();
+ }
+ ).fail(
+ function (response) {
+ //errorProcessor.process(response, messageContainer);
+ alert('An error occured.');
+ fullScreenLoader.stopLoader();
+ }
+ );
+ };
+});
diff --git a/view/frontend/web/js/view/billing-address-mixin.js b/view/frontend/web/js/view/billing-address-mixin.js
new file mode 100644
index 00000000..c5ec7392
--- /dev/null
+++ b/view/frontend/web/js/view/billing-address-mixin.js
@@ -0,0 +1,68 @@
+/**
+ * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with PAYONE Magento 2 Connector. If not, see .
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+/*jshint browser:true jquery:true*/
+/*global alert*/
+define([
+ 'jquery',
+ 'Payone_Core/js/action/addresscheck'
+], function ($, addresscheck) {
+ 'use strict';
+
+ var mixin = {
+ payoneCheckAddress: function () {
+ if (window.checkoutConfig.payment.payone.addresscheckEnabled && window.checkoutConfig.payment.payone.addresscheckBillingEnabled) {
+ return true;
+ }
+ return false;
+ },
+ updateAddress: function () {
+ if (!(this.selectedAddress() && this.selectedAddress() != this.newAddressOption) && !this.payoneCheckAddress()) {
+ return this._super();
+ }
+
+ var addressChecked = this.source.get('payone_address_checked');
+ if (!addressChecked) {
+ addresscheck(this.source.get(this.dataScopePrefix), true, this, 'saveNewAddress');
+ } else {
+ this.source.set('payone_address_checked', false);
+ return this._super();
+ }
+ },
+ payoneUpdateAddress: function (addressData) {
+ this.source.set(this.dataScopePrefix + '.firstname', addressData.firstname);
+ this.source.set(this.dataScopePrefix + '.lastname', addressData.lastname);
+ this.source.set(this.dataScopePrefix + '.street.0', addressData.street[0]);
+ this.source.set(this.dataScopePrefix + '.postcode', addressData.postcode);
+ this.source.set(this.dataScopePrefix + '.city', addressData.city);
+ },
+ payoneContinue: function () {
+ this.source.set('payone_address_checked', true);
+ this.updateAddress();
+ }
+ }
+
+ return function (billing_address) {
+ return billing_address.extend(mixin);
+ };
+});
diff --git a/view/frontend/web/js/view/boni-agreement.js b/view/frontend/web/js/view/boni-agreement.js
new file mode 100644
index 00000000..8e540fac
--- /dev/null
+++ b/view/frontend/web/js/view/boni-agreement.js
@@ -0,0 +1,58 @@
+/**
+ * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with PAYONE Magento 2 Connector. If not, see .
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+define(
+ [
+ 'ko',
+ 'jquery',
+ 'uiComponent'
+ ],
+ function (ko, $, Component) {
+ 'use strict';
+
+ return Component.extend({
+ defaults: {
+ template: 'Payone_Core/payment/boni-agreement'
+ },
+
+ isVisible: function () {
+ if (this.canShowPaymentHintText() || this.canShowAgreementMessage()) {
+ return true;
+ }
+ return false;
+ },
+ canShowPaymentHintText: function () {
+ return window.checkoutConfig.payment.payone.canShowPaymentHintText;
+ },
+ getPaymentHintText: function () {
+ return window.checkoutConfig.payment.payone.paymentHintText;
+ },
+ canShowAgreementMessage: function () {
+ return window.checkoutConfig.payment.payone.canShowAgreementMessage;
+ },
+ getAgreementMessage: function () {
+ return window.checkoutConfig.payment.payone.agreementMessage;
+ }
+ });
+ }
+);
diff --git a/view/frontend/web/js/view/payment/default-mixin.js b/view/frontend/web/js/view/payment/default-mixin.js
new file mode 100644
index 00000000..37593fdc
--- /dev/null
+++ b/view/frontend/web/js/view/payment/default-mixin.js
@@ -0,0 +1,52 @@
+/**
+ * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with PAYONE Magento 2 Connector. If not, see .
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+/*jshint browser:true jquery:true*/
+/*global alert*/
+define([
+ 'jquery'
+], function ($) {
+ 'use strict';
+
+ var mixin = {
+ getData: function () {
+ var parentReturn = this._super();
+ if ($('#payone_boni_agreement') && $('#payone_boni_agreement')[0]) {
+ var blAgreed = false;
+ if ($('#payone_boni_agreement')[0].checked) {
+ blAgreed = true;
+ }
+
+ if (parentReturn.additional_data === null) {
+ parentReturn.additional_data = {};
+ }
+ parentReturn.additional_data.payone_boni_agreement = blAgreed;
+ }
+ return parentReturn;
+ }
+ }
+
+ return function (payment) {
+ return payment.extend(mixin);
+ };
+});
diff --git a/view/frontend/web/js/view/payment/method-renderer/creditcard-method.js b/view/frontend/web/js/view/payment/method-renderer/creditcard-method.js
index 6f39289f..9e342256 100644
--- a/view/frontend/web/js/view/payment/method-renderer/creditcard-method.js
+++ b/view/frontend/web/js/view/payment/method-renderer/creditcard-method.js
@@ -51,14 +51,14 @@ define(
},
getData: function () {
- return {
- 'method': this.item.method,
- 'additional_data': {
- 'firstname': this.firstname(),
- 'lastname': this.lastname(),
- 'pseudocardpan': document.getElementById(this.getCode() + '_pseudocardpan').value
- }
- };
+ var parentReturn = this._super();
+ if (parentReturn.additional_data === null) {
+ parentReturn.additional_data = {};
+ }
+ parentReturn.additional_data.firstname = this.firstname();
+ parentReturn.additional_data.lastname = this.lastname();
+ parentReturn.additional_data.pseudocardpan = document.getElementById(this.getCode() + '_pseudocardpan').value;
+ return parentReturn;
},
handleIframes: function () {
@@ -142,7 +142,7 @@ define(
// PayOne Request if the data is valid
if (window.iframes.isComplete()) {
window.ccjs = this;
- window.iframes.creditCardCheck('processPayoneResponseCCHosted');// Perform "CreditCardCheck" to create and get a
+ window.iframes.creditCardCheck('processPayoneResponseCCHosted'); // Perform "CreditCardCheck" to create and get a
// PseudoCardPan; then call your function "payCallback"
fullScreenLoader.startLoader();
} else {
diff --git a/view/frontend/web/js/view/payment/method-renderer/debit-method.js b/view/frontend/web/js/view/payment/method-renderer/debit-method.js
index 2c0ccec6..fb2fb7a4 100644
--- a/view/frontend/web/js/view/payment/method-renderer/debit-method.js
+++ b/view/frontend/web/js/view/payment/method-renderer/debit-method.js
@@ -110,14 +110,15 @@ define(
if (this.requestBic() == 1) {
document.getElementById(this.getCode() + '_bic').value = this.getCleanedNumber(this.bic());
}
- return {
- 'method': this.item.method,
- 'additional_data': {
- 'bank_country': this.bankCountry(),
- 'iban': this.getCleanedNumber(this.iban()),
- 'bic': this.getCleanedNumber(this.bic())
- }
- };
+
+ var parentReturn = this._super();
+ if (parentReturn.additional_data === null) {
+ parentReturn.additional_data = {};
+ }
+ parentReturn.additional_data.bank_country = this.bankCountry();
+ parentReturn.additional_data.iban = this.getCleanedNumber(this.iban());
+ parentReturn.additional_data.bic = this.getCleanedNumber(this.bic());
+ return parentReturn;
},
isManageMandateActive: function () {
@@ -128,7 +129,7 @@ define(
},
processPayoneResponseELV: function (response) {
if (response.get('status') === "VALID") {
- window.checkoutConfig.payment.payone.bankCodeValidatedAndValid == true;
+ window.checkoutConfig.payment.payone.bankCodeValidatedAndValid = true;
this.selectPaymentMethod();
handleDebitAction(this.getData(), this.messageContainer);
} else if (true || response.get('status') === "BLOCKED") {
diff --git a/view/frontend/web/js/view/payment/method-renderer/klarna-method.js b/view/frontend/web/js/view/payment/method-renderer/klarna-method.js
index 7db990ff..38586f78 100644
--- a/view/frontend/web/js/view/payment/method-renderer/klarna-method.js
+++ b/view/frontend/web/js/view/payment/method-renderer/klarna-method.js
@@ -55,26 +55,26 @@ define(
return this;
},
requestTelephone: function () {
- if (typeof quote.billingAddress().telephone != 'undefined' && quote.billingAddress().telephone != '') {
+ if (quote.billingAddress() != null && typeof quote.billingAddress().telephone != 'undefined' && quote.billingAddress().telephone != '') {
return false;
}
return true;
},
requestAddressAddInfo: function () {
- if (typeof quote.billingAddress().countryId != 'undefined' && quote.billingAddress().countryId != 'NL') {
+ if (quote.billingAddress() != null && typeof quote.billingAddress().countryId != 'undefined' && quote.billingAddress().countryId != 'NL') {
return false;
}
return true;
},
requestDelAddressAddInfo: function () {
- if (typeof quote.billingAddress().countryId != 'undefined' && quote.billingAddress().countryId != 'NL') {
+ if (quote.billingAddress() != null && typeof quote.billingAddress().countryId != 'undefined' && quote.billingAddress().countryId != 'NL') {
return false;
}
return true;
},
requestGender: function () {
var aTriggerCountries = ['DE', 'NL', 'AT'];
- if (typeof quote.billingAddress().countryId != 'undefined' && aTriggerCountries.indexOf(quote.billingAddress().countryId) != -1) {
+ if (quote.billingAddress() != null && typeof quote.billingAddress().countryId != 'undefined' && aTriggerCountries.indexOf(quote.billingAddress().countryId) != -1) {
if (window.checkoutConfig.payment.payone.customerHasGivenGender == false) {
return true;
}
@@ -83,14 +83,14 @@ define(
},
requestPersonalId: function () {
var aTriggerCountries = ['DK', 'FI', 'NO', 'SE'];
- if (typeof quote.billingAddress().countryId != 'undefined' && aTriggerCountries.indexOf(quote.billingAddress().countryId) != -1) {
+ if (quote.billingAddress() != null && typeof quote.billingAddress().countryId != 'undefined' && aTriggerCountries.indexOf(quote.billingAddress().countryId) != -1) {
return true;
}
return false;
},
requestBirthday: function () {
var aTriggerCountries = ['DE', 'NL', 'AT'];
- if (typeof quote.billingAddress().countryId != 'undefined' && aTriggerCountries.indexOf(quote.billingAddress().countryId) != -1) {
+ if (quote.billingAddress() != null && typeof quote.billingAddress().countryId != 'undefined' && aTriggerCountries.indexOf(quote.billingAddress().countryId) != -1) {
if (window.checkoutConfig.payment.payone.customerHasGivenBirthday == false) {
return true;
}
@@ -99,19 +99,19 @@ define(
},
getData: function () {
- return {
- 'method': this.item.method,
- 'additional_data': {
- 'telephone': this.telephone(),
- 'addinfo': this.addinfo(),
- 'del_addinfo': this.delAddinfo(),
- 'gender': this.gender(),
- 'personal_id': this.personalId(),
- 'birthday': this.birthday(),
- 'birthmonth': this.birthmonth(),
- 'birthyear': this.birthyear()
- }
- };
+ var parentReturn = this._super();
+ if (parentReturn.additional_data === null) {
+ parentReturn.additional_data = {};
+ }
+ parentReturn.additional_data.telephone = this.telephone();
+ parentReturn.additional_data.addinfo = this.addinfo();
+ parentReturn.additional_data.del_addinfo = this.delAddinfo();
+ parentReturn.additional_data.gender = this.gender();
+ parentReturn.additional_data.personal_id = this.personalId();
+ parentReturn.additional_data.birthday = this.birthday();
+ parentReturn.additional_data.birthmonth = this.birthmonth();
+ parentReturn.additional_data.birthyear = this.birthyear();
+ return parentReturn;
},
/** Returns payment method instructions */
diff --git a/view/frontend/web/js/view/payment/method-renderer/obt_eps-method.js b/view/frontend/web/js/view/payment/method-renderer/obt_eps-method.js
index 234e7092..4e9814d3 100644
--- a/view/frontend/web/js/view/payment/method-renderer/obt_eps-method.js
+++ b/view/frontend/web/js/view/payment/method-renderer/obt_eps-method.js
@@ -42,12 +42,12 @@ define(
},
getData: function () {
- return {
- 'method': this.item.method,
- 'additional_data': {
- 'bank_group': this.bankGroup()
- }
- };
+ var parentReturn = this._super();
+ if (parentReturn.additional_data === null) {
+ parentReturn.additional_data = {};
+ }
+ parentReturn.additional_data.bank_group = this.bankGroup();
+ return parentReturn;
},
/** Returns payment method instructions */
diff --git a/view/frontend/web/js/view/payment/method-renderer/obt_giropay-method.js b/view/frontend/web/js/view/payment/method-renderer/obt_giropay-method.js
index ad21b3f6..540d34d2 100644
--- a/view/frontend/web/js/view/payment/method-renderer/obt_giropay-method.js
+++ b/view/frontend/web/js/view/payment/method-renderer/obt_giropay-method.js
@@ -25,10 +25,9 @@ define(
[
'Payone_Core/js/view/payment/method-renderer/base',
'Magento_Ui/js/model/messageList',
- 'mage/translate',
- 'Payone_Core/js/action/handle-debit'
+ 'mage/translate'
],
- function (Component, messageList, $t, handleDebitAction) {
+ function (Component, messageList, $t) {
'use strict';
return Component.extend({
defaults: {
@@ -80,13 +79,14 @@ define(
getData: function () {
document.getElementById(this.getCode() + '_iban').value = this.getCleanedNumber(this.iban());
document.getElementById(this.getCode() + '_bic').value = this.getCleanedNumber(this.bic());
- return {
- 'method': this.item.method,
- 'additional_data': {
- 'iban': this.getCleanedNumber(this.iban()),
- 'bic': this.getCleanedNumber(this.bic())
- }
- };
+
+ var parentReturn = this._super();
+ if (parentReturn.additional_data === null) {
+ parentReturn.additional_data = {};
+ }
+ parentReturn.additional_data.iban = this.getCleanedNumber(this.iban());
+ parentReturn.additional_data.bic = this.getCleanedNumber(this.bic());
+ return parentReturn;
}
});
}
diff --git a/view/frontend/web/js/view/payment/method-renderer/obt_ideal-method.js b/view/frontend/web/js/view/payment/method-renderer/obt_ideal-method.js
index 9b15fbe5..e3a241b9 100644
--- a/view/frontend/web/js/view/payment/method-renderer/obt_ideal-method.js
+++ b/view/frontend/web/js/view/payment/method-renderer/obt_ideal-method.js
@@ -42,12 +42,12 @@ define(
},
getData: function () {
- return {
- 'method': this.item.method,
- 'additional_data': {
- 'bank_group': this.bankGroup()
- }
- };
+ var parentReturn = this._super();
+ if (parentReturn.additional_data === null) {
+ parentReturn.additional_data = {};
+ }
+ parentReturn.additional_data.bank_group = this.bankGroup();
+ return parentReturn;
},
/** Returns payment method instructions */
diff --git a/view/frontend/web/js/view/payment/method-renderer/obt_sofortueberweisung-method.js b/view/frontend/web/js/view/payment/method-renderer/obt_sofortueberweisung-method.js
index efeb446d..0830fe31 100644
--- a/view/frontend/web/js/view/payment/method-renderer/obt_sofortueberweisung-method.js
+++ b/view/frontend/web/js/view/payment/method-renderer/obt_sofortueberweisung-method.js
@@ -25,10 +25,9 @@ define(
[
'Payone_Core/js/view/payment/method-renderer/base',
'Magento_Ui/js/model/messageList',
- 'mage/translate',
- 'Payone_Core/js/action/handle-debit'
+ 'mage/translate'
],
- function (Component, messageList, $t, handleDebitAction) {
+ function (Component, messageList, $t) {
'use strict';
return Component.extend({
defaults: {
@@ -80,13 +79,14 @@ define(
getData: function () {
document.getElementById(this.getCode() + '_iban').value = this.getCleanedNumber(this.iban());
document.getElementById(this.getCode() + '_bic').value = this.getCleanedNumber(this.bic());
- return {
- 'method': this.item.method,
- 'additional_data': {
- 'iban': this.getCleanedNumber(this.iban()),
- 'bic': this.getCleanedNumber(this.bic())
- }
- };
+
+ var parentReturn = this._super();
+ if (parentReturn.additional_data === null) {
+ parentReturn.additional_data = {};
+ }
+ parentReturn.additional_data.iban = this.getCleanedNumber(this.iban());
+ parentReturn.additional_data.bic = this.getCleanedNumber(this.bic());
+ return parentReturn;
}
});
}
diff --git a/view/frontend/web/js/view/shipping-mixin.js b/view/frontend/web/js/view/shipping-mixin.js
new file mode 100644
index 00000000..6b9701ac
--- /dev/null
+++ b/view/frontend/web/js/view/shipping-mixin.js
@@ -0,0 +1,87 @@
+/**
+ * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with PAYONE Magento 2 Connector. If not, see .
+ *
+ * PHP version 5
+ *
+ * @category Payone
+ * @package Payone_Magento2_Plugin
+ * @author FATCHIP GmbH
+ * @copyright 2003 - 2016 Payone GmbH
+ * @license GNU Lesser General Public License
+ * @link http://www.payone.de
+ */
+/*jshint browser:true jquery:true*/
+/*global alert*/
+define([
+ 'jquery',
+ 'Payone_Core/js/action/addresscheck'
+], function ($, addresscheck) {
+ 'use strict';
+
+ var mixin = {
+ payoneCheckAddress: function () {
+ if (window.checkoutConfig.payment.payone.addresscheckEnabled && window.checkoutConfig.payment.payone.addresscheckShippingEnabled) {
+ return true;
+ }
+ return false;
+ },
+ saveNewAddress: function () {
+ if (!this.payoneCheckAddress()) {
+ return this._super();
+ }
+
+ var addressChecked = this.source.get('payone_address_checked');
+ if (!addressChecked) {
+ addresscheck(this.source.get('shippingAddress'), false, this, 'saveNewAddress');
+ } else {
+ this.source.set('payone_address_checked', false);
+ return this._super();
+ }
+ },
+ payoneUpdateAddress: function (addressData) {
+ this.source.set('shippingAddress.postcode', addressData.postcode);
+ this.source.set('shippingAddress.firstname', addressData.firstname);
+ this.source.set('shippingAddress.lastname', addressData.lastname);
+ this.source.set('shippingAddress.street.0', addressData.street[0]);
+ this.source.set('shippingAddress.city', addressData.city);
+ },
+ payoneContinue: function (sType) {
+ if (sType == 'saveNewAddress') {
+ this.source.set('payone_address_checked', true);
+ this.saveNewAddress();
+ } else if (sType == 'setShippingInformation') {
+ this.source.set('payone_guest_address_checked', true);
+ this.setShippingInformation();
+ }
+ },
+ setShippingInformation: function () {
+ if (!this.isFormInline || !this.payoneCheckAddress()) {
+ return this._super();
+ }
+
+ if (!this.source.get('payone_guest_address_checked')) {
+ if (this.validateShippingInformation()) {
+ addresscheck(this.source.get('shippingAddress'), false, this, 'setShippingInformation');
+ }
+ } else {
+ this.source.set('payone_guest_address_checked', false);
+ return this._super();
+ }
+ }
+ }
+
+ return function (shipping) {
+ return shipping.extend(mixin);
+ };
+});
diff --git a/view/frontend/web/template/payment/boni-agreement.html b/view/frontend/web/template/payment/boni-agreement.html
new file mode 100644
index 00000000..68063c12
--- /dev/null
+++ b/view/frontend/web/template/payment/boni-agreement.html
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file