Refactor code and log messages for possible errors
This commit is contained in:
		
					parent
					
						
							
								29c24574aa
							
						
					
				
			
			
				commit
				
					
						eb067f5708
					
				
			
		
					 1 changed files with 26 additions and 12 deletions
				
			
		| 
						 | 
					@ -535,21 +535,35 @@ 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.subscription_id:
 | 
					        if membership_order:
 | 
				
			||||||
            result = stripe_utils.unsubscribe_customer(
 | 
					            if membership_order.subscription_id:
 | 
				
			||||||
                subscription_id=membership_order.subscription_id
 | 
					                result = stripe_utils.unsubscribe_customer(
 | 
				
			||||||
            )
 | 
					                    subscription_id=membership_order.subscription_id
 | 
				
			||||||
            stripe_subscription_obj = result.get('response_object')
 | 
					                )
 | 
				
			||||||
            # Check if the subscription was canceled
 | 
					                stripe_subscription_obj = result.get('response_object')
 | 
				
			||||||
            if (stripe_subscription_obj is None or
 | 
					                # Check if the subscription was canceled
 | 
				
			||||||
                    stripe_subscription_obj.status != 'canceled'):
 | 
					                if (stripe_subscription_obj is None or
 | 
				
			||||||
                error_msg = result.get('error')
 | 
					                        stripe_subscription_obj.status != 'canceled'):
 | 
				
			||||||
 | 
					                    error_msg = result.get('error')
 | 
				
			||||||
 | 
					                    logger.error(
 | 
				
			||||||
 | 
					                        "Could not cancel Digital Glarus subscription. "
 | 
				
			||||||
 | 
					                        "Reason: {reason}".format(
 | 
				
			||||||
 | 
					                            reason=error_msg
 | 
				
			||||||
 | 
					                        )
 | 
				
			||||||
 | 
					                    )
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
                logger.error(
 | 
					                logger.error(
 | 
				
			||||||
                    "Could not cancel Digital Glarus subscription. Reason: "
 | 
					                    "User {user} may have Stripe subscriptions created "
 | 
				
			||||||
                    "{reason}".format(
 | 
					                    "manually. Please check.".format(
 | 
				
			||||||
                        reason=error_msg
 | 
					                        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)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue