Skip to content

Commit b3cad72

Browse files
authored
Merge pull request #615 from FatchipRobert/MAG2-369-Click-to-pay
MAG2-369 - Added new payment method Click To Pay
2 parents bd5b843 + 40b4d63 commit b3cad72

File tree

39 files changed

+2046
-15
lines changed

39 files changed

+2046
-15
lines changed

Api/ClickToPayInterface.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 8
18+
*
19+
* @category Payone
20+
* @package Payone_Magento2_Plugin
21+
* @author FATCHIP GmbH <support@fatchip.de>
22+
* @copyright 2003 - 2026 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 ClickToPayInterface
30+
{
31+
/**
32+
* Get JWT for ClickToPay process
33+
*
34+
* @param string $cartId
35+
* @return \Payone\Core\Service\V1\Data\ClickToPayResponse
36+
*/
37+
public function getJwt($cartId);
38+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 8
18+
*
19+
* @category Payone
20+
* @package Payone_Magento2_Plugin
21+
* @author FATCHIP GmbH <support@fatchip.de>
22+
* @copyright 2003 - 2026 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 ClickToPayResponseInterface
30+
{
31+
/**
32+
* Returns JSON web token
33+
*
34+
* @return string
35+
*/
36+
public function getJwt();
37+
38+
/**
39+
* Returns if the call was successful
40+
*
41+
* @return bool
42+
*/
43+
public function getSuccess();
44+
45+
/**
46+
* Returns errormessage
47+
*
48+
* @return string
49+
*/
50+
public function getErrormessage();
51+
}

Block/Adminhtml/Protocol/Api/View.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ public function formatValue($sKey, $sValue)
117117
if (in_array($sKey, ['add_paydata[amazon_address_token]', 'add_paydata[paymentmethod_token_data]'])) {
118118
return '<span title="'.$sValue.'">[...]</span>';
119119
}
120+
if ($sKey == "token") {
121+
return '<div style="overflow:scroll;max-width:40vw;">'.$sValue.'</div>';
122+
}
120123
return $sValue;
121124
}
122125
}

Helper/Api.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,10 @@ public function __construct(
150150
* Check which communication possibilities are existing and send the request
151151
*
152152
* @param string $sRequestUrl
153+
* @param array $aHeaders
153154
* @return array
154155
*/
155-
public function sendApiRequest($sRequestUrl)
156+
public function sendApiRequest($sRequestUrl, $aHeaders = [])
156157
{
157158
$aParsedRequestUrl = parse_url($sRequestUrl);
158159
if ($aParsedRequestUrl === false) {
@@ -161,13 +162,13 @@ public function sendApiRequest($sRequestUrl)
161162

162163
if ($this->connCurlPhp->isApplicable()) {
163164
// php native curl exists so we gonna use it for requesting
164-
$aResponse = $this->connCurlPhp->sendCurlPhpRequest($aParsedRequestUrl);
165+
$aResponse = $this->connCurlPhp->sendCurlPhpRequest($aParsedRequestUrl, $aHeaders);
165166
} elseif ($this->connCurlCli->isApplicable()) {
166167
// cli version of curl exists on server
167-
$aResponse = $this->connCurlCli->sendCurlCliRequest($aParsedRequestUrl);
168+
$aResponse = $this->connCurlCli->sendCurlCliRequest($aParsedRequestUrl, $aHeaders);
168169
} else {
169170
// last resort => via sockets
170-
$aResponse = $this->connFsockopen->sendSocketRequest($aParsedRequestUrl);
171+
$aResponse = $this->connFsockopen->sendSocketRequest($aParsedRequestUrl, $aHeaders);
171172
}
172173

173174
$aResponse = $this->formatOutputByResponse($aResponse);

Helper/Connection/CurlCli.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ public function isApplicable()
4848
* Send cli Curl request
4949
*
5050
* @param array $aParsedRequestUrl
51+
* @param array $aHeaders
5152
* @return array
5253
*/
53-
public function sendCurlCliRequest($aParsedRequestUrl)
54+
public function sendCurlCliRequest($aParsedRequestUrl, $aHeaders = [])
5455
{
5556
if (!$this->isApplicable()) {
5657
return ["errormessage" => "Cli-Curl is not applicable on this server."];
@@ -63,7 +64,12 @@ public function sendCurlCliRequest($aParsedRequestUrl)
6364
$sPostUrl = $aParsedRequestUrl['scheme']."://".$aParsedRequestUrl['host'].$aParsedRequestUrl['path'];
6465
$sPostData = $aParsedRequestUrl['query'];
6566

66-
$sCommand = $sCurlPath." -m 45 -k -d \"".$sPostData."\" ".$sPostUrl;
67+
$sHeaderString = "";
68+
foreach ($aHeaders as $sHeader) {
69+
$sHeaderString .= ' -H "'.$sHeader.'" ';
70+
}
71+
72+
$sCommand = $sCurlPath." -m 45 ".$sHeaderString." -k -d \"".$sPostData."\" ".$sPostUrl;
6773

6874
$iSysOut = -1;
6975
exec($sCommand, $aResponse, $iSysOut);

Helper/Connection/CurlPhp.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ public function isApplicable()
4848
* Send php Curl request
4949
*
5050
* @param array $aParsedRequestUrl
51+
* @param array $aHeaders
5152
* @return array
5253
*/
53-
public function sendCurlPhpRequest($aParsedRequestUrl)
54+
public function sendCurlPhpRequest($aParsedRequestUrl, $aHeaders = [])
5455
{
5556
if (!$this->isApplicable()) {
5657
return ["errormessage" => "Php-Curl is not applicable on this server."];
@@ -66,6 +67,10 @@ public function sendCurlPhpRequest($aParsedRequestUrl)
6667
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, true);
6768
curl_setopt($oCurl, CURLOPT_TIMEOUT, 45);
6869

70+
if (!empty($aHeaders)) {
71+
curl_setopt($oCurl, CURLOPT_HTTPHEADER, $aHeaders);
72+
}
73+
6974
$sResult = curl_exec($oCurl);
7075
if (curl_error($oCurl)) {
7176
$aResponse[] = "connection-type: 1 - errormessage=".curl_errno($oCurl).": ".curl_error($oCurl);

Helper/Connection/Fsockopen.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,18 @@ public function isApplicable()
4848
* Get request header for fsockopen request
4949
*
5050
* @param array $aParsedRequestUrl
51+
* @param array $aHeaders
5152
* @return string
5253
*/
53-
protected function getSocketRequestHeader($aParsedRequestUrl)
54+
protected function getSocketRequestHeader($aParsedRequestUrl, $aHeaders = [])
5455
{
5556
$sRequestHeader = "POST ".$aParsedRequestUrl['path']." HTTP/1.1\r\n";
5657
$sRequestHeader .= "Host: ".$aParsedRequestUrl['host']."\r\n";
5758
$sRequestHeader .= "Content-Type: application/x-www-form-urlencoded\r\n";
5859
$sRequestHeader .= "Content-Length: ".strlen($aParsedRequestUrl['query'])."\r\n";
60+
foreach ($aHeaders as $sHeader) {
61+
$sRequestHeader .= $sHeader."\r\n";
62+
}
5963
$sRequestHeader .= "Connection: close\r\n\r\n";
6064
$sRequestHeader .= $aParsedRequestUrl['query'];
6165
return $sRequestHeader;
@@ -89,9 +93,10 @@ protected function getSocketResponse($oFsockOpen)
8993
* Send fsockopen request
9094
*
9195
* @param array $aParsedRequestUrl
96+
* @param array $aHeaders
9297
* @return array
9398
*/
94-
public function sendSocketRequest($aParsedRequestUrl)
99+
public function sendSocketRequest($aParsedRequestUrl, $aHeaders = [])
95100
{
96101
if (!$this->isApplicable()) {
97102
return ["errormessage" => "Cli-Curl is not applicable on this server."];
@@ -109,7 +114,7 @@ public function sendSocketRequest($aParsedRequestUrl)
109114

110115
$oFsockOpen = fsockopen($sScheme.$aParsedRequestUrl['host'], $iPort, $iErrorNumber, $sErrorString, 45);
111116
if ($oFsockOpen) {
112-
fwrite($oFsockOpen, $this->getSocketRequestHeader($aParsedRequestUrl));
117+
fwrite($oFsockOpen, $this->getSocketRequestHeader($aParsedRequestUrl, $aHeaders));
113118
return $this->getSocketResponse($oFsockOpen);
114119
}
115120
return ["errormessage=fsockopen:Failed opening http socket connection: ".$sErrorString." (".$iErrorNumber.")"];

Helper/Payment.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Payment extends \Payone\Core\Helper\Base
4242
*/
4343
protected $aAvailablePayments = [
4444
PayoneConfig::METHOD_CREDITCARD,
45+
PayoneConfig::METHOD_CREDITCARDV2,
4546
PayoneConfig::METHOD_DEBIT,
4647
PayoneConfig::METHOD_PAYPAL,
4748
PayoneConfig::METHOD_PAYPALV2,
@@ -83,6 +84,7 @@ class Payment extends \Payone\Core\Helper\Base
8384
*/
8485
protected $aPaymentAbbreviation = [
8586
PayoneConfig::METHOD_CREDITCARD => 'cc',
87+
PayoneConfig::METHOD_CREDITCARDV2 => 'cc',
8688
PayoneConfig::METHOD_CASH_ON_DELIVERY => 'cod',
8789
PayoneConfig::METHOD_DEBIT => 'elv',
8890
PayoneConfig::METHOD_ADVANCE_PAYMENT => 'vor',

Model/Api/Request/Base.php

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,19 @@ abstract class Base
5050
protected $sOrderId = null;
5151

5252
/**
53-
* Array or request parameters
53+
* Array of request parameters
5454
*
5555
* @var array
5656
*/
5757
protected $aParameters = [];
5858

59+
/**
60+
* Array of request headers
61+
*
62+
* @var array
63+
*/
64+
protected $aHeaders = [];
65+
5966
/**
6067
* Response of the request
6168
*
@@ -198,6 +205,17 @@ public function addParameter($sKey, $sValue, $blAddAsNullIfEmpty = false)
198205
$this->aParameters[$sKey] = $sValue;
199206
}
200207

208+
/**
209+
* Adds a header to the collection of headers.
210+
*
211+
* @param string $sHeader
212+
* @return void
213+
*/
214+
public function addHeader($sHeader)
215+
{
216+
$this->aHeaders[] = $sHeader;
217+
}
218+
201219
/**
202220
* Remove parameter from request
203221
*
@@ -234,6 +252,16 @@ public function getParameters()
234252
{
235253
return $this->aParameters;
236254
}
255+
256+
/**
257+
* Return headers
258+
*
259+
* @return array
260+
*/
261+
public function getHeaders()
262+
{
263+
return $this->aHeaders;
264+
}
237265

238266
/**
239267
* Set response array
@@ -327,6 +355,16 @@ protected function validateParameters()
327355
return true;
328356
}
329357

358+
/**
359+
* Retrieve the API URL.
360+
*
361+
* @return string
362+
*/
363+
protected function getApiUrl()
364+
{
365+
return $this->sApiUrl;
366+
}
367+
330368
/**
331369
* Send the previously prepared request, log request and response into the database and return the response
332370
@@ -342,9 +380,9 @@ protected function send(?PayoneMethod $oPayment = null)
342380
if (!$this->validateParameters()) {// all base parameters existing?
343381
return ["errormessage" => "Payone API Setup Data not complete (API-URL, MID, AID, PortalID, Key, Mode)"];
344382
}
345-
346-
$sRequestUrl = $this->apiHelper->getRequestUrl($this->getParameters(), $this->sApiUrl);
347-
$aResponse = $this->apiHelper->sendApiRequest($sRequestUrl); // send request to PAYONE
383+
384+
$sRequestUrl = $this->apiHelper->getRequestUrl($this->getParameters(), $this->getApiUrl());
385+
$aResponse = $this->apiHelper->sendApiRequest($sRequestUrl, $this->getHeaders()); // send request to PAYONE
348386

349387
$this->setResponse($aResponse);
350388

Model/Api/Request/GetJWT.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 8
18+
*
19+
* @category Payone
20+
* @package Payone_Magento2_Plugin
21+
* @author FATCHIP GmbH <support@fatchip.de>
22+
* @copyright 2003 - 2026 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\Model\Api\Request;
28+
29+
use Payone\Core\Model\Methods\PayoneMethod;
30+
31+
/**
32+
* Class for the PAYONE Server API request "getJWT"
33+
*/
34+
class GetJWT extends Base
35+
{
36+
/**
37+
* Send request "getJWT" to PAYONE server API
38+
*
39+
* @param PayoneMethod $oPayment
40+
* @return array
41+
*/
42+
public function sendRequest(PayoneMethod $oPayment)
43+
{
44+
$this->addParameter('request', 'getJWT'); // Request method
45+
$this->addParameter('mode', $oPayment->getOperationMode());
46+
47+
$this->addHeader('Accept: text/plain'); // Request will receive no response without an Accept header
48+
49+
$aResponse = $this->send($oPayment);
50+
51+
return $aResponse;
52+
}
53+
}

0 commit comments

Comments
 (0)