Also handle ch_vat
This commit is contained in:
parent
908c2e055c
commit
4a40438edc
3 changed files with 13 additions and 7 deletions
|
@ -131,7 +131,7 @@ def check_otp(name, realm, token):
|
||||||
return response.status_code
|
return response.status_code
|
||||||
|
|
||||||
|
|
||||||
def validate_vat_number(stripe_customer_id, vat_number):
|
def validate_vat_number(stripe_customer_id, vat_number, country):
|
||||||
try:
|
try:
|
||||||
billing_address = BillingAddress.objects.get(vat_number=vat_number)
|
billing_address = BillingAddress.objects.get(vat_number=vat_number)
|
||||||
except BillingAddress.DoesNotExist as dne:
|
except BillingAddress.DoesNotExist as dne:
|
||||||
|
@ -163,9 +163,13 @@ def validate_vat_number(stripe_customer_id, vat_number):
|
||||||
"validated_on": ""
|
"validated_on": ""
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
tax_id_obj = create_tax_id(stripe_customer_id, vat_number)
|
tax_id_obj = create_tax_id(
|
||||||
|
stripe_customer_id, vat_number,
|
||||||
|
"ch_vat" if country.lower() == "ch" else "eu_vat")
|
||||||
else:
|
else:
|
||||||
tax_id_obj = create_tax_id(stripe_customer_id, vat_number)
|
tax_id_obj = create_tax_id(
|
||||||
|
stripe_customer_id, vat_number,
|
||||||
|
"ch_vat" if country.lower() == "ch" else "eu_vat")
|
||||||
|
|
||||||
if 'response_object' in tax_id_obj:
|
if 'response_object' in tax_id_obj:
|
||||||
return tax_id_obj
|
return tax_id_obj
|
||||||
|
@ -176,11 +180,12 @@ def validate_vat_number(stripe_customer_id, vat_number):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def create_tax_id(stripe_customer_id, vat_number):
|
def create_tax_id(stripe_customer_id, vat_number, type):
|
||||||
stripe_utils = StripeUtils()
|
stripe_utils = StripeUtils()
|
||||||
tax_id_response = stripe_utils.create_tax_id_for_user(
|
tax_id_response = stripe_utils.create_tax_id_for_user(
|
||||||
stripe_customer_id,
|
stripe_customer_id,
|
||||||
vat_number=vat_number,
|
vat_number=vat_number,
|
||||||
|
type=type
|
||||||
)
|
)
|
||||||
|
|
||||||
tax_id_obj = tax_id_response.get('response_object')
|
tax_id_obj = tax_id_response.get('response_object')
|
||||||
|
|
|
@ -546,7 +546,8 @@ class PaymentOrderView(FormView):
|
||||||
if vat_number:
|
if vat_number:
|
||||||
validate_result = validate_vat_number(
|
validate_result = validate_vat_number(
|
||||||
stripe_customer_id=request.session['customer'],
|
stripe_customer_id=request.session['customer'],
|
||||||
vat_number=address_form.cleaned_data.get('vat_number')
|
vat_number=address_form.cleaned_data.get('vat_number'),
|
||||||
|
country=address_form.cleaned_data.get("country").strip()
|
||||||
)
|
)
|
||||||
|
|
||||||
if 'response_object' in validate_result:
|
if 'response_object' in validate_result:
|
||||||
|
|
|
@ -436,10 +436,10 @@ class StripeUtils(object):
|
||||||
subscription.save()
|
subscription.save()
|
||||||
|
|
||||||
@handleStripeError
|
@handleStripeError
|
||||||
def create_tax_id_for_user(self, stripe_customer_id, vat_number):
|
def create_tax_id_for_user(self, stripe_customer_id, vat_number, type="eu_vat"):
|
||||||
tax_id_obj = stripe.Customer.create_tax_id(
|
tax_id_obj = stripe.Customer.create_tax_id(
|
||||||
stripe_customer_id,
|
stripe_customer_id,
|
||||||
type="eu_vat",
|
type=type,
|
||||||
value=vat_number,
|
value=vat_number,
|
||||||
)
|
)
|
||||||
return tax_id_obj
|
return tax_id_obj
|
||||||
|
|
Loading…
Reference in a new issue