10.April 2026

This commit is contained in:
Kevin Adametz 2026-04-10 17:15:27 +02:00
parent a00c42e770
commit f58c709945
208 changed files with 19280 additions and 2914 deletions

View file

@ -1,4 +1,5 @@
<?php
/**
* This class is a wrapper to be able to send arrays of Payone request
* to the Payone platform.
@ -16,8 +17,8 @@
* You should have received a copy of the GNU General Public License
* along with Payone Connector. If not, see <http://www.gnu.org/licenses/>.
*
* @package Simple PHP Integration
* @link https://www.bspayone.com/
*
* @copyright (C) BS PAYONE GmbH 2016, 2018
* @author Florian Bender <florian.bender@bspayone.com>
* @author Timo Kuchel <timo.kuchel@bspayone.com>
@ -26,87 +27,124 @@
namespace App\Services;
//require 'vendor/autoload.php';
// require 'vendor/autoload.php';
use Exception;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use Psr\Http\Message\ResponseInterface;
/**
* Class Payone
*/
class Payone {
class Payone
{
/**
* The URL of the Payone API
*/
const PAYONE_SERVER_API_URL = 'https://api.pay1.de/post-gateway/';
const PAYONE_CLIENT_API_URL = 'https://secure.pay1.de/client-api/';
/**
* performing the HTTP POST request to the PAYONE platform
*
* @param array $request
* @param string $responsetype
* @throws Exception
* @param array $request
* @param string $responsetype
* @param Client|null $client Optional Guzzle client (e.g. mocked in tests).
* @return array|\Psr\Http\Message\StreamInterface Returns an array of response
* parameters in "classic" mode, a Stream for any other mode.
* parameters in "classic" mode, a Stream for any other mode.
*
* @throws Exception
*/
public static function sendRequest($request, $responsetype = "")
public static function sendRequest($request, $responsetype = '', ?Client $client = null)
{
if ($responsetype === "json") {
// appends the accept: application/json header to the request
// This is used to retrieve structured JSON in the response
// $client = new Client(['headers' => ['accept' => 'application/json', 'content-type' => 'text/plain;charset=UTF-8']]);
$client = new Client(['headers' => ['accept' => 'application/json']]);
}
else {
// if $responsetype is set to anything else than "json", use the standard request
// $client = new Client(['headers' => ['content-type' => 'text/plain;charset=UTF-8']]);
$client = new Client();
if ($client === null) {
if ($responsetype === 'json') {
// appends the accept: application/json header to the request
// This is used to retrieve structured JSON in the response
// $client = new Client(['headers' => ['accept' => 'application/json', 'content-type' => 'text/plain;charset=UTF-8']]);
$client = new Client(['headers' => ['accept' => 'application/json']]);
} else {
// if $responsetype is set to anything else than "json", use the standard request
// $client = new Client(['headers' => ['content-type' => 'text/plain;charset=UTF-8']]);
$client = new Client;
}
}
// echo "Requesting...";
// echo "Requesting...";
$begin = microtime(true);
$userMessage = 'Der Zahlungsanbieter ist nicht erreichbar, die Zahlung konnte nicht durchgeführt werden. Bitte versuchen Sie es später erneut. Fehlercode: 1002';
try {
$response = $client->request('POST', self::PAYONE_SERVER_API_URL, ['form_params' => $request]);
}
catch (\GuzzleHttp\Exception\ClientException $e) {
} catch (BadResponseException $e) {
$error = $e->getResponse();
$responseBodyAsString = $error->getBody()->getContents();
MyLog::writeLog(
'payone',
'error',
'Error:1002 Der Zahlungsanbieter ist nicht erreichbar, die Zahlung konnte nicht durchgeführt werden. App\Services\Payone::sendRequest Something went wrong during the HTTP request.',
'payone',
'error',
'Error:1002 Der Zahlungsanbieter ist nicht erreichbar, die Zahlung konnte nicht durchgeführt werden. App\Services\Payone::sendRequest HTTP-Fehlerantwort (4xx/5xx).',
['error' => $error, 'responseBodyAsString' => $responseBodyAsString, 'request' => $request]
);
abort(403, 'Der Zahlungsanbieter ist nicht erreichbar, die Zahlung konnte nicht durchgeführt werden. Bitte versuchen Sie es später erneut. Fehlercode: 1002');
abort(403, $userMessage);
} catch (ConnectException $e) {
MyLog::writeLog(
'payone',
'error',
'Error:1002 Der Zahlungsanbieter ist nicht erreichbar, die Zahlung konnte nicht durchgeführt werden. App\Services\Payone::sendRequest Netzwerk-/Transportfehler (keine HTTP-Antwort).',
[
'exception' => $e->getMessage(),
'request' => $request,
]
);
abort(403, $userMessage);
} catch (RequestException $e) {
if ($e->hasResponse()) {
$error = $e->getResponse();
$responseBodyAsString = $error !== null ? $error->getBody()->getContents() : '';
MyLog::writeLog(
'payone',
'error',
'Error:1002 Der Zahlungsanbieter ist nicht erreichbar, die Zahlung konnte nicht durchgeführt werden. App\Services\Payone::sendRequest HTTP-Fehlerantwort.',
['error' => $error, 'responseBodyAsString' => $responseBodyAsString, 'request' => $request]
);
} else {
MyLog::writeLog(
'payone',
'error',
'Error:1002 Der Zahlungsanbieter ist nicht erreichbar, die Zahlung konnte nicht durchgeführt werden. App\Services\Payone::sendRequest Transportfehler (RequestException ohne Antwort).',
[
'exception' => $e->getMessage(),
'request' => $request,
]
);
}
}
abort(403, $userMessage);
}
if (isset($response)) {
if (implode($response->getHeader('Content-Type')) == 'text/plain;charset=UTF-8'){
if (implode($response->getHeader('Content-Type')) == 'text/plain;charset=UTF-8') {
// if the content type is text/plain, parse response into array
$return = self::parseResponse($response);
// \Log::channel('payone')->error('App\Services\Payone::sendRequest content type is text/plain: '.$response);
} else {
// if the content type is anything else, just return the response body
$return = json_decode($response->getBody(),true);
$return = json_decode($response->getBody(), true);
MyLog::writeLog(
'payone',
'error',
'Error: App\Services\Payone::sendRequest content type is anything else',
'payone',
'error',
'Error: App\Services\Payone::sendRequest content type is anything else',
['error' => $return, 'response' => $response, 'request' => $request]
);
}
} else {
MyLog::writeLog(
'payone',
'error',
'Error: App\Services\Payone::sendRequest Something went wrong during the HTTP request',
'payone',
'error',
'Error: App\Services\Payone::sendRequest Something went wrong during the HTTP request',
['request' => $request]
);
throw new Exception('Something went wrong during the HTTP request.');
@ -114,60 +152,62 @@ class Payone {
$end = microtime(true);
$duration = $end - $begin;
if(!is_array($return)){
if (! is_array($return)) {
MyLog::writeLog(
'payone',
'error',
'Error: 1003 App\Http\Controllers\Pay\PayoneController::ResponseData response is non array: return:',
['return'=>$return, 'response' => $response, 'request' => $request]
'payone',
'error',
'Error: 1003 App\Http\Controllers\Pay\PayoneController::ResponseData response is non array: return:',
['return' => $return, 'response' => $response, 'request' => $request]
);
abort(403, 'Der Zahlungsanbieter ist nicht erreichbar, die Zahlung konnte nicht durchgeführt werden. Bitte versuchen Sie es später erneut. Fehlercode: 1003');
}
if(!isset($return['status'])){
if (! isset($return['status'])) {
MyLog::writeLog(
'payone',
'error',
'Error: 1004 App\Http\Controllers\Pay\PayoneController::ResponseData response has non status',
['return'=>$return, 'response' => $response, 'request' => $request]
'payone',
'error',
'Error: 1004 App\Http\Controllers\Pay\PayoneController::ResponseData response has non status',
['return' => $return, 'response' => $response, 'request' => $request]
);
abort(403, 'Der Zahlungsanbieter ist nicht erreichbar, die Zahlung konnte nicht durchgeführt werden. Bitte versuchen Sie es später erneut. Fehlercode: 1004');
}
/* echo "done.\n";
echo "Request took " . $duration . " seconds.\n";
echo "<br>";
*/
/* echo "done.\n";
echo "Request took " . $duration . " seconds.\n";
echo "<br>";
*/
return $return;
}
/**
* gets response string an puts it into an array
*
* @param \Psr\Http\Message\ResponseInterface $response
* @throws Exception
* @return array
*
* @throws Exception
*/
public static function parseResponse(ResponseInterface $response)
{
$responseArray = array();
$responseArray = [];
$explode = explode("\n", $response->getBody());
foreach ($explode as $e) {
$keyValue = explode("=", $e);
if (trim($keyValue[0]) != "") {
$keyValue = explode('=', $e);
if (trim($keyValue[0]) != '') {
if (count($keyValue) == 2) {
$responseArray[$keyValue[0]] = trim($keyValue[1]);
} else {
$key = $keyValue[0];
unset($keyValue[0]);
$value = implode("=", $keyValue);
$value = implode('=', $keyValue);
$responseArray[$key] = $value;
}
}
}
/*if ($responseArray['status'] == "ERROR") {
$msg = "Payone returned an error:\n" . print_r($responseArray, true);
throw new Exception($msg);
}*/
/*if ($responseArray['status'] == "ERROR") {
$msg = "Payone returned an error:\n" . print_r($responseArray, true);
throw new Exception($msg);
}*/
return $responseArray;
}
}