Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
hilrob committed Nov 24, 2017
2 parents 96e4cee + 362f03c commit 85ca0ec
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 49 deletions.
21 changes: 14 additions & 7 deletions Block/Adminhtml/System/Config/ThirdPartyInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/**
* Config form fieldset renderer
*/

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


Expand All @@ -40,7 +41,6 @@ class ThirdPartyInfo extends \Magento\Config\Block\System\Config\Form\Fieldset
*/
protected $paymentConfig;


public function __construct(
\Magento\Payment\Model\Config $paymentConfig,
\Magento\Backend\Block\Context $context,
Expand All @@ -55,7 +55,7 @@ public function __construct(
/**
* Render fieldset html
*
* @param AbstractElement $element
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
Expand All @@ -64,18 +64,25 @@ 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)) {
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['id'] = 'text_' . $thirdPartyMethod;
$fieldConfig['label'] = $paymentMethod->getTitle();
$fieldConfig['config_path'] = 'payment/iways_paypalplus_section/third_party_modul_info/text_'.$thirdPartyMethod;
$fieldConfig['config_path'] =
'payment/iways_paypalplus_section/third_party_modul_info/text_' . $thirdPartyMethod;

$field->setData('field_config', $fieldConfig);
$field->setData('html_id', str_replace('dummy', $thirdPartyMethod, $field->getData('html_id')));
$html .= $field->toHtml();
Expand Down
28 changes: 28 additions & 0 deletions Block/Config/System/Config/Form/Comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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\Block\Config\System\Config\Form;

class Comment extends \Magento\Config\Block\System\Config\Form\Field
{
/**
* Retrieve HTML markup for given form element
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
return $this->_decorateRowHtml($element, __($element->getComment()));
}
}
18 changes: 9 additions & 9 deletions Block/Onepage/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,29 @@ class Success extends \Magento\Framework\View\Element\Template
* Checkout session
* @var \Magento\Checkout\Model\Session
*/
protected $_checkoutSession;
protected $checkoutSession;

/**
* Order
* @var Order
*/
protected $_order;
protected $order;

/**
* Construct
*
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param array $data
* @param [] $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Checkout\Model\Session $checkoutSession,
array $data = []
) {
parent::__construct($context, $data);
$this->_checkoutSession = $checkoutSession;
$this->_order = $this->_checkoutSession->getLastRealOrder();
$this->checkoutSession = $checkoutSession;
$this->order = $this->checkoutSession->getLastRealOrder();
}

/**
Expand All @@ -61,7 +61,7 @@ public function __construct(
*/
public function isPPP()
{
if ($this->_order->getPayment()->getMethodInstance()->getCode() == Payment::CODE) {
if ($this->order->getPayment()->getMethodInstance()->getCode() == Payment::CODE) {
return true;
}
return false;
Expand All @@ -77,7 +77,7 @@ public function isPUI()
return (
$this->isPPP()
&& (
$this->_order->getPayment()->getData('ppp_instruction_type')
$this->order->getPayment()->getData('ppp_instruction_type')
== Payment::PPP_INSTRUCTION_TYPE
)
) ? true : false;
Expand All @@ -90,7 +90,7 @@ public function isPUI()
*/
public function hasPaymentInstruction()
{
return ($this->isPPP() && $this->_order->getPayment()->getData('ppp_instruction_type')) ? true : false;
return ($this->isPPP() && $this->order->getPayment()->getData('ppp_instruction_type')) ? true : false;
}

/**
Expand All @@ -101,7 +101,7 @@ public function hasPaymentInstruction()
*/
public function getAdditionalInformation($key)
{
return $this->_order->getPayment()->getData($key);
return $this->order->getPayment()->getData($key);
}

/**
Expand Down
1 change: 1 addition & 0 deletions Controller/Order/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public function __construct(

/**
* Execute
* @return void
*/
public function execute()
{
Expand Down
6 changes: 2 additions & 4 deletions Controller/Webhooks/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,13 @@ public function execute()
$data = file_get_contents('php://input');
/** @var \PayPal\Api\WebhookEvent $webhookEvent */
$webhookEvent = $this->_apiFactory->create()->validateWebhook($data);
if(!$webhookEvent) {
if (!$webhookEvent) {
throw new LocalizedException(__('Event not found.'));
}
$this->_webhookEventFactory->create()->processWebhookRequest($webhookEvent);
} catch (\Exception $e) {
} catch (\Exception $e) {
$this->_logger->critical($e);
$this->getResponse()->setStatusHeader(503, '1.1', 'Service Unavailable')->sendResponse();
/** @todo eliminate usage of exit statement */
exit;
}
}
}
45 changes: 25 additions & 20 deletions Model/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
* 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\Model;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Encryption\EncryptorInterface;
use Magento\Quote\Model\Quote;
use PayPal\Api\Refund;
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Api\Address;
Expand Down Expand Up @@ -100,9 +102,9 @@ class Api
protected $payPalPlusWebhookEventFactory;

/**
* @var \Magento\Checkout\Model\Type\Onepage
* @var \Magento\Checkout\Model\Session
*/
protected $checkoutTypeOnepage;
protected $checkoutSession;

/**
* @var \Magento\Backend\Model\Session
Expand Down Expand Up @@ -145,7 +147,7 @@ class Api
* @param \Psr\Log\LoggerInterface $logger
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param Webhook\EventFactory $payPalPlusWebhookEventFactory
* @param \Magento\Checkout\Model\Type\Onepage $checkoutTypeOnepage
* @param \Magento\Checkout\Model\Session $session
* @param \Magento\Backend\Model\Session $backendSession
* @param DirectoryList $directoryList
* @param \Magento\Framework\Message\ManagerInterface $messageManager
Expand All @@ -161,7 +163,7 @@ public function __construct(
\Psr\Log\LoggerInterface $logger,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Iways\PayPalPlus\Model\Webhook\EventFactory $payPalPlusWebhookEventFactory,
\Magento\Checkout\Model\Type\Onepage $checkoutTypeOnepage,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Backend\Model\Session $backendSession,
\Magento\Framework\App\Filesystem\DirectoryList $directoryList,
\Magento\Framework\Message\ManagerInterface $messageManager,
Expand All @@ -176,7 +178,7 @@ public function __construct(
$this->logger = $logger;
$this->storeManager = $storeManager;
$this->payPalPlusWebhookEventFactory = $payPalPlusWebhookEventFactory;
$this->checkoutTypeOnepage = $checkoutTypeOnepage;
$this->checkoutSession = $checkoutSession;
$this->backendSession = $backendSession;
$this->directoryList = $directoryList;
$this->messageManager = $messageManager;
Expand Down Expand Up @@ -207,7 +209,7 @@ public function setApiContext($website = null)
\Magento\Store\Model\ScopeInterface::SCOPE_STORE, $website);

$this->_apiContext->setConfig(
array(
[
'http.ConnectionTimeOut' => 30,
'http.Retry' => 1,
'cache.enabled' => $this->scopeConfig->getValue(
Expand All @@ -220,7 +222,7 @@ public function setApiContext($website = null)
\Magento\Store\Model\ScopeInterface::SCOPE_STORE, $website),
'log.FileName' => $this->directoryList->getPath(DirectoryList::LOG) . '/PayPal.log',
'log.LogLevel' => 'INFO'
)
]
);
$this->_apiContext->addRequestHeader('PayPal-Partner-Attribution-Id', 'Magento_Cart_PayPalPlusMagento2');
return $this;
Expand Down Expand Up @@ -251,7 +253,7 @@ public function getPaymentExperience()
* Get a payment
*
* @param string $paymentId
* @return Payment
* @return \PayPal\Api\Payment
*/
public function getPayment($paymentId)
{
Expand Down Expand Up @@ -317,7 +319,7 @@ public function patchPayment($quote)
$payment = PayPalPayment::get($this->customerSession->getPayPalPaymentId(), $this->_apiContext);
$patchRequest = new PatchRequest();

if(!$quote->isVirtual()) {
if (!$quote->isVirtual()) {
$shippingAddress = $this->buildShippingAddress($quote);
$addressPatch = new Patch();
$addressPatch->setOp(self::PATCH_ADD);
Expand Down Expand Up @@ -354,8 +356,8 @@ public function patchPayment($quote)
* Patches invoice number to PayPal transaction
* (Magento order increment id)
*
* @param $paymentId
* @param $invoiceNumber
* @param string $paymentId
* @param string $invoiceNumber
* @return bool
*/
public function patchInvoiceNumber($paymentId, $invoiceNumber)
Expand All @@ -381,7 +383,7 @@ public function patchInvoiceNumber($paymentId, $invoiceNumber)
*
* @param string $paymentId
* @param string $payerId
* @return boolean
* @return boolean|\PayPal\Api\Payment
*/
public function executePayment($paymentId, $payerId)
{
Expand All @@ -403,9 +405,9 @@ public function executePayment($paymentId, $payerId)
/**
* Refund a payment
*
* @param type $paymentId
* @param type $amount
* @return type
* @param string $paymentId
* @param string $amount
* @return Refund
*/
public function refundPayment($paymentId, $amount)
{
Expand Down Expand Up @@ -739,10 +741,15 @@ protected function buildAmount($quote)
);
}

$total = $quote->getBaseGrandTotal();
if((float)$quote->getShippingAddress()->getBaseShippingAmount() == 0 && (float)$quote->getShippingAddress()->getBaseShippingInclTax() >= 0) {
$total = (float)$total - (float)$quote->getShippingAddress()->getBaseShippingInclTax();
}

$amount = new Amount();
$amount->setCurrency($quote->getBaseCurrencyCode())
->setDetails($details)
->setTotal($quote->getBaseGrandTotal());
->setTotal($total);

return $amount;
}
Expand Down Expand Up @@ -791,8 +798,7 @@ protected function buildWebProfilePresentation()
$presentation->setLocaleCode(
substr(
$this->scopeConfig->getValue('general/locale/code', \Magento\Store\Model\ScopeInterface::SCOPE_STORE),
3,
2
-2
)
);
return $presentation;
Expand Down Expand Up @@ -864,7 +870,7 @@ protected function saveWebhookId($id)
*/
protected function getQuote()
{
return $this->checkoutTypeOnepage->getQuote();
return $this->checkoutSession->getQuote();
}

/**
Expand All @@ -891,5 +897,4 @@ public function testCredentials($website)
return false;
}
}

}
8 changes: 8 additions & 0 deletions RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
==== 1.1.4 ====
Changed locale_code parsing
Added workaround for broken shipping cost calculation in checkout
Fixed magento/module-paypal requirement to support Magento 2.2.X

==== 1.1.3 ====
Added notice to configuration if merchant country is not set to Germany

==== 1.1.2 ====
Fix JS Script error on empty third party method array
Fix for missing ShippingAddress on virtual orders
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
],
"require": {
"php": "~5.5.0|~5.6.0|~7.0.0|~7.1.0",
"paypal/rest-api-sdk-php": "^1.6"
"paypal/rest-api-sdk-php": "^1.6",
"magento/module-paypal": "100.0.*|100.1.*|100.2.*"
},
"authors": [
{
Expand All @@ -18,7 +19,7 @@
}
],
"type": "magento2-module",
"version": "1.1.2",
"version": "1.1.4",
"license": [
"OSL-3.0"
],
Expand Down
Loading

0 comments on commit 85ca0ec

Please sign in to comment.