get($endpoint, ['command' => $command] + $payload) ->throw(); $xml = simplexml_load_string((string) $response->body(), SimpleXMLElement::class, LIBXML_NOCDATA); if (! $xml instanceof SimpleXMLElement) { throw new RuntimeException('Oxxa returned invalid XML.'); } $responseData = $this->xmlToArray($xml); $statusCode = trim((string) data_get($responseData, 'order.status_code', '')); $statusDescription = trim((string) data_get($responseData, 'order.status_description', '')); if ($statusCode === 'XMLERR 1') { return [ 'ok' => false, 'error' => 'Credentials are incorrect. Please change the credentials in the registrar module.', 'status_code' => $statusCode, 'status_description' => $statusDescription, ]; } if (str_contains($statusCode, 'XMLOK')) { return [ 'ok' => true, 'status_code' => $statusCode, 'status_description' => $statusDescription, 'data' => $responseData, ]; } return [ 'ok' => false, 'error' => trim($statusCode.' '.$statusDescription), 'status_code' => $statusCode, 'status_description' => $statusDescription, 'data' => $responseData, ]; } private function xmlToArray(SimpleXMLElement $xml): array { return json_decode(json_encode($xml, JSON_THROW_ON_ERROR), true, 512, JSON_THROW_ON_ERROR); } }