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

TaxID: Add support for Spanish CIF #227

Merged
merged 2 commits into from
Sep 25, 2024
Merged
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
32 changes: 25 additions & 7 deletions localstripe/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,12 @@ def __init__(self, name=None, description=None, email=None,
for data in tax_id_data:
assert type(data) is dict
assert set(data.keys()) == {'type', 'value'}
assert data['type'] in ('eu_vat', 'nz_gst', 'au_abn')
assert type(data['value']) is str and len(data['value']) > 10
assert data['type'] in ('eu_vat', 'nz_gst', 'au_abn', 'es_cif')
assert type(data['value']) is str
if data['type'] == 'es_cif':
assert len(data['value']) == 9
else:
assert len(data['value']) > 10
if payment_method is not None:
assert type(payment_method) is str
assert type(balance) is int
Expand Down Expand Up @@ -928,8 +932,12 @@ def _api_add_tax_id(cls, id, type=None, value=None, **kwargs):
raise UserError(400, 'Unexpected ' + ', '.join(kwargs.keys()))

try:
assert type in ('eu_vat', 'nz_gst', 'au_abn')
assert _type(value) is str and len(value) > 10
assert type in ('eu_vat', 'nz_gst', 'au_abn', 'es_cif')
assert _type(value) is str
if type == 'es_cif':
assert len(value) == 9
else:
assert len(value) > 10
except AssertionError:
raise UserError(400, 'Bad request')

Expand Down Expand Up @@ -3273,10 +3281,20 @@ def __init__(self, country=None, customer=None, type=None, value=None,
try:
assert _type(customer) is str
assert customer.startswith('cus_')
assert type in ('eu_vat', 'nz_gst', 'au_abn')
assert _type(value) is str and len(value) > 10
assert type in ('eu_vat', 'nz_gst', 'au_abn', 'es_cif')
assert _type(value) is str
if type == 'es_cif':
assert len(value) == 9
else:
assert len(value) > 10
if country is None:
country = value[0:2]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably just me, but I don't fully understand this commit. More precisely why not just put .upper() here?
Or said otherwise, why add an if/else?

Copy link
Collaborator Author

@feliixx feliixx Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sample eu_vat: ATU12345678 (for Austria, country code: AT)
sample au_abn: 12345678912
sample nz_gst: 123456789

(cf https://docs.stripe.com/billing/customer/tax-ids)

We can use the first two characters of the value is the country code only for eu_vat. For the two others taxIDs, it's the first two characters of the type (and it seems nice to use this), hence the if/else.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, my bad, I didn't read the code carefully enough.

Thanks for the explanation!

if type == 'eu_vat':
country = value[0:2]
elif type in ('nz_gst', 'au_abn', 'es_cif'):
country = type[0:2].upper()
else:
# shouldn't happen because type is checked above
assert False
assert _type(country) is str
except AssertionError:
raise UserError(400, 'Bad request')
Expand Down
Loading