def test_robokassa_signal(self): """ Test order_payments signal handler """ # Create notification notification_1 = SuccessNotification.objects.create( InvId='1', OutSum='100') # Create order order_1 = Order.objects.create(total=Decimal("22.37")) result_received.send(sender=notification_1, InvId=notification_1.InvId, OutSum=notification_1.OutSum) # No transaction for order becouse OutSum != total order self.assertFalse(Order.objects.get(id=order_1.id).transaction_id) # Transaction was created self.assertEqual(Transactions.objects.all().count(), 1) transaction = Transactions.objects.all()[0] # test Robokassa transaction data self.assertEqual(transaction.backend, 'Robokassa') self.assertEqual(transaction.status, 'paid') self.assertEqual(transaction.amount_paid, Decimal('100')) self.assertEqual(int(transaction.external_id), notification_1.id) # Test transaction with same OutSum. notification_2 = SuccessNotification.objects.create( InvId='1', OutSum='22.37') result_received.send(sender=notification_2, InvId=notification_2.InvId, OutSum=notification_2.OutSum) # Now order got Transaction self.assertTrue(Order.objects.get(id=order_1.id).transaction_id)
def receive_result(request, **credentials): """ Обработчик для ResultURL """ data = request.POST if USE_POST else request.GET form = ResultURLForm(data, **credentials) if form.is_valid(): inv_id = form.cleaned_data['InvId'] out_sum = form.cleaned_data['OutSum'] # сохраняем данные об успешном уведомлении в базе, чтобы # можно было выполнить дополнительную проверку на странице успешного # заказа notification = SuccessNotification.objects.create( InvId=inv_id, OutSum=out_sum ) # дополнительные действия с заказом (например, смену его статуса) можно # осуществить в обработчике сигнала robokassa.signals.result_received result_received.send( sender=notification, InvId=inv_id, OutSum=out_sum, extra=form.extra_params()) return HttpResponse('OK%s' % inv_id) return HttpResponse('error: bad signature')
def dispatch(self, request, *args, **kwargs): log.debug("=" * 80) log.debug("In result view") log.debug("=" * 80) data = self.get_data(request) log.debug("data is %s", data) if data is None: return self.http_method_not_allowed(request, *args, **kwargs) self.process_data(data) log.debug("cleaned data is %s", self.robokassa_cleaned_data) if self.robokassa_cleaned_data is None: return HttpResponse('error: bad signature') log.debug("basket num is %s", self.basket_num) self.basket = get_object_or_404(Basket, id=self.basket_num, status=Basket.FROZEN) # checking complete: create notification and send confirmation SuccessNotification.objects.create(InvId=self.basket_num, OutSum=self.robokassa_amount) # keeping this for legacy result_received.send(sender=self.basket, request=request, InvId=self.basket_num, OutSum=self.robokassa_amount, order_num=self.order_num, session_key=self.session_key, extra=self.robokassa_extra_params) return HttpResponse('OK%s' % self.basket_num)
def dispatch(self, request, *args, **kwargs): log.debug("="*80) log.debug("In result view") log.debug("="*80) data = self.get_data(request) log.debug("data is %s", data) if data is None: return self.http_method_not_allowed(request, *args, **kwargs) self.process_data(data) log.debug("cleaned data is %s", self.robokassa_cleaned_data) if self.robokassa_cleaned_data is None: return HttpResponse('error: bad signature') log.debug("basket num is %s", self.basket_num) self.basket = get_object_or_404(Basket, id=self.basket_num, status=Basket.FROZEN) # checking complete: create notification and send confirmation SuccessNotification.objects.create( InvId = self.basket_num, OutSum = self.robokassa_amount) # keeping this for legacy result_received.send(sender = self.basket, request=request, InvId = self.basket_num, OutSum = self.robokassa_amount, order_num = self.order_num, session_key = self.session_key, extra = self.robokassa_extra_params) return HttpResponse('OK%s' % self.basket_num)
def test_handler_recrive_signal(self): result_received.send(sender = None, InvId = self.WP_deal.pk, OutSum = self.WP_deal.cost) deals = Dealings.objects.filter(buyer = self.user,state="PD") self.assertQuerysetIdEqual(deals,[self.PD_deal.pk,self.WP_deal.pk]) # wrong Sum result_received.send(sender = None, InvId = self.BT_deal.pk, OutSum = "2.50") deals = Dealings.objects.filter(buyer = self.user,state="PD") self.assertQuerysetIdEqual(deals,[self.PD_deal.pk,self.WP_deal.pk])
def receive_result(request): """ обработчик для ResultURL. """ data = request.POST if USE_POST else request.GET form = ResultURLForm(data) if form.is_valid(): id, sum = form.cleaned_data["InvId"], form.cleaned_data["OutSum"] # сохраняем данные об успешном уведомлении в базе, чтобы # можно было выполнить дополнительную проверку на странице успешного # заказа notification = SuccessNotification.objects.create(InvId=id, OutSum=sum) # дополнительные действия с заказом (например, смену его статуса) можно # осуществить в обработчике сигнала robokassa.signals.result_received result_received.send(sender=notification, InvId=id, OutSum=sum, extra=form.extra_params()) return HttpResponse("OK%s" % id) return HttpResponse("error: bad signature")
def payment_result(request): data = request.POST if USE_POST else request.GET form = ResultURLForm(data) print data.get('SignatureValue') if form.is_valid(): order_id, order_sum = form.cleaned_data['InvId'], form.cleaned_data['OutSum'] # сохраняем данные об успешном уведомлении в базе, чтобы # можно было выполнить дополнительную проверку на странице успешного # заказа notification = SuccessNotification.objects.create(InvId=order_id, OutSum=order_sum) # дополнительные действия с заказом (например, смену его статуса) можно # осуществить в обработчике сигнала robokassa.signals.result_received result_received.send(sender=notification, InvId=order_id, OutSum=order_sum, extra=form.extra_params()) return HttpResponse('OK%s' % order_id) return HttpResponse('error: bad signature')
def receive_result(request): """ обработчик для ResultURL. """ data = request.POST if USE_POST else request.GET logger.debug("receive result from robokassa: {}".format(data)) form = ResultURLForm(data) if form.is_valid(): logger.debug("result form from robokassa is valid") id, sum = form.cleaned_data['InvId'], form.cleaned_data['OutSum'] # сохраняем данные об успешном уведомлении в базе, чтобы # можно было выполнить дополнительную проверку на странице успешного # заказа notification = SuccessNotification.objects.create(InvId=id, OutSum=sum) # дополнительные действия с заказом (например, смену его статуса) можно # осуществить в обработчике сигнала robokassa.signals.result_received result_received.send(sender=notification, InvId=id, OutSum=sum, extra=form.extra_params()) logger.debug("return ok to robokassa") return HttpResponse('OK%s' % id) logger.debug("return bad to robokassa. errors: {}".format(form.errors)) return HttpResponse('error: bad signature')