08 2024
This commit is contained in:
parent
04d677d37a
commit
bfa3bb1df4
1191 changed files with 637397 additions and 10619 deletions
|
|
@ -29,6 +29,7 @@ namespace App\Services;
|
|||
|
||||
//require 'vendor/autoload.php';
|
||||
use Exception;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
|
|
@ -41,7 +42,7 @@ 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//';
|
||||
const PAYONE_CLIENT_API_URL = 'https://secure.pay1.de/client-api/';
|
||||
|
||||
/**
|
||||
* performing the HTTP POST request to the PAYONE platform
|
||||
|
|
@ -57,35 +58,84 @@ class Payone {
|
|||
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']]);
|
||||
// $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();
|
||||
// $client = new Client(['headers' => ['content-type' => 'text/plain;charset=UTF-8']]);
|
||||
$client = new Client();
|
||||
}
|
||||
|
||||
// echo "Requesting...";
|
||||
$begin = microtime(true);
|
||||
try {
|
||||
$response = $client->request('POST', self::PAYONE_SERVER_API_URL, ['form_params' => $request]);
|
||||
}
|
||||
catch (\GuzzleHttp\Exception\ClientException $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.',
|
||||
['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');
|
||||
|
||||
if ($response = $client->request('POST', self::PAYONE_SERVER_API_URL, ['form_params' => $request])) {
|
||||
|
||||
if (implode($response->getHeader('Content-Type')) == 'text/plain; charset=UTF-8'){
|
||||
}
|
||||
if (isset($response)) {
|
||||
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 = $response->getBody();
|
||||
$return = json_decode($response->getBody(),true);
|
||||
MyLog::writeLog(
|
||||
'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',
|
||||
['request' => $request]
|
||||
);
|
||||
throw new Exception('Something went wrong during the HTTP request.');
|
||||
}
|
||||
|
||||
$end = microtime(true);
|
||||
$duration = $end - $begin;
|
||||
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]
|
||||
);
|
||||
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'])){
|
||||
MyLog::writeLog(
|
||||
'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 "Request took " . $duration . " seconds.\n";
|
||||
echo "<br>";
|
||||
*/
|
||||
return $return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue