def create(self, request): task, order, contract, error_response = validate_product_job( self, request) if error_response is not None: return error_response # If the model is pay-per-use charge for pending payment redirect_url = None if task['priceType'].lower() == 'usage': # The update of the product status need to be postponed if there is a pending payment redirect_url, error_response = process_product_payment( self, request, task, order, contract) if error_response is not None: return error_response response = build_response(request, 200, 'OK') # Include redirection header if needed if redirect_url is not None: response['X-Redirect-URL'] = redirect_url else: # Suspend the product as no pending payment on_product_suspended(order, contract) contract.suspended = True order.save() client = InventoryClient() client.suspend_product(contract.product_id) return response
def _check_renovation_date(self, renovation_date, order, contract): now = datetime.now() timed = renovation_date - now if timed.days < 7: handler = NotificationsHandler() if timed.days < 0: # Notify that the subscription has finished handler.send_payment_required_notification(order, contract) # Set the product as suspended client = InventoryClient() client.suspend_product(contract.product_id) else: # There is less than a week remaining handler.send_near_expiration_notification(order, contract, timed.days)
def _check_renovation_date(self, renovation_date, order, contract): now = datetime.utcnow() timed = renovation_date - now if timed.days < 7: handler = NotificationsHandler() if timed.days < 0: # Suspend the access to the service on_product_suspended(order, contract) # Notify that the subscription has finished handler.send_payment_required_notification(order, contract) # Set the product as suspended client = InventoryClient() client.suspend_product(contract.product_id) else: # There is less than a week remaining handler.send_near_expiration_notification( order, contract, timed.days)