ZATCA
ZATCA copied to clipboard
PublicKey not found in Certificate when trying to Sign the XML Invoice
I started my process with Generating a CSRRequest
$CSRRequest = CSRRequest::make()
->setUID($OrganizationIdentifier)
->setSerialNumber($solutionName, $version,$serialNumber)
->setCommonName($commonName)
->setCountryName('SA')
->setOrganizationName($organizationName)
->setOrganizationalUnitName($organizationalUnitName)
->setRegisteredAddress($registeredAddress)
->setInvoiceType(true, true) //invoice types , the default is true, true
->setCurrentZatcaEnv($currentEnv) //support all modes ['sandbox','simulation','core']
->setBusinessCategory($businessCategory);
$CSR = GenerateCSR::fromRequest($CSRRequest)->initialize()->generate();
openssl_pkey_export($CSR->getPrivateKey(), $privateKey);
$csr_content = $CSR->getCsrContent();
Then get the Private Key and CSRContent and pass it to API to get the Secret
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://gw-fatoora.zatca.gov.sa/e-invoicing/developer-portal/compliance',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>json_encode(array('csr'=>base64_encode($csr_content))),
CURLOPT_HTTPHEADER => array(
'OTP: 123345',
'Accept-Version: V2',
'Content-Type: application/json',
),
));
$response = curl_exec($curl);
curl_close($curl);
// Compliance CSID (Certificate)
$rData = json_decode($response,true);
Till this point it is working fine
Now i want to generate the certificate and sign the XML E Invoice when i generate the certificate it goes on without any error but when i am trying to sign the XML Invoice it is throwing this error
$invoice = (new InvoiceSign($xmlInvoice, $certificate))->sign();
And IF i use This
$tags = UXML::fromString($xmlInvoice)->toTagsArray($certificate, null, null);
$QRCodeAsBase64 = GenerateQrCode::fromArray($tags)->toBase64();
If i vardump the $certificate i get following result looks like its all empty
Can you point out any thing that i am doing wrong here
Thanks
@thaifanisalla and @SallaDev