Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
hilrob committed May 20, 2019
2 parents e566b47 + fb33a34 commit eaba52d
Show file tree
Hide file tree
Showing 31 changed files with 399 additions and 348 deletions.
22 changes: 2 additions & 20 deletions Block/Adminhtml/System/Config/ThirdPartyInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,11 @@

namespace Iways\PayPalPlus\Block\Adminhtml\System\Config;


use Magento\Framework\App\Config\ScopeConfigInterface;

class ThirdPartyInfo extends \Magento\Config\Block\System\Config\Form\Fieldset
{
/**
* @var
*/
protected $_dummyElement;
/**
* @var
*/
protected $_fieldRenderer;
/**
* @var
*/
protected $_values;

/**
* @var \Magento\Payment\Model\Config
*/
Expand Down Expand Up @@ -64,19 +51,14 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
$html = $this->_getHeaderHtml($element);
$dummyField = $element->getElements()[0];

$thirdPartyMethods = explode(',',
$this->_scopeConfig->getValue('payment/iways_paypalplus_payment/third_party_moduls'));
$thirdPartyMethods = explode(',', $this->_scopeConfig->getValue('payment/iways_paypalplus_payment/third_party_moduls'));
foreach ($this->paymentConfig->getActiveMethods() as $paymentMethod) {
if (in_array($paymentMethod->getCode(), $thirdPartyMethods)) {
$thirdPartyMethod = $paymentMethod->getCode();
$field = clone $dummyField;
$field->setData('name', str_replace('dummy', $thirdPartyMethod, $field->getName()));
$field->setData('label', $paymentMethod->getTitle());
$field->setData('value',
$this->_scopeConfig->getValue(
'payment/iways_paypalplus_section/third_party_modul_info/text_' . $thirdPartyMethod
)
);
$field->setData('value', $this->_scopeConfig->getValue('payment/iways_paypalplus_section/third_party_modul_info/text_' . $thirdPartyMethod));
$fieldConfig = $field->getData('field_config');
$fieldConfig['id'] = 'text_' . $thirdPartyMethod;
$fieldConfig['label'] = $paymentMethod->getTitle();
Expand Down
4 changes: 2 additions & 2 deletions Block/Onepage/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function isPPP()
}

/**
* Checks if order is PayPal Plus and PuI
* Checks if order is PayPal PLUS and PuI
*
* @return bool
*/
Expand All @@ -84,7 +84,7 @@ public function isPUI()
}

/**
* Checks if order is PayPal Plus and has payment instructions
* Checks if order is PayPal PLUS and has payment instructions
*
* @return bool
*/
Expand Down
8 changes: 4 additions & 4 deletions Block/PaymentInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public function toPdf()

/**
* Prepare information specific to current payment method
*
* @param \Magento\Framework\DataObject|array $transport
* @param null $transport
* @return \Magento\Framework\DataObject
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _prepareSpecificInformation($transport = null)
{
Expand All @@ -64,9 +64,9 @@ protected function _prepareSpecificInformation($transport = null)
}

/**
* Checks if PayPal Plus payment is PUI
*
* Checks if PayPal PLUS payment is PUI
* @return bool
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function isPUI()
{
Expand Down
19 changes: 13 additions & 6 deletions Controller/Order/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use Magento\Customer\Model\Session;
use Magento\Framework\DataObject;
use Magento\Quote\Model\QuoteIdMask;
use Magento\Quote\Model\QuoteIdMaskFactory;
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
use Magento\Sales\Model\OrderFactory;
Expand All @@ -30,7 +29,7 @@
*/
class Create extends \Magento\Framework\App\Action\Action
{

const MAX_SEND_MAIL_VERSION = '2.2.6';
/**
* @var \Psr\Log\LoggerInterface
*/
Expand Down Expand Up @@ -76,6 +75,11 @@ class Create extends \Magento\Framework\App\Action\Action
*/
protected $historyFactory;

/**
* @var \Magento\Framework\App\ProductMetadataInterface
*/
protected $productMetadata;

public function __construct(
\Magento\Framework\App\Action\Context $context,
\Psr\Log\LoggerInterface $logger,
Expand All @@ -87,7 +91,8 @@ public function __construct(
OrderSender $orderSender,
OrderFactory $orderFactory,
\Magento\Sales\Model\Order\Status\HistoryFactory $historyFactory,
Session $customerSession
Session $customerSession,
\Magento\Framework\App\ProductMetadataInterface $productMetadata
) {
$this->logger = $logger;
$this->checkoutSession = $checkoutSession;
Expand All @@ -99,8 +104,8 @@ public function __construct(
$this->orderSender = $orderSender;
$this->orderFactory = $orderFactory;
$this->historyFactory = $historyFactory;
$this->productMetadata = $productMetadata;
parent::__construct($context);

}

/**
Expand All @@ -121,7 +126,10 @@ public function execute()

if ($orderId) {
$order = $this->orderFactory->create()->load($orderId);
if ($order->getCanSendNewEmailFlag()) {
if (
$order->getCanSendNewEmailFlag()
&& version_compare($this->productMetadata->getVersion(), self::MAX_SEND_MAIL_VERSION, '<')
) {
try {
$this->orderSender->send($order);
} catch (\Exception $e) {
Expand All @@ -148,7 +156,6 @@ public function execute()
}
}
} catch (\Exception $e) {

}
}
$result->setData('success', true);
Expand Down
2 changes: 2 additions & 0 deletions Controller/Webhooks/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,7 @@ public function execute()
$this->_logger->critical($e);
$this->getResponse()->setStatusHeader(503, '1.1', 'Service Unavailable')->sendResponse();
}

return;
}
}
42 changes: 42 additions & 0 deletions Controller/Webhooks/Twothree.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* Author Robert Hillebrand - [email protected] - i-ways sales solutions GmbH
* Copyright i-ways sales solutions GmbH © 2015. All Rights Reserved.
* License http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace Iways\PayPalPlus\Controller\Webhooks;

use Magento\Framework\App\CsrfAwareActionInterface;
use Magento\Framework\App\Request\InvalidRequestException;

/**
* Unified IPN controller for all supported PayPal methods
*/
class Twothree extends Index implements CsrfAwareActionInterface
{
/**
* @param \Magento\Framework\App\RequestInterface $request
* @return bool|null
*/
public function validateForCsrf(\Magento\Framework\App\RequestInterface $request): ?bool
{
return true;
}

/**
* @param \Magento\Framework\App\RequestInterface $request
* @return InvalidRequestException|null
*/
public function createCsrfValidationException(\Magento\Framework\App\RequestInterface $request): ?InvalidRequestException
{
return null;
}
}
66 changes: 51 additions & 15 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@
namespace Iways\PayPalPlus\Helper;

use Magento\Framework\App\Cache\TypeListInterface;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\LayoutFactory;

/**
* Iways PayPalPlus Helper
*
* @category Iways
* @package Iways_PayPalPlus
* @author robert
* Class Data
* @package Iways\PayPalPlus\Helper
*/
class Data extends \Magento\Payment\Helper\Data
{
Expand Down Expand Up @@ -62,6 +58,28 @@ class Data extends \Magento\Payment\Helper\Data
*/
protected $cacheTypeList;

/**
* @var \Magento\Framework\App\ProductMetadata
*/
protected $productMetaData;

/**
* Data constructor.
* @param \Magento\Framework\App\Helper\Context $context
* @param LayoutFactory $layoutFactory
* @param \Magento\Payment\Model\Method\Factory $paymentMethodFactory
* @param \Magento\Store\Model\App\Emulation $appEmulation
* @param \Magento\Payment\Model\Config $paymentConfig
* @param \Magento\Framework\App\Config\Initial $initialConfig
* @param \Magento\Framework\Session\Generic $generic
* @param \Magento\Framework\App\Request\Http $request
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Iways\PayPalPlus\Model\ApiFactory $payPalPlusApiFactory
* @param \Magento\Framework\Message\ManagerInterface $messageManager
* @param \Magento\Config\Model\ResourceModel\Config $configResource
* @param \Magento\Framework\App\ProductMetadata $productMetaData
* @param TypeListInterface $cacheTypeList
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
LayoutFactory $layoutFactory,
Expand All @@ -75,6 +93,7 @@ public function __construct(
\Iways\PayPalPlus\Model\ApiFactory $payPalPlusApiFactory,
\Magento\Framework\Message\ManagerInterface $messageManager,
\Magento\Config\Model\ResourceModel\Config $configResource,
\Magento\Framework\App\ProductMetadata $productMetaData,
TypeListInterface $cacheTypeList
) {
parent::__construct($context, $layoutFactory, $paymentMethodFactory, $appEmulation, $paymentConfig, $initialConfig);
Expand All @@ -85,7 +104,9 @@ public function __construct(
$this->messageManager = $messageManager;
$this->configResource = $configResource;
$this->cacheTypeList = $cacheTypeList;
$this->productMetaData = $productMetaData;
}

/**
* Show Exception if debug mode.
*
Expand All @@ -105,20 +126,33 @@ public function handleException(\Exception $e)
*/
public function getWebhooksUrl()
{
$version = $this->productMetaData->getVersion();
if (version_compare($version, '2.3.0', '>=')) {
return str_replace(
'http://',
'https://',
$this->_getUrl(
'paypalplus/webhooks/twothree/',
[
'_forced_secure' => true,
'_nosid' => true,
]
)
);
}
return str_replace(
'http://',
'https://',
$this->_getUrl(
'paypalplus/webhooks/index/',
array(
[
'_forced_secure' => true,
'_nosid' => true,
)
]
)
);
}


/**
* Get url wrapper for security urls and form key
*
Expand Down Expand Up @@ -152,16 +186,16 @@ public function getDefaultCountryId()
}

/**
* Helper for saving store configuration programmatically
*
* Save Store Config
* @param $key
* @param $value
* @param $storeId
* @return boolean
* @param null $storeId
* @return bool
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function saveStoreConfig($key, $value, $storeId = null)
{
if(!$storeId) {
if (!$storeId) {
$storeId = $this->storeManager->getStore()->getId();
}
$this->configResource->saveConfig(
Expand All @@ -173,12 +207,14 @@ public function saveStoreConfig($key, $value, $storeId = null)
$this->cacheTypeList->cleanType('config');
return true;
}

/**
* Reset web profile id
*
* @return boolean
*/
public function resetWebProfileId() {
public function resetWebProfileId()
{
foreach ($this->storeManager->getStores() as $store) {
$this->configResource->saveConfig(
'iways_paypalplus/dev/web_profile_id',
Expand Down
Loading

0 comments on commit eaba52d

Please sign in to comment.