diff --git a/pyazul/models/schemas.py b/pyazul/models/schemas.py index 13a7973..282ba65 100644 --- a/pyazul/models/schemas.py +++ b/pyazul/models/schemas.py @@ -68,7 +68,7 @@ def _validate_itbis_field(v: Union[str, int, float, None], info) -> str: ValueError: If value is negative or not a valid number """ if v is None: - return "0" + return "000" if isinstance(v, float): # Convert float to int (cents) then to str v = str(int(v)) @@ -84,6 +84,9 @@ def _validate_itbis_field(v: Union[str, int, float, None], info) -> str: if numeric_val < 0: raise ValueError(f"{info.field_name} ('{v}') must be non-negative.") + if numeric_val == 0: + return "000" + return str(numeric_val) diff --git a/pyproject.toml b/pyproject.toml index 7a4f79e..c92e19c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "pyazul" -version = "3.2.0" +version = "3.2.1" description = "An Azul Webservices light wrapper for Python." authors = [{ name = "INDEXA Inc.", email = "info@indexa.do" }] license = { text = "MIT License" } diff --git a/tests/e2e/services/test_payment_page_integration.py b/tests/e2e/services/test_payment_page_integration.py index 9e1b8a4..564a6dd 100644 --- a/tests/e2e/services/test_payment_page_integration.py +++ b/tests/e2e/services/test_payment_page_integration.py @@ -38,7 +38,7 @@ def test_valid_amounts(self): assert model.ITBIS == "18000" def test_zero_itbis_format(self): - """Test that zero ITBIS is formatted as '0'.""" + """Test that zero ITBIS is formatted as '000'.""" model = PaymentPage( OrderNumber=generate_order_number(), Amount="100000", @@ -48,7 +48,20 @@ def test_zero_itbis_format(self): CancelUrl=HttpUrl("https://example.com/cancel"), AltMerchantName=None, ) - assert model.ITBIS == "0" + assert model.ITBIS == "000" + + def test_none_itbis_format(self): + """Test that none ITBIS is formatted as '000'.""" + model = PaymentPage( + OrderNumber=generate_order_number(), + Amount="100000", + ITBIS=None, + ApprovedUrl=HttpUrl("https://example.com/approved"), + DeclineUrl=HttpUrl("https://example.com/declined"), + CancelUrl=HttpUrl("https://example.com/cancel"), + AltMerchantName=None, + ) + assert model.ITBIS == "000" def test_invalid_amount_format(self): """Test that invalid amount formats are rejected."""