Skip to content

Commit

Permalink
Merge pull request #10 from wirecard/masterUpdate
Browse files Browse the repository at this point in the history
Master update
  • Loading branch information
rinnhofer authored Aug 16, 2017
2 parents b13dfc7 + e07ff4d commit e07ca3c
Show file tree
Hide file tree
Showing 25 changed files with 69 additions and 248 deletions.
25 changes: 25 additions & 0 deletions Block/Checkout/Script.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ class Script extends Template
*/
protected $_dataStorageHelper;

/**
* @var \Wirecard\CheckoutSeamless\Helper\Data
*/
protected $_dataHelper;

/**
* @var \Magento\Quote\Model\Quote
*/
protected $_checkoutSession;

/**
* Constructor
Expand All @@ -53,14 +62,30 @@ class Script extends Template
public function __construct(
Template\Context $context,
\Wirecard\CheckoutSeamless\Helper\DataStorage $helper,
\Magento\Checkout\Model\Session $checkoutSession,
\Wirecard\CheckoutSeamless\Helper\Data $dataHelper,
array $data = []
) {
parent::__construct($context, $data);
$this->_dataStorageHelper = $helper;
$this->_checkoutSession = $checkoutSession;
$this->_dataHelper = $dataHelper;
}

public function getDataStorageUrl()
{
return $this->_dataStorageHelper->init();
}

public function getConsumerDeviceId()
{
if (!strlen($this->_checkoutSession->getData('consumerDeviceId'))) {
$customerId = $this->_dataHelper->getConfigArray()['CUSTOMER_ID'];
$consumerDeviceId = md5($customerId . "_" . microtime());

$this->_checkoutSession->setData('consumerDeviceId', $consumerDeviceId);
}

return $this->_checkoutSession->getData('consumerDeviceId');
}
}
76 changes: 7 additions & 69 deletions Model/AbstractPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public function initPaymentByCart(CheckoutCart $cart, $urls, \Magento\Framework\
$init->setConfirmUrl($urls['confirm']);

$quote->reserveOrderId();
$checkoutSession = $cart->getCheckoutSession();
$quote->save();

$orderId = $quote->getReservedOrderId();
Expand All @@ -170,13 +171,18 @@ public function initPaymentByCart(CheckoutCart $cart, $urls, \Magento\Framework\
->setFailureUrl($returnUrl)
->setServiceUrl($this->_dataHelper->getConfigData('options/service_url'))
->setConsumerData($this->_getConsumerData($quote))
->setStorageid($this->_dataStorageHelper->getStorageId())
->setStorageId($this->_dataStorageHelper->getStorageId())
->setOrderIdent($quote->getId());

$init->mage_orderId = $orderId;
$init->mage_quoteId = $quote->getId();
$init->mage_orderCreation = $this->_dataHelper->getConfigData('options/order_creation');

if (strlen($checkoutSession->getData('consumerDeviceId'))) {
$init->consumerDeviceId = $checkoutSession->getData('consumerDeviceId');
$checkoutSession->unsetData('consumerDeviceId');
}

$init->generateCustomerStatement($this->_dataHelper->getConfigData('options/shopname'), sprintf('%010d', $orderId));

$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
Expand Down Expand Up @@ -441,25 +447,6 @@ public function assignData(\Magento\Framework\DataObject $data)
*/
protected function _isAvailablePayolution($quote)
{
$dob = $quote->getCustomer()->getDob();

//we only need to check the dob if it's set. Else we ask for dob on payment selection page.
if ($dob) {
$dobObject = new \DateTime($dob);
$currentYear = date('Y');
$currentMonth = date('m');
$currentDay = date('d');
$ageCheckDate = ( $currentYear - 17 ) . '-' . $currentMonth . '-' . $currentDay;
$ageCheckObject = new \DateTime($ageCheckDate);
if ($ageCheckObject < $dobObject) {
return false;
}
}

if ($quote->hasVirtualItems()) {
return false;
}

if ($this->getConfigData('billing_shipping_address_identical') && !$this->compareAddresses($quote)) {
return false;
}
Expand All @@ -476,18 +463,6 @@ protected function _isAvailablePayolution($quote)
}
}

if (strlen($this->getConfigData('max_basket_size'))) {
if ($quote->getItemsQty() > $this->getConfigData('max_basket_size')) {
return false;
}
}

if (strlen($this->getConfigData('min_basket_size'))) {
if ($quote->getItemsQty() < $this->getConfigData('min_basket_size')) {
return false;
}
}

return parent::isAvailable($quote);
}

Expand All @@ -498,31 +473,6 @@ protected function _isAvailablePayolution($quote)
*/
protected function _isAvailableRatePay($quote)
{
$dob = $quote->getCustomer()->getDob();
$minAge = (int) $this->getConfigData('min_age');

if ($minAge <= 0) {
$this->_logger->debug(__METHOD__ . ':warning min-age not set for ratepay');
return false;
}

//we only need to check the dob if it's set. Else we ask for dob on payment selection page.
if ($dob) {
$dobObject = new \DateTime($dob);
$currentYear = date('Y');
$currentMonth = date('m');
$currentDay = date('d');
$ageCheckDate = ( $currentYear - $minAge ) . '-' . $currentMonth . '-' . $currentDay;
$ageCheckObject = new \DateTime($ageCheckDate);
if ($ageCheckObject < $dobObject) {
return false;
}
}

if ($quote->hasVirtualItems()) {
return false;
}

if ($this->getConfigData('billing_shipping_address_identical') && !$this->compareAddresses($quote)) {
return false;
}
Expand All @@ -539,18 +489,6 @@ protected function _isAvailableRatePay($quote)
}
}

if (strlen($this->getConfigData('max_basket_size'))) {
if ($quote->getItemsQty() > $this->getConfigData('max_basket_size')) {
return false;
}
}

if (strlen($this->getConfigData('min_basket_size'))) {
if ($quote->getItemsQty() < $this->getConfigData('min_basket_size')) {
return false;
}
}

return parent::isAvailable($quote);
}

Expand Down
13 changes: 0 additions & 13 deletions Model/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ class ConfigProvider implements ConfigProviderInterface
Payment\Ideal::CODE,
Payment\Giropay::CODE,
Payment\Tatrapay::CODE,
Payment\Skrilldirect::CODE,
Payment\Skrillwallet::CODE,
Payment\Mpass::CODE,
Payment\Bmc::CODE,
Payment\P24::CODE,
Payment\Poli::CODE,
Expand Down Expand Up @@ -204,17 +202,6 @@ public function getConfig()
$config['payment'][Payment\Invoiceb2b::CODE]['consenttxt'] = sprintf($txt, $payolutionLink);
}

$config['payment'][Payment\Invoice::CODE]['min_age'] = $this->methods[Payment\Invoice::CODE]->getConfigData('min_age');
$config['payment'][Payment\Installment::CODE]['min_age'] = $this->methods[Payment\Installment::CODE]->getConfigData('min_age');

if ($this->methods[Payment\Invoice::CODE]->getProvider() == 'payolution') {
$config['payment'][Payment\Invoice::CODE]['min_age'] = 18;
}

if ($this->methods[Payment\Installment::CODE]->getProvider() == 'payolution') {
$config['payment'][Payment\Installment::CODE]['min_age'] = 18;
}

$payolutionLink = $this->_dataHelper->getPayolutionLink($this->methods[Payment\Installment::CODE]->getConfigData('payolution_mid'));
if ($this->methods[Payment\Installment::CODE]->getProvider() == 'payolution' && $this->methods[Payment\Installment::CODE]->getConfigData('payolution_terms')) {
$config['payment'][Payment\Installment::CODE]['consenttxt'] = sprintf($txt, $payolutionLink);
Expand Down
6 changes: 5 additions & 1 deletion Model/Payment/Installment.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function assignData(\Magento\Framework\DataObject $data)
/**
* Determine method availability based on quote amount and config data
*
* @param \Magento\Quote\Api\Data\CartInterface|null $quote
* @param \Magento\Quote\Model\Quote|\Magento\Quote\Api\Data\CartInterface|null $quote
*
* @return bool
*/
Expand All @@ -88,6 +88,10 @@ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
if ($quote === null)
return false;

if ($quote->hasVirtualItems()) {
return false;
}

if ($this->getConfigData('provider') == 'ratepay') {
return $this->_isAvailableRatePay($quote);
}
Expand Down
6 changes: 5 additions & 1 deletion Model/Payment/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function assignData(\Magento\Framework\DataObject $data)
/**
* Determine method availability based on quote amount and config data
*
* @param \Magento\Quote\Api\Data\CartInterface|null $quote
* @param \Magento\Quote\Model\Quote|\Magento\Quote\Api\Data\CartInterface|null $quote
*
* @return bool
*/
Expand All @@ -89,6 +89,10 @@ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
return false;
}

if ($quote->hasVirtualItems()) {
return false;
}

if ($this->getConfigData('provider') == 'ratepay') {
return $this->_isAvailableRatePay($quote);
} elseif ($this->getConfigData('provider') == 'payolution') {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wirecard/magento2-wcs",
"description": "Wirecard Checkout Seamless",
"type": "magento2-module",
"version": "1.0.4",
"version": "1.0.5",
"license": [
"MIT"
],
Expand Down
Loading

0 comments on commit e07ca3c

Please sign in to comment.