<?php

namespace App\Http\Controllers\api\v1;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class TimbrarController extends Controller
{
    public function timbrar(Request $request)
    { 

        return response()->json([
            'rfc' => $request->input('rfc'),
            'inib64' => $request->input('inib64'),
            'cer' => $request->input('cer'),
            'key' => $request->input('key'),
            'pass' => $request->input('pass')
        ]);

     /*   // Datos necesarios para la solicitud SOAP
        $rfc = $request->input('rfc');
        $inib64 = $request->input('inib64');
        $cer = $request->input('cer');
        $key = $request->input('key');
        $pass = $request->input('pass');
        
        // URL del servicio SOAP
        $url = "https://ini.facturacionmexico.com.mx:443/timbrarini.php";
        
        // Construir el cuerpo del mensaje SOAP
        $xmlRequest = <<<XML
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:wservicewsdl">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:timbrarini1 soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <rfc xsi:type="xsd:string">$rfc</rfc>
         <inib64 xsi:type="xsd:string">$inib64</inib64>
         <cer xsi:type="xsd:string">$cer</cer>
         <key xsi:type="xsd:string">$key</key>
         <pass xsi:type="xsd:string">$pass</pass>
      </urn:timbrarini1>
   </soapenv:Body>
</soapenv:Envelope>
XML;

        // Configuración de la solicitud SOAP
        $soapHeaders = [
            'Content-Type: text/xml',
            'Content-Length: ' . strlen($xmlRequest)
        ];
        
        // Realizar la solicitud SOAP
        $soapClient = new \SoapClient(null, [
            'location' => $url,
            'uri' => "urn:wservicewsdl",
            'trace' => 1,
            'stream_context' => stream_context_create([
                'http' => [
                    'header' => implode("\r\n", $soapHeaders),
                    'method' => 'POST',
                    'content' => $xmlRequest
                ]
            ])
        ]);

        // Procesar la respuesta
        $response = $soapClient->__doRequest($xmlRequest, $url, "timbrarini1", SOAP_1_2);
        
        // Devolver la respuesta como XML
        return response($response, 200)->header('Content-Type', 'text/xml');*/
    }
}