def get_object(self, queryset=None): order = super(OrderDetail, self).get_object(queryset=queryset) # Do a status check with DocData when we don't know the status of in_progress orders. if order and order.id and order.status == OrderStatuses.current and order.recurring == False: latest_payment = order.latest_payment if latest_payment.payment_order_id and latest_payment.status == PaymentStatuses.in_progress: payments.update_payment_status(order.latest_payment) return order
def get_object(self, queryset=None): # Catch NotAuthenticated exceptions so anonymous users get the proper response. try: order = super(OrderDetail, self).get_object(queryset=queryset) except exceptions.NotAuthenticated: raise exceptions.PermissionDenied() # Do a status check with DocData when we don't know the status of in_progress orders. if order and order.id and order.status == OrderStatuses.current and order.recurring == False: latest_payment = order.latest_payment if latest_payment.payment_order_id and latest_payment.status == PaymentStatuses.in_progress: payments.update_payment_status(order.latest_payment) return order
def get_object(self, queryset=None): alias = self.kwargs.get('alias', None) if alias == 'current': order = self.get_or_create_current_order() else: order = super(OrderDetail, self).get_object() self.check_object_permissions(self.request, order) if not order: raise Http404(_(u"No %(verbose_name)s found matching the query") % {'verbose_name': queryset.model._meta.verbose_name}) if order.status == OrderStatuses.in_progress: payments.update_payment_status(order.payment) return order
def get(self, request, *args, **kwargs): if 'order' in request.QUERY_PARAMS: order = request.QUERY_PARAMS['order'] # TODO: Match on this regex when not testing: '^COWRY-([0-9]+)$'. Can only do this when test config setting. if re.match('^COWRY-', order): # Try to find the payment for this mor. try: payment = DocDataPaymentOrder.objects.get(merchant_order_reference=order) except DocDataPaymentOrder.DoesNotExist: status_logger.error('Could not find order {0} to update payment status.'.format(order)) return response.Response(status=status.HTTP_403_FORBIDDEN) # Update the status for the payment. status_logger.info('{0}: Processing status changed notification for order {1}.'.format(payment.payment_order_id, order)) payments.update_payment_status(payment, status_changed_notification=True) # Return 200 as required by DocData when the status changed notification was consumed. return response.Response(status=status.HTTP_200_OK) else: status_logger.error('Could not match order {0} to update payment status.'.format(order)) return response.Response(status=status.HTTP_403_FORBIDDEN)
def get(self, request, *args, **kwargs): if 'order' in request.QUERY_PARAMS: order = request.QUERY_PARAMS['order'] if re.match('^[\w]+-[0-9]+$', order): # Try to find the payment for this order. try: payment = DocDataPaymentOrder.objects.get(merchant_order_reference=order) except DocDataPaymentOrder.DoesNotExist: logger.error('Could not find order {0} to update payment status.'.format(order)) return response.Response(status=status.HTTP_403_FORBIDDEN) # Update the status for the payment. status_log = DocDataPaymentLogEntry(docdata_payment_order=payment, level=PaymentLogLevels.info) status_log.message = 'Received status changed notification for merchant_order_reference {0}.'.format(order) status_log.save() payments.update_payment_status(payment, status_changed_notification=True) # Return 200 as required by DocData when the status changed notification was consumed. return response.Response(status=status.HTTP_200_OK) else: logger.error('Could not match order {0} to update payment status.'.format(order)) return response.Response(status=status.HTTP_403_FORBIDDEN)
def get(self, request, *args, **kwargs): if 'mor' in request.QUERY_PARAMS: mor = request.QUERY_PARAMS['mor'] # TODO: Match on this regex when not testing: '^COWRY-([0-9]+)$'. Can only do this when test config setting. if re.match('^COWRY-', mor): # Try to find the payment for this mor. try: payment = DocDataPaymentOrder.objects.get(merchant_order_reference=mor) except DocDataPaymentOrder.DoesNotExist: status_logger.error('Cannot find payment for merchant_order_reference: {0}'.format(mor)) response.Response(status=status.HTTP_403_FORBIDDEN) # TODO: Can update status as background job. # Update the status for the payment. status_logger.info('Processing status changed notification for: {0}'.format(mor)) payments.update_payment_status(payment, status_changed_notification=True) # Return 200 as required by DocData when the status changed notification was consumed. return response.Response(status=status.HTTP_200_OK) else: status_logger.error('merchant_order_reference not correctly matched: {0}'.format(mor)) return response.Response(status=status.HTTP_403_FORBIDDEN)
def get_object(self, queryset=None): alias = self.kwargs.get('alias', None) if alias == 'current': order = self.get_or_create_current_order() else: order = super(OrderCurrentDetail, self).get_object() self.check_object_permissions(self.request, order) if not order: raise Http404(_(u"No %(verbose_name)s found matching the query") % {'verbose_name': queryset.model._meta.verbose_name}) # Don't allow anonymous users to set recurring orders. This check is here and not in the Serializer # because we need to access the request to see if a user is authenticated or not. if not self.request.user.is_authenticated() and 'recurring' in self.request.DATA and self.request.DATA['recurring']: raise exceptions.PermissionDenied(_("Anonymous users are not permitted to create recurring orders.")) # Only try to update the status if we're not using the 'current' alias and the statuses match our expectations. if alias != 'current': if order.status == OrderStatuses.current and order.latest_payment.payment_order_id and order.latest_payment.status == PaymentStatuses.in_progress: payments.update_payment_status(order.latest_payment) return order