Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Invalid signed properties hashing #52

Open
ashoeb2197 opened this issue Jan 22, 2025 · 4 comments
Open

"Invalid signed properties hashing #52

ashoeb2197 opened this issue Jan 22, 2025 · 4 comments

Comments

@ashoeb2197
Copy link

`"type" => "ERROR"

    "code" => "signed-properties-hashing"

    "category" => "CERTIFICATE_ERRORS"

    "message" => "Invalid signed properties hashing, SignedProperties with id='xadesSignedProperties'"

    "status" => "ERROR"` 

sandbox error always appear for reporting

@thaifanisalla
Copy link
Contributor

@ashoeb2197
can you share the steps for generate the invoice , Or the xml result here ?

@ashoeb2197
Copy link
Author

Thanks for your reply . I solved this error but returned another error that indicates hash in api body doesn't equal to calculated one. I searched and investigated my xml and nothing is wrong
After search i think this is because whitespaces in the XML but i can't solve it . Is there a php function that can generate the proper xml?

@Hazem7575
Copy link

hello @ashoeb2197 how solve this error ?
public function prepareInvoiceData(){

    $invoice = (object)[
        'branch_id' => '0',
        'invoice_no' => '0002',
        'total'=> 1,
        'grand_total'=> 1.15,
        'order_discount'=> 0,//$invoice->order_discount,
        'product_tax'=> 0.15,
        'is_pos' => true,
        'is_invoice'=> true,
        'date' => date('Y-m-d').'T'.date('H:i:s').'Z',
        'customer' => (object)[
            'name' => null,
            'billing_address'=> null,
            'email' => null,
            'tax_number' => null,
            'billing_country' => null,
            'billing_city' => null,
            'billing_state' => null,
            'billing_phone' => null,
            'billing_postal' => null,
            'billing_building' => null
        ]
    ];

    $invoiceItems[] = (object)[
        'product_id' => 100,
        'product_name' => 'Item A',
        'unit_quantity' => 1,
        'net_unit_price' => 1,
        'discount' => 0,
        'item_tax' => 0.15,
        'subtotal' => 1,
        'city_tax' => 0
    ];


    $customer = $invoice->customer;

    return $this->generateXML($invoice,$invoice,$customer,$invoiceItems);

}$UUID = vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex(random_bytes(16)), 4));
    $props = [
        'invoice_serial_number' => $id,
        'uuid' => $UUID,//'3cf5ee18-ee25-44ea-a444-2c37ba7f28be',// vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex(random_bytes(16)), 4)),
        'date' => $now->format('Y-m-d'),
        'time' => $now->format('H:i:s').'Z',
        'previous_invoice_hash' => 'NWZlY2ViNjZmZmM4NmYzOGQ5NTI3ODZjNmQ2OTZjNzljMmRiYzIzOWRkNGU5MWI0NjcyOWQ3M2EyN2ZiNTdlOQ==',
        'invoice_counter_number' => 1,
        'CRN_number' => $vatNo,
        'street' => $address,
        'building' => $building,
        'plot_identification' => $plot_identification,
        'city_subdivision' => $city_subdivision,
        'city' => $city,
        'postal' => $postal,
        'VAT_number' => $vatNo,
        'VAT_name' => $companyName,
        'details' => $details,
        'sale' => $sale,
        'invoice_type' => $invoiceType,
        'invoice_type_no' => $invoiceTypeNo,

        'CRN_number_CUSTOMER' => $customer_vatNo,
        'street_CUSTOMER' => $address,
        'building_CUSTOMER' => $building_customer ? $building_customer : '0000',
        'plot_identification_CUSTOMER' => $plot_identification_customer,
        'city_subdivision_CUSTOMER' => $city_subdivision_customer,
        'city_CUSTOMER' => $city_customer,
        'postal_CUSTOMER' => $postal_customer ? $postal_customer : '00000',
        'total' => $sale->total,
        'grand_total' => $sale->grand_total,
        'product_tax' => $sale->product_tax,
    ];

// dd($props);

    //dd($props);

    $invoiceXML = $this->getDefaultSimplifiedTaxInvoice($props);

    //dd($invoiceXML);

// $sendInvoiceResult = $this->signInvoice($invoiceXML,$UUID,$m_invoice->is_pos,$id,$m_invoice->branch_id,$sale->total,$sale->product_tax,$sale->date);

    $private_key = File::get(public_path('certificate/private_key.pem'));
    $csid = File::get(public_path('certificate/CSID.json'));
    $csid = json_decode($csid, true);
    $binarySecurityToken = $csid['binarySecurityToken'];

    $secret = $csid['secret'];

    $certificate = (new Certificate(
        base64_decode($binarySecurityToken), // get from ZATCA when you exchange the CSR via APIs
        $private_key // generated at stage one
    ))->setSecretKey($secret); // get from ZATCA when you exchange the CSR via APIs

    $invoice = (new InvoiceSign($invoiceXML, $certificate))->sign();

    info($invoice->getInvoice());
    return $this->sendInvoiceToZatca($invoice->getHash(),$UUID,$invoice->getInvoice(),true,$id,0);

Image
im geted this error
Invalid signed properties hashing, SignedProperties with id='xadesSignedProperties

@Hazem7575
Copy link

im solved thanks <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants