@csrf_exempt_m
    def ipn(self, request):
        OGONE = settings.OGONE

        try:
            parameters_repr = repr(request.POST.copy()).encode('utf-8')
            logger.info('IPN: Processing request data %s' % parameters_repr)

            try:
                orderID = request.POST['orderID']
                currency = request.POST['currency']
                amount = request.POST['amount']
                STATUS = request.POST['STATUS']
                PAYID = request.POST['PAYID']
                BRAND = request.POST['BRAND']
                SHASIGN = request.POST['SHASIGN']
            except __HOLE__:
                logger.error('IPN: Missing data in %s' % parameters_repr)
                return HttpResponseForbidden('Missing data')

            value_strings = [
                u'{0}={1}{2}'.format(key.upper(), value, OGONE['SHA1_OUT'])
                for key, value in request.POST.items()
                if value and not key == 'SHASIGN']
            sha1_out = sha1(
                (u''.join(sorted(value_strings))).encode('utf-8')).hexdigest()

            if sha1_out.lower() != SHASIGN.lower():
                logger.error('IPN: Invalid hash in %s' % parameters_repr)
                return HttpResponseForbidden('Hash did not validate')

            try:
                order, order_id, payment_id = orderID.split('-')
            except ValueError:
                logger.error('IPN: Error getting order for %s' % orderID)
                return HttpResponseForbidden('Malformed order ID')

            # Try fetching the order and order payment objects
            # We create a new order payment object in case the old one
            # cannot be found.
            try:
                order = self.shop.order_model.objects.get(pk=order_id)
            except self.shop.order_model.DoesNotExist:
                logger.error('IPN: Order %s does not exist' % order_id)
                return HttpResponseForbidden(
                    'Order %s does not exist' % order_id)

            try:
                payment = order.payments.get(pk=payment_id)
            except order.payments.model.DoesNotExist:
                payment = order.payments.model(
                    order=order,
                    payment_module='%s' % self.name,
                )

            payment.status = OrderPayment.PROCESSED
            payment.currency = currency
            payment.amount = Decimal(amount)
            payment.data = request.POST.copy()
            payment.transaction_id = PAYID
            payment.payment_method = BRAND
            payment.notes = STATUS_DICT.get(STATUS)

            if STATUS in ('5', '9'):
                payment.authorized = timezone.now()
                payment.status = OrderPayment.AUTHORIZED

            payment.save()
            order = order.reload()

            logger.info(
                'IPN: Successfully processed IPN request for %s' % order)

            if payment.authorized and plata.settings.PLATA_STOCK_TRACKING:
                StockTransaction = plata.stock_model()
                self.create_transactions(
                    order, _('sale'),
                    type=StockTransaction.SALE, negative=True, payment=payment)

            if not order.balance_remaining:
                self.order_paid(order, payment=payment, request=request)

            return HttpResponse('OK')
        except Exception as e:
            logger.error('IPN: Processing failure %s' % e)
            raise
dataset/ETHPy150Open matthiask/plata/plata/payment/modules/ogone.py/PaymentProcessor.ipn