Skip to content

customer_document rejected when leading zeros are present in call to /v1/charges #9

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

Open
bgeneto opened this issue Feb 18, 2025 · 1 comment

Comments

@bgeneto
Copy link
Contributor

bgeneto commented Feb 18, 2025

Description:

The listCharges method in the EfiPay library throws an EfiException when the customer_document parameter contains leading zeros, even though the documentation suggests it should accept CPF or CNPJ strings. The error message indicates an incorrect document format, likely due to an internal conversion to an integer that strips the leading zeros. This prevents valid CPF/CNPJ numbers with leading zeros from being used.

Steps to Reproduce:

  1. Use the following code snippet (or similar) with a customer_document value containing leading zeros:

    <?php
    
    use Efi\Exception\EfiException;
    use Efi\EfiPay;
    
    // Replace with your actual options
    $options = [
        'sandbox' => true, // Or false for production
        'client_id' => 'YOUR_CLIENT_ID',
        'client_secret' => 'YOUR_CLIENT_SECRET',
        'certificate' => '/path/to/your/certificate.pem',
    ];
    
    $params = [
        "charge_type" => "subscription",
        "begin_date" => "2024-02-18",
        "end_date" => "2025-02-18",
        "customer_document" => "03973638004" // CPF with leading zero
    ];
    
    try {
        $api = new EfiPay($options);
        $response = $api->listCharges($params);
        print_r($response);
    } catch (EfiException $e) {
        print_r($e->code . "<br>");
        print_r($e->error . "<br>");
        print_r($e->errorDescription) . "<br>");
    }
  2. Execute the PHP script.

Expected Result:

The listCharges method should successfully execute and return a list of charges (or an empty list if no matching charges are found). The customer_document should be accepted as a valid string.

Actual Result:

An EfiException is thrown with the following error message (or similar, depending on the specific document number):

EfiException: Propriedade: "3973638004". documento 3973638004 incorreto
@guilherme-cota-efi
Copy link
Member

We have identified that the "customer_document" parameter is being treated as an integer, which removes the leading zero.

Our engineering team will work on a fix, and we will update you here as soon as we have more information!

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

2 participants