From 32d9f06c18dbea2bf789b8e4f2615f4613c9a032 Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 26 Dec 2019 18:22:08 +0530 Subject: [PATCH] Add logger messages --- datacenterlight/utils.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/datacenterlight/utils.py b/datacenterlight/utils.py index 4ebdc4ab..7181e38f 100644 --- a/datacenterlight/utils.py +++ b/datacenterlight/utils.py @@ -156,18 +156,27 @@ def validate_vat_number(stripe_customer_id, billing_address_id, logger.debug("Multiple BillingAddress exist for %s" % billing_address_id) billing_address = BillingAddress.objects.filter(id=billing_address_id).order_by('-id').first() if billing_address is not None: + logger.debug("BillingAddress found: %s %s type=%s" % ( + billing_address_id, str(billing_address), type(billing_address))) if billing_address.vat_number_validated_on: + logger.debug("billing_address verified on %s" % + billing_address.vat_number_validated_on) return { "validated_on": billing_address.vat_number_validated_on, "status": "verified" } else: + logger.debug("billing_address not yet verified, " + "Checking if we already have a tax id") if billing_address.stripe_tax_id: + logger.debug("We have a tax id %s" % billing_address.stripe_tax_id) tax_id_obj = stripe.Customer.retrieve_tax_id( stripe_customer_id, billing_address.stripe_tax_id, ) if tax_id_obj.verification.status == "verified": + logger.debug("Latest status on Stripe=%s. Updating" % + tax_id_obj.verification.status) # update billing address billing_address.vat_number_validated_on = datetime.datetime.now() billing_address.save() @@ -176,17 +185,24 @@ def validate_vat_number(stripe_customer_id, billing_address_id, "validated_on": billing_address.vat_number_validated_on } else: + logger.debug( + "Latest status on Stripe=%s" % str(tax_id_obj) + ) return { - "status": tax_id_obj.verification.status, + "status": tax_id_obj.verification.status if tax_id_obj + else "unknown", "validated_on": "" } else: + logger.debug("Creating a tax id") tax_id_obj = create_tax_id( stripe_customer_id, billing_address_id, "ch_vat" if billing_address.country.lower() == "ch" else "eu_vat", is_user_ba=is_user_ba ) + logger.debug("Created tax_id %s" % tax_id_obj['response_object'].id) else: + logger.debug("invalid billing address") return { "status": "invalid billing address", "validated_on": ""