From 3758b83901f20a8ed912ab486ea39d50ff4b0f35 Mon Sep 17 00:00:00 2001 From: feliixx Date: Wed, 25 Sep 2024 08:36:01 +0200 Subject: [PATCH 1/2] TaxID: Correctly set country for non 'eu_vat' taxIDs 'au_abn' and 'nz_gst' are numbers with only digits, they don't contain their country code. We can only guess the country from 'eu_vat' taxIDs, so let's adapt the code to better handle AU and NZ taxIDs number. See [the Stripe documentation] for the exact format of these two taxIDs number. [the Stripe documentation]: https://docs.stripe.com/billing/customer/tax-ids --- localstripe/resources.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/localstripe/resources.py b/localstripe/resources.py index 5d74d94..5208990 100644 --- a/localstripe/resources.py +++ b/localstripe/resources.py @@ -3276,7 +3276,13 @@ def __init__(self, country=None, customer=None, type=None, value=None, assert type in ('eu_vat', 'nz_gst', 'au_abn') assert _type(value) is str and len(value) > 10 if country is None: - country = value[0:2] + if type == 'eu_vat': + country = value[0:2] + elif type in ('nz_gst', 'au_abn'): + 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') From 81a4c54170764d8c3e2fffd1ea99424a4040dcc8 Mon Sep 17 00:00:00 2001 From: Guillaume Couzy Date: Wed, 25 Sep 2024 08:21:27 +0200 Subject: [PATCH 2/2] 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 | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/localstripe/resources.py b/localstripe/resources.py index 5208990..6c7b8b2 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,12 +3281,16 @@ 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 in ('nz_gst', 'au_abn'): + elif type in ('nz_gst', 'au_abn', 'es_cif'): country = type[0:2].upper() else: # shouldn't happen because type is checked above