Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pyazul/models/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
17 changes: 15 additions & 2 deletions tests/e2e/services/test_payment_page_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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."""
Expand Down
Loading