Skip to content

Commit 837e2e2

Browse files
authored
Merge pull request #566 from FatchipRobert/MAG2-319-PayPalV2
MAG2-319 - Added PayPal V2 integration
2 parents 606b46e + d927656 commit 837e2e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2397
-124
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/**
4+
* PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
* PHP version 5
18+
*
19+
* @category Payone
20+
* @package Payone_Magento2_Plugin
21+
* @author FATCHIP GmbH <support@fatchip.de>
22+
* @copyright 2003 - 2024 Payone GmbH
23+
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License
24+
* @link http://www.payone.de
25+
*/
26+
27+
namespace Payone\Core\Api\Data;
28+
29+
interface PayPalResponseInterface
30+
{
31+
/**
32+
* Returns the PAYONE workorder id
33+
*
34+
* @return string
35+
*/
36+
public function getWorkorderId();
37+
38+
/**
39+
* Returns if the call was successful
40+
*
41+
* @return bool
42+
*/
43+
public function getSuccess();
44+
45+
/**
46+
* Return paypal order id
47+
*
48+
* @return string
49+
*/
50+
public function getOrderId();
51+
52+
/**
53+
* Returns errormessage
54+
*
55+
* @return string
56+
*/
57+
public function getErrormessage();
58+
}

Api/PayPalInterface.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/**
4+
* PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
* PHP version 5
18+
*
19+
* @category Payone
20+
* @package Payone_Magento2_Plugin
21+
* @author FATCHIP GmbH <support@fatchip.de>
22+
* @copyright 2003 - 2024 Payone GmbH
23+
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License
24+
* @link http://www.payone.de
25+
*/
26+
27+
namespace Payone\Core\Api;
28+
29+
interface PayPalInterface
30+
{
31+
/**
32+
* Trigger PayPal Express v2 process
33+
*
34+
* @param string $cartId
35+
* @return \Payone\Core\Service\V1\Data\PayPalResponse
36+
*/
37+
public function startPayPalExpress($cartId);
38+
}

Block/Paypal/Base.php

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?php
2+
3+
/**
4+
* PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
* PHP version 5
18+
*
19+
* @category Payone
20+
* @package Payone_Magento2_Plugin
21+
* @author FATCHIP GmbH <support@fatchip.de>
22+
* @copyright 2003 - 2024 Payone GmbH
23+
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License
24+
* @link http://www.payone.de
25+
*/
26+
27+
namespace Payone\Core\Block\Paypal;
28+
29+
use Magento\Framework\View\Element\Template;
30+
31+
class Base extends Template implements \Magento\Catalog\Block\ShortcutInterface
32+
{
33+
/**
34+
* Shortcut alias
35+
*
36+
* @var string
37+
*/
38+
protected $alias;
39+
40+
/**
41+
* @var string
42+
*/
43+
protected $name;
44+
45+
/**
46+
* @var \Magento\Framework\Locale\ResolverInterface
47+
*/
48+
protected $localeResolver;
49+
50+
/**
51+
* Locale codes supported by misc images (marks, shortcuts etc)
52+
*
53+
* @var array
54+
*/
55+
protected $aSupportedLocales = [
56+
'de_DE',
57+
'en_AU',
58+
'en_GB',
59+
'en_US',
60+
'es_ES',
61+
'es_XC',
62+
'fr_FR',
63+
'fr_XC',
64+
'it_IT',
65+
'ja_JP',
66+
'nl_NL',
67+
'pl_PL',
68+
'zh_CN',
69+
'zh_XC',
70+
];
71+
72+
/**
73+
* Constructor
74+
*
75+
* @param \Magento\Framework\View\Element\Template\Context $context
76+
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
77+
* @param array $data
78+
*/
79+
public function __construct(
80+
\Magento\Framework\View\Element\Template\Context $context,
81+
\Magento\Framework\Locale\ResolverInterface $localeResolver,
82+
array $data = []
83+
) {
84+
parent::__construct($context, $data);
85+
$this->localeResolver = $localeResolver;
86+
$this->setTemplate($this->sTemplate);
87+
}
88+
89+
/**
90+
* Get shortcut alias
91+
*
92+
* @return string
93+
*/
94+
public function getAlias()
95+
{
96+
return $this->alias;
97+
}
98+
99+
/**
100+
* @param string $sName
101+
* @return void
102+
*/
103+
public function setName($sName)
104+
{
105+
$this->name = $sName;
106+
}
107+
108+
/**
109+
* @return string
110+
*/
111+
public function getName()
112+
{
113+
return $this->name;
114+
}
115+
116+
117+
/**
118+
* @return string
119+
*/
120+
public function getButtonIdent()
121+
{
122+
$sButtonIdent = "payone-paypal-button-container";
123+
if (strpos($this->getName(), "checkout.cart.shortcut.buttons") !== false) {
124+
$sButtonIdent = "payone-paypal-button-basket";
125+
} elseif (strpos($this->getName(), "shortcutbuttons") !== false) {
126+
$sButtonIdent = "payone-paypal-button-minibasket";
127+
}
128+
return $sButtonIdent;
129+
}
130+
131+
/**
132+
* Check whether specified locale code is supported. Fallback to en_US
133+
*
134+
* @param string $sLocale
135+
* @return string
136+
*/
137+
protected function getSupportedLocaleCode($sLocale = null)
138+
{
139+
if (!$sLocale || !in_array($sLocale, $this->aSupportedLocales)) {
140+
return 'en_US';
141+
}
142+
return $sLocale;
143+
}
144+
145+
/**
146+
* @return string
147+
*/
148+
protected function getLocale()
149+
{
150+
$sCurrentLocal = $this->localeResolver->getLocale();
151+
$sPayPalLocal = $this->getSupportedLocaleCode($sCurrentLocal);
152+
return $sPayPalLocal;
153+
}
154+
}

Block/Paypal/ExpressButton.php

Lines changed: 4 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/**
3232
* Block class for the PayPal Express button
3333
*/
34-
class ExpressButton extends Template implements \Magento\Catalog\Block\ShortcutInterface
34+
class ExpressButton extends Base
3535
{
3636
/**
3737
* Shortcut alias
@@ -41,72 +41,9 @@ class ExpressButton extends Template implements \Magento\Catalog\Block\ShortcutI
4141
protected $alias = 'payone.block.paypal.expressbutton';
4242

4343
/**
44-
* Is mandate link to be shown?
45-
*
46-
* @var bool|null
47-
*/
48-
protected $blShowMandateLink = null;
49-
50-
/**
51-
* Instruction notes
52-
*
53-
* @var string|bool
54-
*/
55-
protected $sInstructionNotes = false;
56-
57-
/**
58-
* @var \Magento\Framework\Locale\ResolverInterface
59-
*/
60-
protected $localeResolver;
61-
62-
/**
63-
* Locale codes supported by misc images (marks, shortcuts etc)
64-
*
65-
* @var array
66-
*/
67-
protected $aSupportedLocales = [
68-
'de_DE',
69-
'en_AU',
70-
'en_GB',
71-
'en_US',
72-
'es_ES',
73-
'es_XC',
74-
'fr_FR',
75-
'fr_XC',
76-
'it_IT',
77-
'ja_JP',
78-
'nl_NL',
79-
'pl_PL',
80-
'zh_CN',
81-
'zh_XC',
82-
];
83-
84-
/**
85-
* Constructor
86-
*
87-
* @param \Magento\Framework\View\Element\Template\Context $context
88-
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
89-
* @param array $data
90-
*/
91-
public function __construct(
92-
\Magento\Framework\View\Element\Template\Context $context,
93-
\Magento\Framework\Locale\ResolverInterface $localeResolver,
94-
array $data = []
95-
) {
96-
parent::__construct($context, $data);
97-
$this->localeResolver = $localeResolver;
98-
$this->setTemplate('paypal/express_button.phtml');
99-
}
100-
101-
/**
102-
* Get shortcut alias
103-
*
104-
* @return string
44+
* @var string
10545
*/
106-
public function getAlias()
107-
{
108-
return $this->alias;
109-
}
46+
protected $sTemplate = 'paypal/express_button.phtml';
11047

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

121-
/**
122-
* Check whether specified locale code is supported. Fallback to en_US
123-
*
124-
* @param string $sLocale
125-
* @return string
126-
*/
127-
protected function getSupportedLocaleCode($sLocale = null)
128-
{
129-
if (!$sLocale || !in_array($sLocale, $this->aSupportedLocales)) {
130-
return 'en_US';
131-
}
132-
return $sLocale;
133-
}
134-
13558
/**
13659
* Return URL to PayPal Express logo
13760
*
13861
* @return string
13962
*/
14063
public function getPayPalExpressLogoUrl()
14164
{
142-
$sCurrentLocal = $this->localeResolver->getLocale();
143-
$sPayPalLocal = $this->getSupportedLocaleCode($sCurrentLocal);
144-
return sprintf('https://www.paypal.com/%s/i/btn/btn_xpressCheckout.gif', $sPayPalLocal);
65+
return sprintf('https://www.paypal.com/%s/i/btn/btn_xpressCheckout.gif', $this->getLocale());
14566
}
14667
}

0 commit comments

Comments
 (0)