From d9a16900553ca6ba4fbbf2c7ce35763f9b84102e Mon Sep 17 00:00:00 2001 From: Guillaume Couzy Date: Wed, 25 Sep 2024 08:21:27 +0200 Subject: [PATCH] TaxID: Add support for Spanish CIF MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- localstripe/resources.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/localstripe/resources.py b/localstripe/resources.py index 1de6cc5..dc18001 100644 --- a/localstripe/resources.py +++ b/localstripe/resources.py @@ -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 @@ -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') @@ -3273,8 +3281,12 @@ 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]