Skip to content
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

Inconsistencies in Supported Countries List #16

Open
Alexander01998 opened this issue Jul 12, 2024 · 6 comments · Fixed by #20
Open

Inconsistencies in Supported Countries List #16

Alexander01998 opened this issue Jul 12, 2024 · 6 comments · Fixed by #20
Assignees

Comments

@Alexander01998
Copy link

Alexander01998 commented Jul 12, 2024

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
Copy link
Contributor

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
Copy link
Contributor

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

@Alexander01998
Copy link
Author

Alexander01998 commented Aug 11, 2024

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.

@Alexander01998 Alexander01998 changed the title Country Code NI (Nicaragua) is missing Inconsistencies in Supported Countries List Aug 11, 2024
@mikeymike mikeymike reopened this Aug 11, 2024
@mikeymike
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

vifer commented Aug 19, 2024

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.

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

Successfully merging a pull request may close this issue.

3 participants