PaddleHQ / paddle-python-sdk

Python SDK for working with the Paddle API in server-side apps.
https://developer.paddle.com/
Apache License 2.0
16 stars 3 forks source link

Inconsistencies in Supported Countries List #16

Open Alexander01998 opened 1 month ago

Alexander01998 commented 1 month ago

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).

mikeymike commented 1 month ago

Hi @Alexander01998 ๐Ÿ‘‹

Thanks for raising this issue, there is definitely something we'll investigate further on the SDK side as we would not expect to be seeing a ValueError here.

However, unfortunately Nicaragua is not actually one of our currently supported countries which is why the value option does not exist within the SDK.

I'm going to keep this issue open and come back with updates while we work at making this error case more clear and better handled all around.

mikeymike commented 1 month ago

We've now released v0.2.0 with some changes around enums prevents this error at the SDK level ๐Ÿ‘

Alexander01998 commented 4 weeks ago

Hey @mikeymike, thanks for the update, but there still seems to be a mismatch between which countries the SDK thinks are supported and which countries the API thinks are supported.

For example, I just found out that BL (Saint Barthรฉlemy) is listed in the CountryCode enum, but requesting a price preview for it returns an error. The error message includes a list of supported countries that differs greatly from the CountryCode enum:

address.country_code must be one of the following: \"AD\", \"AE\", \"AF\", \"AG\", \"AI\", \"AL\", \"AM\", \"AN\",
 \"AO\", \"AR\", \"AS\", \"AT\", \"AU\", \"AW\", \"AX\", \"AZ\", \"BA\", \"BB\", \"BD\", \"BE\", \"BF\", \"BG\", \"BH\",
 \"BI\", \"BJ\", \"BM\", \"BN\", \"BO\", \"BQ\", \"BR\", \"BS\", \"BT\", \"BV\", \"BW\", \"BY\", \"BZ\", \"CA\", \"CC\",
 \"CF\", \"CG\", \"CH\", \"CI\", \"CK\", \"CL\", \"CM\", \"CN\", \"CO\", \"CR\", \"CU\", \"CV\", \"CW\", \"CX\", \"CY\",
 \"CZ\", \"DE\", \"DJ\", \"DK\", \"DM\", \"DO\", \"DZ\", \"EC\", \"EE\", \"EG\", \"EH\", \"ER\", \"ES\", \"ET\", \"FI\",
 \"FJ\", \"FK\", \"FM\", \"FO\", \"FR\", \"GA\", \"GB\", \"GD\", \"GE\", \"GF\", \"GG\", \"GH\", \"GI\", \"GL\", \"GM\",
 \"GN\", \"GP\", \"GQ\", \"GR\", \"GS\", \"GT\", \"GU\", \"GW\", \"GY\", \"HK\", \"HM\", \"HN\", \"HR\", \"HT\", \"HU\",
 \"ID\", \"IE\", \"IL\", \"IM\", \"IN\", \"IO\", \"IQ\", \"IR\", \"IS\", \"IT\", \"JE\", \"JM\", \"JO\", \"JP\", \"KE\",
 \"KG\", \"KH\", \"KI\", \"KM\", \"KN\", \"KP\", \"KR\", \"KW\", \"KY\", \"KZ\", \"LA\", \"LB\", \"LC\", \"LI\", \"LK\",
 \"LR\", \"LS\", \"LT\", \"LU\", \"LV\", \"LY\", \"MA\", \"MC\", \"MD\", \"ME\", \"MF\", \"MG\", \"MH\", \"MK\", \"ML\",
 \"MM\", \"MN\", \"MO\", \"MP\", \"MQ\", \"MR\", \"MS\", \"MT\", \"MU\", \"MV\", \"MW\", \"MX\", \"MY\", \"MZ\", \"NA\",
 \"NC\", \"NE\", \"NF\", \"NG\", \"NI\", \"NL\", \"NO\", \"NP\", \"NR\", \"NU\", \"NZ\", \"OM\", \"PA\", \"PE\", \"PF\",
 \"PG\", \"PH\", \"PK\", \"PL\", \"PM\", \"PN\", \"PR\", \"PS\", \"PT\", \"PW\", \"PY\", \"QA\", \"RE\", \"RO\", \"RS\",
 \"RU\", \"RW\", \"SA\", \"SB\", \"SC\", \"SD\", \"SE\", \"SG\", \"SH\", \"SI\", \"SJ\", \"SK\", \"SL\", \"SM\", \"SN\",
 \"SO\", \"SR\", \"ST\", \"SV\", \"SY\", \"SZ\", \"TC\", \"TD\", \"TF\", \"TG\", \"TH\", \"TJ\", \"TK\", \"TL\", \"TM\",
 \"TN\", \"TO\", \"TR\", \"TT\", \"TV\", \"TW\", \"TZ\", \"UA\", \"UG\", \"UM\", \"US\", \"UY\", \"UZ\", \"VA\", \"VC\",
 \"VE\", \"VG\", \"VI\", \"VN\", \"VU\", \"WF\", \"WS\", \"YE\", \"YT\", \"ZA\", \"ZM\", \"ZW\"

As you can see, RU and NI are included in this list, even though they aren't supposed to be supported countries, and BL is missing even though it's supposed to be supported. (There may be other differences that I haven't noticed yet.)

It seems like this might be a bug on the API side where it's using an outdated country list. If the API is maintained by a different team at Paddle, could you please let them know about this bug? It's really frustrating to find all these edge cases where a country works on one side but not the other.

Update: Country code AN, listed in the API response, also doesn't work and is not even a valid ISO 3166-1 alpha-2 country code anymore. According to Wikipedia, it was dissolved into five separate territories in 2010. https://en.wikipedia.org/wiki/ISO_3166-2:AN

Update 2: Country codes SX (Sint Maarten) and XK (Kosovo) are also listed in the CountryCode enum but not supported by the API.

mikeymike commented 3 weeks ago

Hey @Alexander01998 thanks for the extra details around this and the specific examples is great ๐Ÿ™

I'll make sure this is raised with the relevant people here and get some clarity on the behaviour. I'll update here as things progress.

Alexander01998 commented 3 weeks ago

Hey @mikeymike, thanks for the follow-up on this issue and for escalating it with the team! ๐Ÿ‘

By the way, I noticed that v0.2.0 isn't available on PyPi yet. It still shows 0.1.3 as the latest version. Is the new release supposed to be available there?

vifer commented 2 weeks ago

Hey @mikeymike, thanks for the follow-up on this issue and for escalating it with the team! ๐Ÿ‘

By the way, I noticed that v0.2.0 isn't available on PyPi yet. It still shows 0.1.3 as the latest version. Is the new release supposed to be available there?

Hey @Alexander01998, thanks for flagging this, we have just released v0.2.1 on PyPi, there was an issue with one of the pipelines that was suppose to publish to PyPi.