Skip to content

Commit

Permalink
TaxID: Add support for Spanish CIF
Browse files Browse the repository at this point in the history
According to Stripe's documentation[^1], two Spanish Customer Tax IDs (`eu_vat`
& `es_cif`) are supported.

[^1]: https://docs.stripe.com/billing/customer/tax-ids#supported-tax-id-types

Let's add the support for Spain's _código de identificación fiscal_ (CIF) tax
ID.

Even if Stripe doesn't validate this type of Customer Tax ID (unlike EU
VAT)[^2], the related dashboard form input only checks if the given value's
length is 9.

[^2]: https://docs.stripe.com/billing/customer/tax-ids#validation
  • Loading branch information
GuillaumeCz authored and feliixx committed Sep 25, 2024
1 parent 6a4d0a3 commit 81524fb
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 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,15 +3281,21 @@ 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:
if type == 'eu_vat':
country = value[0:2]
elif type == 'nz_gst':
country = 'NZ'
elif type == 'au_abn':
country = 'AU'
elif type == 'es_cif':
country = 'ES'
assert _type(country) is str
except AssertionError:
raise UserError(400, 'Bad request')
Expand Down

0 comments on commit 81524fb

Please sign in to comment.