mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2025-03-03 13:29:24 +01:00
Merge branch 'OpenXE-org:master' into lieferant-lagerbestand-import
This commit is contained in:
commit
28772ea98d
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
namespace Xentral\Carrier\Go;
|
namespace Xentral\Carrier\Go;
|
||||||
|
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use Xentral\Carrier\Go\Data\CreateOrderRequest;
|
use Xentral\Carrier\Go\Data\CreateOrderRequest;
|
||||||
use Xentral\Carrier\Go\Data\CreateOrderResponse;
|
use Xentral\Carrier\Go\Data\CreateOrderResponse;
|
||||||
use Xentral\Carrier\Go\Data\OrderStatus;
|
use Xentral\Carrier\Go\Data\OrderStatus;
|
||||||
@ -16,7 +17,7 @@ class GoApi {
|
|||||||
|
|
||||||
protected string $baseUrl;
|
protected string $baseUrl;
|
||||||
|
|
||||||
public function __construct(protected string $username, protected string $password, bool $testMode = true) {
|
public function __construct(protected LoggerInterface $logger, protected string $username, protected string $password, bool $testMode = true) {
|
||||||
if ($testMode)
|
if ($testMode)
|
||||||
$this->baseUrl = self::BASE_URL_TEST;
|
$this->baseUrl = self::BASE_URL_TEST;
|
||||||
else
|
else
|
||||||
@ -25,6 +26,12 @@ class GoApi {
|
|||||||
|
|
||||||
public function createOrder(CreateOrderRequest $request): CreateOrderResponse|string {
|
public function createOrder(CreateOrderRequest $request): CreateOrderResponse|string {
|
||||||
$curl = curl_init();
|
$curl = curl_init();
|
||||||
|
try {
|
||||||
|
$json = json_encode($request, JSON_THROW_ON_ERROR|JSON_PRETTY_PRINT);
|
||||||
|
$this->logger->debug('GO-API Create Order Request', ['json' => $json]);
|
||||||
|
} catch (JsonException $e) {
|
||||||
|
return 'Internal Error: '.$e->getMessage();
|
||||||
|
}
|
||||||
curl_setopt_array($curl, [
|
curl_setopt_array($curl, [
|
||||||
CURLOPT_RETURNTRANSFER => 1,
|
CURLOPT_RETURNTRANSFER => 1,
|
||||||
CURLOPT_URL => $this->baseUrl.'createOrder',
|
CURLOPT_URL => $this->baseUrl.'createOrder',
|
||||||
@ -32,13 +39,15 @@ class GoApi {
|
|||||||
CURLOPT_USERNAME => $this->username,
|
CURLOPT_USERNAME => $this->username,
|
||||||
CURLOPT_PASSWORD => $this->password,
|
CURLOPT_PASSWORD => $this->password,
|
||||||
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
||||||
CURLOPT_POSTFIELDS => json_encode($request, JSON_THROW_ON_ERROR),
|
CURLOPT_POSTFIELDS => $json,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response = json_decode(curl_exec($curl));
|
$response = json_decode(curl_exec($curl));
|
||||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
|
|
||||||
|
$this->logger->debug('GO-API Create Order Response', ['response' => $response, 'code' => $code]);
|
||||||
|
|
||||||
if ($code == 200) {
|
if ($code == 200) {
|
||||||
$ret = new CreateOrderResponse();
|
$ret = new CreateOrderResponse();
|
||||||
$ret->hwbNumber = $response->hwbNumber;
|
$ret->hwbNumber = $response->hwbNumber;
|
||||||
|
@ -27,7 +27,12 @@ class Versandart_go extends Versanddienstleister
|
|||||||
parent::__construct($app, $id);
|
parent::__construct($app, $id);
|
||||||
if (!isset($this->id) || !isset($this->settings->username) || !isset($this->settings->password))
|
if (!isset($this->id) || !isset($this->settings->username) || !isset($this->settings->password))
|
||||||
return;
|
return;
|
||||||
$this->api = new GoApi($this->settings->username, $this->settings->password, $this->settings->useTestEndpoint ?? true);
|
$this->api = new GoApi(
|
||||||
|
$this->app->Container->get('Logger'),
|
||||||
|
$this->settings->username,
|
||||||
|
$this->settings->password,
|
||||||
|
$this->settings->useTestEndpoint ?? true,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetName(): string
|
public function GetName(): string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user