|
|
|
@ -53,10 +53,10 @@ class Stepper |
|
|
|
|
|
|
|
public function onSubmit() |
|
|
|
{ |
|
|
|
$client = new Client(); |
|
|
|
$client = new Client(['http_errors' => false]); |
|
|
|
|
|
|
|
$payload = json_decode(file_get_contents('php://input'), true); |
|
|
|
$client->post($this->baseUrl . '/api/lead', [ |
|
|
|
$response = $client->post($this->baseUrl . '/api/lead', [ |
|
|
|
'json' => $payload, |
|
|
|
'headers' => [ |
|
|
|
'Accept' => 'application/json', |
|
|
|
@ -64,6 +64,19 @@ class Stepper |
|
|
|
'Authorization' => 'Bearer ' . $this->token(), |
|
|
|
] |
|
|
|
]); |
|
|
|
|
|
|
|
if ($response->getStatusCode() === 401) { |
|
|
|
$this->error('Anmeldung fehlgeschlagen.'); |
|
|
|
} |
|
|
|
|
|
|
|
if ($response->getStatusCode() === 500) { |
|
|
|
$this->error('Ein Fehler ist aufgetreten.'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private function error(string $error): void |
|
|
|
{ |
|
|
|
wp_send_json(['message' => '', 'errors' => ['error' => [$error]]], 422); |
|
|
|
} |
|
|
|
|
|
|
|
protected function token(): string |
|
|
|
|