Move customer data check to separate method
It is already quite complex code, so better separate it. Signed-off-by: Michal Čihař <michal@cihar.com>
This commit is contained in:
parent
95f56a1b4b
commit
837e3191d2
|
|
@ -287,6 +287,8 @@ PAYMENT_FAKTURACE = "/home/nijel/weblate/tmp-fakturace"
|
|||
SSO_SERVER = 'https://hosted.weblate.org/accounts/sso/'
|
||||
SSO_PRIVATE_KEY = None
|
||||
SSO_PUBLIC_KEY = None
|
||||
SSO_PRIVATE_KEY = 'iO4sLg4eRJRz0LbjOJebVYGKyich4jvmtc8xrACJT7lcfSaJibOFwYfuPeXRnalJ'
|
||||
SSO_PUBLIC_KEY = 'mxH8jVEgzAqC4ncvtHQOW0CilYQma96j2y7cYiEv0lKNAxVXT1k992pvNGheNjnk'
|
||||
|
||||
LOGIN_URL = '/sso-login/'
|
||||
|
||||
|
|
|
|||
|
|
@ -88,6 +88,29 @@ class PaymentView(FormView, SingleObjectMixin):
|
|||
)
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
def check_customer(self, customer):
|
||||
if not self.check_customer:
|
||||
return None
|
||||
if customer.is_empty:
|
||||
messages.info(
|
||||
self.request,
|
||||
_(
|
||||
'Please provide your billing information to '
|
||||
'complete the payment.'
|
||||
)
|
||||
)
|
||||
return redirect('payment-customer', pk=self.object.pk)
|
||||
if customer.vat:
|
||||
try:
|
||||
validate_vatin(customer.vat)
|
||||
except ValidationError:
|
||||
messages.warning(
|
||||
self.request,
|
||||
_('The VAT ID is no longer valid, please update it.')
|
||||
)
|
||||
return redirect('payment-customer', pk=self.object.pk)
|
||||
return None
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
with transaction.atomic(using='payments_db'):
|
||||
self.object = self.get_object()
|
||||
|
|
@ -97,25 +120,9 @@ class PaymentView(FormView, SingleObjectMixin):
|
|||
# the web redirect was aborted
|
||||
if self.object.state != Payment.NEW:
|
||||
return self.redirect_origin()
|
||||
if self.check_customer:
|
||||
if customer.is_empty:
|
||||
messages.info(
|
||||
self.request,
|
||||
_(
|
||||
'Please provide your billing information to '
|
||||
'complete the payment.'
|
||||
)
|
||||
)
|
||||
return redirect('payment-customer', pk=self.object.pk)
|
||||
if customer.vat:
|
||||
try:
|
||||
validate_vatin(customer.vat)
|
||||
except ValidationError:
|
||||
messages.warning(
|
||||
self.request,
|
||||
_('The VAT ID is no longer valid, please update it.')
|
||||
)
|
||||
return redirect('payment-customer', pk=self.object.pk)
|
||||
result = self.check_customer()
|
||||
if result is not None:
|
||||
return result
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def form_valid(self, form):
|
||||
|
|
|
|||
Loading…
Reference in New Issue