From b15ece7088c48f490b5526733d50a363aaa5a88b Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 25 Dec 2019 22:40:57 +0530 Subject: [PATCH] Validate VAT number only if it is set --- datacenterlight/views.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 3274c480..e2fa8d0f 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -542,22 +542,24 @@ class PaymentOrderView(FormView): else: request.session['customer'] = customer - validate_result = validate_vat_number( - stripe_customer_id=request.session['customer'], - vat_number=address_form.cleaned_data.get('vat_number') - ) - - if 'response_object' in validate_result: - messages.add_message( - request, messages.ERROR, validate_result["error"], - extra_tags='vat_error' - ) - return HttpResponseRedirect( - reverse('datacenterlight:payment') + '#vat_error' + vat_number = address_form.cleaned_data.get('vat_number').strip() + if vat_number: + validate_result = validate_vat_number( + stripe_customer_id=request.session['customer'], + vat_number=address_form.cleaned_data.get('vat_number') ) - request.session["vat_validation_status"] = validate_result["status"] - request.session["vat_validated_on"] = validate_result["validated_on"] + if 'response_object' in validate_result: + messages.add_message( + request, messages.ERROR, validate_result["error"], + extra_tags='vat_error' + ) + return HttpResponseRedirect( + reverse('datacenterlight:payment') + '#vat_error' + ) + + request.session["vat_validation_status"] = validate_result["status"] + request.session["vat_validated_on"] = validate_result["validated_on"] # For generic payment we take the user directly to confirmation if ('generic_payment_type' in request.session and