Skip to content

Commit 415a61d

Browse files
Guillaume Couzyfeliixx
Guillaume Couzy
authored andcommitted
TaxID: Add support for Spanish CIF
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
1 parent 6a4d0a3 commit 415a61d

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

localstripe/resources.py

+20-6
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,12 @@ def __init__(self, name=None, description=None, email=None,
759759
for data in tax_id_data:
760760
assert type(data) is dict
761761
assert set(data.keys()) == {'type', 'value'}
762-
assert data['type'] in ('eu_vat', 'nz_gst', 'au_abn')
763-
assert type(data['value']) is str and len(data['value']) > 10
762+
assert data['type'] in ('eu_vat', 'nz_gst', 'au_abn', 'es_cif')
763+
assert type(data['value']) is str
764+
if data['type'] == 'es_cif':
765+
assert len(data['value']) == 9
766+
else:
767+
assert len(data['value']) > 10
764768
if payment_method is not None:
765769
assert type(payment_method) is str
766770
assert type(balance) is int
@@ -928,8 +932,12 @@ def _api_add_tax_id(cls, id, type=None, value=None, **kwargs):
928932
raise UserError(400, 'Unexpected ' + ', '.join(kwargs.keys()))
929933

930934
try:
931-
assert type in ('eu_vat', 'nz_gst', 'au_abn')
932-
assert _type(value) is str and len(value) > 10
935+
assert type in ('eu_vat', 'nz_gst', 'au_abn', 'es_cif')
936+
assert _type(value) is str and len(value) == 9
937+
if type == 'es_cif':
938+
assert len(value) == 9
939+
else:
940+
assert len(value) > 10
933941
except AssertionError:
934942
raise UserError(400, 'Bad request')
935943

@@ -3273,15 +3281,21 @@ def __init__(self, country=None, customer=None, type=None, value=None,
32733281
try:
32743282
assert _type(customer) is str
32753283
assert customer.startswith('cus_')
3276-
assert type in ('eu_vat', 'nz_gst', 'au_abn')
3277-
assert _type(value) is str and len(value) > 10
3284+
assert type in ('eu_vat', 'nz_gst', 'au_abn', 'es_cif')
3285+
assert _type(value) is str
3286+
if type == 'es_cif':
3287+
assert len(value) == 9
3288+
else:
3289+
assert len(value) > 10
32783290
if country is None:
32793291
if type == 'eu_vat':
32803292
country = value[0:2]
32813293
elif type == 'nz_gst':
32823294
country = 'NZ'
32833295
elif type == 'au_abn':
32843296
country = 'AU'
3297+
elif type == 'es_cif':
3298+
country = 'ES'
32853299
assert _type(country) is str
32863300
except AssertionError:
32873301
raise UserError(400, 'Bad request')

0 commit comments

Comments
 (0)