Refactor code and log messages for possible errors

This commit is contained in:
PCoder 2017-12-24 14:38:32 +01:00
parent 29c24574aa
commit eb067f5708

View file

@ -535,6 +535,7 @@ class MembershipDeactivateView(LoginRequiredMixin, UpdateView):
membership_order = MembershipOrder.objects.filter( membership_order = MembershipOrder.objects.filter(
customer__user=self.request.user customer__user=self.request.user
).last() ).last()
if membership_order:
if membership_order.subscription_id: if membership_order.subscription_id:
result = stripe_utils.unsubscribe_customer( result = stripe_utils.unsubscribe_customer(
subscription_id=membership_order.subscription_id subscription_id=membership_order.subscription_id
@ -545,11 +546,24 @@ class MembershipDeactivateView(LoginRequiredMixin, UpdateView):
stripe_subscription_obj.status != 'canceled'): stripe_subscription_obj.status != 'canceled'):
error_msg = result.get('error') error_msg = result.get('error')
logger.error( logger.error(
"Could not cancel Digital Glarus subscription. Reason: " "Could not cancel Digital Glarus subscription. "
"{reason}".format( "Reason: {reason}".format(
reason=error_msg reason=error_msg
) )
) )
else:
logger.error(
"User {user} may have Stripe subscriptions created "
"manually. Please check.".format(
user=self.request.user.name
)
)
else:
logger.error(
"MembershipOrder for {user} not found".format(
user=self.request.user.name
)
)
return HttpResponseRedirect(self.success_url) return HttpResponseRedirect(self.success_url)