Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAG2-319 - Added PayPal V2 integration #566

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions Api/Data/PayPalResponseInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* 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 <http://www.gnu.org/licenses/>.
*
* PHP version 5
*
* @category Payone
* @package Payone_Magento2_Plugin
* @author FATCHIP GmbH <[email protected]>
* @copyright 2003 - 2024 Payone GmbH
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License
* @link http://www.payone.de
*/

namespace Payone\Core\Api\Data;

interface PayPalResponseInterface
{
/**
* Returns the PAYONE workorder id
*
* @return string
*/
public function getWorkorderId();

/**
* Returns if the call was successful
*
* @return bool
*/
public function getSuccess();

/**
* Return paypal order id
*
* @return string
*/
public function getOrderId();

/**
* Returns errormessage
*
* @return string
*/
public function getErrormessage();
}
38 changes: 38 additions & 0 deletions Api/PayPalInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* 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 <http://www.gnu.org/licenses/>.
*
* PHP version 5
*
* @category Payone
* @package Payone_Magento2_Plugin
* @author FATCHIP GmbH <[email protected]>
* @copyright 2003 - 2024 Payone GmbH
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License
* @link http://www.payone.de
*/

namespace Payone\Core\Api;

interface PayPalInterface
{
/**
* Trigger PayPal Express v2 process
*
* @param string $cartId
* @return \Payone\Core\Service\V1\Data\PayPalResponse
*/
public function startPayPalExpress($cartId);
}
154 changes: 154 additions & 0 deletions Block/Paypal/Base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php

/**
* 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 <http://www.gnu.org/licenses/>.
*
* PHP version 5
*
* @category Payone
* @package Payone_Magento2_Plugin
* @author FATCHIP GmbH <[email protected]>
* @copyright 2003 - 2024 Payone GmbH
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License
* @link http://www.payone.de
*/

namespace Payone\Core\Block\Paypal;

use Magento\Framework\View\Element\Template;

class Base extends Template implements \Magento\Catalog\Block\ShortcutInterface
{
/**
* Shortcut alias
*
* @var string
*/
protected $alias;

/**
* @var string
*/
protected $name;

/**
* @var \Magento\Framework\Locale\ResolverInterface
*/
protected $localeResolver;

/**
* Locale codes supported by misc images (marks, shortcuts etc)
*
* @var array
*/
protected $aSupportedLocales = [
'de_DE',
'en_AU',
'en_GB',
'en_US',
'es_ES',
'es_XC',
'fr_FR',
'fr_XC',
'it_IT',
'ja_JP',
'nl_NL',
'pl_PL',
'zh_CN',
'zh_XC',
];

/**
* Constructor
*
* @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,
\Magento\Framework\Locale\ResolverInterface $localeResolver,
array $data = []
) {
parent::__construct($context, $data);
$this->localeResolver = $localeResolver;
$this->setTemplate($this->sTemplate);
}

/**
* Get shortcut alias
*
* @return string
*/
public function getAlias()
{
return $this->alias;
}

/**
* @param string $sName
* @return void
*/
public function setName($sName)
{
$this->name = $sName;
}

/**
* @return string
*/
public function getName()
{
return $this->name;
}


/**
* @return string
*/
public function getButtonIdent()
{
$sButtonIdent = "payone-paypal-button-container";
if (strpos($this->getName(), "checkout.cart.shortcut.buttons") !== false) {
$sButtonIdent = "payone-paypal-button-basket";
} elseif (strpos($this->getName(), "shortcutbuttons") !== false) {
$sButtonIdent = "payone-paypal-button-minibasket";
}
return $sButtonIdent;
}

/**
* Check whether specified locale code is supported. Fallback to en_US
*
* @param string $sLocale
* @return string
*/
protected function getSupportedLocaleCode($sLocale = null)
{
if (!$sLocale || !in_array($sLocale, $this->aSupportedLocales)) {
return 'en_US';
}
return $sLocale;
}

/**
* @return string
*/
protected function getLocale()
{
$sCurrentLocal = $this->localeResolver->getLocale();
$sPayPalLocal = $this->getSupportedLocaleCode($sCurrentLocal);
return $sPayPalLocal;
}
}
87 changes: 4 additions & 83 deletions Block/Paypal/ExpressButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/**
* Block class for the PayPal Express button
*/
class ExpressButton extends Template implements \Magento\Catalog\Block\ShortcutInterface
class ExpressButton extends Base
{
/**
* Shortcut alias
Expand All @@ -41,72 +41,9 @@ class ExpressButton extends Template implements \Magento\Catalog\Block\ShortcutI
protected $alias = 'payone.block.paypal.expressbutton';

/**
* Is mandate link to be shown?
*
* @var bool|null
*/
protected $blShowMandateLink = null;

/**
* Instruction notes
*
* @var string|bool
*/
protected $sInstructionNotes = false;

/**
* @var \Magento\Framework\Locale\ResolverInterface
*/
protected $localeResolver;

/**
* Locale codes supported by misc images (marks, shortcuts etc)
*
* @var array
*/
protected $aSupportedLocales = [
'de_DE',
'en_AU',
'en_GB',
'en_US',
'es_ES',
'es_XC',
'fr_FR',
'fr_XC',
'it_IT',
'ja_JP',
'nl_NL',
'pl_PL',
'zh_CN',
'zh_XC',
];

/**
* Constructor
*
* @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,
\Magento\Framework\Locale\ResolverInterface $localeResolver,
array $data = []
) {
parent::__construct($context, $data);
$this->localeResolver = $localeResolver;
$this->setTemplate('paypal/express_button.phtml');
}

/**
* Get shortcut alias
*
* @return string
* @var string
*/
public function getAlias()
{
return $this->alias;
}
protected $sTemplate = 'paypal/express_button.phtml';

/**
* URL to paypal start controller
Expand All @@ -118,29 +55,13 @@ public function getPayPalExpressLink()
return $this->getUrl('payone/paypal/express');
}

/**
* Check whether specified locale code is supported. Fallback to en_US
*
* @param string $sLocale
* @return string
*/
protected function getSupportedLocaleCode($sLocale = null)
{
if (!$sLocale || !in_array($sLocale, $this->aSupportedLocales)) {
return 'en_US';
}
return $sLocale;
}

/**
* Return URL to PayPal Express logo
*
* @return string
*/
public function getPayPalExpressLogoUrl()
{
$sCurrentLocal = $this->localeResolver->getLocale();
$sPayPalLocal = $this->getSupportedLocaleCode($sCurrentLocal);
return sprintf('https://www.paypal.com/%s/i/btn/btn_xpressCheckout.gif', $sPayPalLocal);
return sprintf('https://www.paypal.com/%s/i/btn/btn_xpressCheckout.gif', $this->getLocale());
}
}
Loading
Loading