Add debugging messages

This commit is contained in:
PCoder 2020-12-23 14:12:30 +05:30
parent 259c509113
commit 70c8ed6825
2 changed files with 78 additions and 73 deletions

View file

@ -1144,12 +1144,14 @@ def do_create_vm(request, user, stripe_api_cus_id, card_details_response,
) )
# Save billing address # Save billing address
logger.debug('billing_address_data is {}'.format(billing_address_data))
billing_address_data.update({ billing_address_data.update({
'user': custom_user.id 'user': custom_user.id
}) })
logger.debug('billing_address_data is {}'.format(billing_address_data))
if 'generic_payment_type' in request: generic_payment_type = request.get('generic_payment_type', None)
if generic_payment_type:
logger.debug("generic_payment_type case")
stripe_cus = StripeCustomer.objects.filter( stripe_cus = StripeCustomer.objects.filter(
stripe_id=stripe_api_cus_id stripe_id=stripe_api_cus_id
).first() ).first()
@ -1185,12 +1187,15 @@ def do_create_vm(request, user, stripe_api_cus_id, card_details_response,
billing_address_user_form.is_valid() billing_address_user_form.is_valid()
billing_address_user_form.save() billing_address_user_form.save()
if request['generic_payment_details']['recurring']: recurring = request['generic_payment_details'].get('recurring')
if recurring:
logger.debug("recurring case")
# Associate the given stripe subscription with the order # Associate the given stripe subscription with the order
order.set_subscription_id( order.set_subscription_id(
stripe_subscription_obj.id, card_details_dict stripe_subscription_obj.id, card_details_dict
) )
else: else:
logger.debug("one time charge case")
# Associate the given stripe charge id with the order # Associate the given stripe charge id with the order
order.set_stripe_charge(stripe_onetime_charge) order.set_stripe_charge(stripe_onetime_charge)

View file

@ -136,84 +136,84 @@ def handle_webhook(request):
if (invoice_obj.paid and if (invoice_obj.paid and
invoice_obj.billing_reason == "subscription_update"): invoice_obj.billing_reason == "subscription_update"):
logger.debug("Start provisioning") logger.debug("Start provisioning")
# try:
stripe_subscription_obj = stripe.Subscription.retrieve(
invoice_obj.subscription)
try: try:
incomplete_sub = IncompleteSubscriptions.objects.get( stripe_subscription_obj = stripe.Subscription.retrieve(
subscription_id=invoice_obj.subscription) invoice_obj.subscription)
request = "" try:
soc = "" incomplete_sub = IncompleteSubscriptions.objects.get(
card_details_response = "" subscription_id=invoice_obj.subscription)
gp_details = "" request = ""
template = "" soc = ""
specs = "" card_details_response = ""
billing_address_data = "" gp_details = ""
if incomplete_sub.request: template = ""
request = json.loads(incomplete_sub.request) specs = ""
if incomplete_sub.specs: billing_address_data = ""
specs = json.loads(incomplete_sub.specs) if incomplete_sub.request:
if incomplete_sub.stripe_onetime_charge: request = json.loads(incomplete_sub.request)
soc = json.loads(incomplete_sub.stripe_onetime_charge) if incomplete_sub.specs:
if incomplete_sub.gp_details: specs = json.loads(incomplete_sub.specs)
gp_details = json.loads(incomplete_sub.gp_details) if incomplete_sub.stripe_onetime_charge:
if incomplete_sub.card_details_response: soc = json.loads(incomplete_sub.stripe_onetime_charge)
card_details_response = json.loads( if incomplete_sub.gp_details:
incomplete_sub.card_details_response) gp_details = json.loads(incomplete_sub.gp_details)
if incomplete_sub.template: if incomplete_sub.card_details_response:
template = json.loads( card_details_response = json.loads(
incomplete_sub.template) incomplete_sub.card_details_response)
if incomplete_sub.billing_address_data: if incomplete_sub.template:
billing_address_data = json.loads( template = json.loads(
incomplete_sub.billing_address_data) incomplete_sub.template)
logger.debug("*******") if incomplete_sub.billing_address_data:
logger.debug(str(incomplete_sub)) billing_address_data = json.loads(
logger.debug("*******") incomplete_sub.billing_address_data)
logger.debug("1*******") logger.debug("*******")
logger.debug(request) logger.debug(str(incomplete_sub))
logger.debug("2*******") logger.debug("*******")
logger.debug(card_details_response) logger.debug("1*******")
logger.debug("3*******") logger.debug(request)
logger.debug(soc) logger.debug("2*******")
logger.debug("4*******") logger.debug(card_details_response)
logger.debug(gp_details) logger.debug("3*******")
logger.debug("5*******") logger.debug(soc)
logger.debug(template) logger.debug("4*******")
logger.debug("6*******") logger.debug(gp_details)
do_create_vm( logger.debug("5*******")
request=request, logger.debug(template)
user={'name': incomplete_sub.name, logger.debug("6*******")
'email': incomplete_sub.email}, do_create_vm(
stripe_api_cus_id=incomplete_sub.stripe_api_cus_id, request=request,
card_details_response=card_details_response, user={'name': incomplete_sub.name,
stripe_subscription_obj=stripe_subscription_obj, 'email': incomplete_sub.email},
stripe_onetime_charge=soc, stripe_api_cus_id=incomplete_sub.stripe_api_cus_id,
gp_details=gp_details, card_details_response=card_details_response,
specs=specs, stripe_subscription_obj=stripe_subscription_obj,
vm_template_id=incomplete_sub.vm_template_id, stripe_onetime_charge=soc,
template=template, gp_details=gp_details,
billing_address_data=billing_address_data specs=specs,
) vm_template_id=incomplete_sub.vm_template_id,
except (IncompleteSubscriptions.DoesNotExist, template=template,
IncompleteSubscriptions.MultipleObjectsReturned) as ex: billing_address_data=billing_address_data
)
except (IncompleteSubscriptions.DoesNotExist,
IncompleteSubscriptions.MultipleObjectsReturned) as ex:
logger.error(str(ex))
# TODO Inform admin
email_data = {
'subject': "IncompleteSubscriptions error",
'from_email': settings.DCL_SUPPORT_FROM_ADDRESS,
'to': settings.DCL_ERROR_EMAILS_TO_LIST,
'body': "Response = %s" % str(ex),
}
send_plain_email_task.delay(email_data)
except Exception as ex:
logger.error(str(ex)) logger.error(str(ex))
# TODO Inform admin
email_data = { email_data = {
'subject': "IncompleteSubscriptions error", 'subject': "invoice.paid Webhook error",
'from_email': settings.DCL_SUPPORT_FROM_ADDRESS, 'from_email': settings.DCL_SUPPORT_FROM_ADDRESS,
'to': settings.DCL_ERROR_EMAILS_TO_LIST, 'to': settings.DCL_ERROR_EMAILS_TO_LIST,
'body': "Response = %s" % str(ex), 'body': "Response = %s" % str(ex),
} }
send_plain_email_task.delay(email_data) send_plain_email_task.delay(email_data)
# except Exception as ex:
# logger.error(str(ex))
# email_data = {
# 'subject': "invoice.paid Webhook error",
# 'from_email': settings.DCL_SUPPORT_FROM_ADDRESS,
# 'to': settings.DCL_ERROR_EMAILS_TO_LIST,
# 'body': "Response = %s" % str(ex),
# }
# send_plain_email_task.delay(email_data)
else: else:
logger.error("Unhandled event : " + event.type) logger.error("Unhandled event : " + event.type)
return HttpResponse(status=200) return HttpResponse(status=200)