def get(self, request, *args, **kwargs): # Directly query the latest state from Docdata try: order_key = self.get_order_slug() except KeyError as e: return HttpResponseBadRequest(e.message, content_type='text/plain; charset=utf-8') callback = request.GET.get('callback') or '' logger.info("Returned from Docdata for {0}, callback: {1}".format(order_key, callback)) # Need to make sure the latest status is present, # won't wait for Docdata to call our update API. with transaction_atomic(): self.order = self.get_order(order_key) # this is the docdata id. self.update_order(self.order) # Allow other code to perform actions, e.g. send a confirmation email. responses = return_view_called.send(sender=self.__class__, request=request, order=self.order, callback=callback) # Allow a signal receiver to override the returned URL and return a response. for receiver, response in responses: if response and isinstance(response, HttpResponse): return response # Redirect to thank you page, or the cancelled page, # depending on the callback parameter with translation.override(self.order.language): # Allow i18n_patterns() to work properly url = str(self.get_redirect_url(callback)) # force evaluation of reverse_lazy() return HttpResponseRedirect(url)
def get(self, request, *args, **kwargs): try: order_key = self.get_order_slug() except KeyError as e: return HttpResponseBadRequest(e.message, content_type='text/plain; charset=utf-8') logger.info("Got Docdata status changed notification for {0}".format(order_key)) with transaction_atomic(): try: self.order = self.get_order(order_key) # Inconsistent, this call uses the merchant_order_id except Http404 as e: return HttpResponseNotFound(str(e), content_type='text/plain; charset=utf-8') try: self.update_order(self.order) except DocdataStatusError as e: logger.exception("The order status could not be retrieved from Docdata by the notification-url") return HttpResponseServerError( "Failed to fetch status from Docdata API.\n" "\n\n" "Docdata API response:\n" "---------------------\n" "\n" "code: {0}\n" "message: {1}".format(e.code, e.message), content_type='text/plain; charset=utf-8' ) responses = status_changed_view_called.send(sender=self.__class__, request=request, order=self.order) # Return 200 as required by DocData when the status changed notification was consumed. return HttpResponse(u"ok, order {0} updated\n".format(order_key), content_type='text/plain; charset=utf-8')
def get(self, request, *args, **kwargs): try: order_key = self.get_order_slug() except KeyError as e: return HttpResponseBadRequest( e.message, content_type='text/plain; charset=utf-8') logger.info("Got Docdata status changed notification for {0}".format( order_key)) with transaction_atomic(): try: self.order = self.get_order( order_key ) # Inconsistent, this call uses the merchant_order_id except Http404 as e: return HttpResponseNotFound( str(e), content_type='text/plain; charset=utf-8') try: self.update_order(self.order) except DocdataStatusError as e: logger.exception( "The order status could not be retrieved from Docdata by the notification-url" ) return HttpResponseServerError( "Failed to fetch status from Docdata API.\n" "\n\n" "Docdata API response:\n" "---------------------\n" "\n" "code: {0}\n" "message: {1}".format(e.code, e.message), content_type='text/plain; charset=utf-8') responses = status_changed_view_called.send(sender=self.__class__, request=request, order=self.order) # Return 200 as required by DocData when the status changed notification was consumed. return HttpResponse(u"ok, order {0} updated\n".format(order_key), content_type='text/plain; charset=utf-8')
def get(self, request, *args, **kwargs): # Directly query the latest state from Docdata try: order_key = self.get_order_slug() except KeyError as e: return HttpResponseBadRequest( e.message, content_type='text/plain; charset=utf-8') callback = request.GET.get('callback') or '' logger.info("Returned from Docdata for {0}, callback: {1}".format( order_key, callback)) # Need to make sure the latest status is present, # won't wait for Docdata to call our update API. with transaction_atomic(): self.order = self.get_order(order_key) # this is the docdata id. self.update_order(self.order) # Allow other code to perform actions, e.g. send a confirmation email. responses = return_view_called.send(sender=self.__class__, request=request, order=self.order, callback=callback) # Allow a signal receiver to override the returned URL and return a response. for receiver, response in responses: if response and isinstance(response, HttpResponse): return response # Redirect to thank you page, or the cancelled page, # depending on the callback parameter with translation.override( self.order.language): # Allow i18n_patterns() to work properly url = str(self.get_redirect_url( callback)) # force evaluation of reverse_lazy() return HttpResponseRedirect(url)