Skip to content

Inconsistencies in Supported Countries List #16

@Alexander01998

Description

@Alexander01998

Describe the bug

If you request a price preview for a customer_ip_address located in Nicaragua, a ValueError is thrown with the message 'NI' is not a valid CountryCode. I can't share the IP address for privacy reasons, but the same bug also occurs if you manually try to construct the AddressPreview object with a country_code of NI.

Steps to reproduce

Run this:

from paddle_billing.Entities.Shared import AddressPreview

this_will_fail = AddressPreview.from_dict({"postal_code": None, "country_code": "NI"})

You will get the following error:

Traceback (most recent call last):
  File "C:\...\bug.py", line 3, in <module>
    this_will_fail = AddressPreview.from_dict({"postal_code": None, "country_code": "NI"})
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\.venv\Lib\site-packages\paddle_billing\Entities\Shared\AddressPreview.py", line 17, in from_dict
    country_code = CountryCode(data['country_code']),
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\enum.py", line 744, in __call__
    return cls.__new__(cls, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\enum.py", line 1158, in __new__
    raise ve_exc
ValueError: 'NI' is not a valid CountryCode

Or, if you have an IP address from Nicaragua to test with:

import paddle_billing
from paddle_billing.Entities.PricingPreviews import PricePreviewItem
from paddle_billing.Resources.PricingPreviews.Operations import PreviewPrice

paddle = paddle_billing.Client(YOUR_API_KEY)

this_will_fail = paddle.pricing_previews.preview_prices(
	PreviewPrice(
		items=[PricePreviewItem(price_id=A_VALID_PRICE_ID, quantity=1)],
		customer_ip_address=AN_IP_FROM_NICARAGUA,
	)
)

And then you get this error:

Traceback (most recent call last):
  File "C:\...\bug.py", line 7, in <module>
    this_will_fail = paddle.pricing_previews.preview_prices(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\.venv\Lib\site-packages\paddle_billing\Resources\PricingPreviews\PricingPreviewsClient.py", line 20, in preview_prices
    return PricePreview.from_dict(parser.get_data())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\.venv\Lib\site-packages\paddle_billing\Entities\PricePreview.py", line 30, in from_dict
    address                   = AddressPreview.from_dict(data['address']) if data.get('address') else None,
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\.venv\Lib\site-packages\paddle_billing\Entities\Shared\AddressPreview.py", line 17, in from_dict
    country_code = CountryCode(data['country_code']),
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\enum.py", line 744, in __call__
    return cls.__new__(cls, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\enum.py", line 1158, in __new__
    raise ve_exc
ValueError: 'NI' is not a valid CountryCode

Expected behavior

NI should be an accepted country code in paddle_billing.Entities.Shared.AddressPreview, because it's possible for Paddle's servers to respond with an address object that has the country code NI.

Alternatively, it should not be possible for Paddle's servers to respond with an address that has a country code of NI. (Though I'd recommend the former solution, since Nicaragua obviously is a valid country.)

Code snippets

See repro steps above.

Python version

Python 3.12

SDK version

paddle-python-sdk==0.1.3

API version

Paddle Version 1 (default)

Additional context

Update: The same problem happens with Russia (RU).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions