def liqpay_callback(request): form = CallbackForm(request.POST or None) if not form.is_valid(): logger.warning('Invalid callback form, POST: {}'.format(request.POST)) return HttpResponse(status=400) data = form.cleaned_data['data'] signature = form.cleaned_data['signature'] default_conf = settings.LIQPAY_CONF[settings.DEFAULT_LIQPAY] additional_conf = settings.LIQPAY_CONF[settings.ADDITIONAL_LIQPAY] liqpay = LiqPay(default_conf['LIQPAY_PUBLIC_KEY'], default_conf['LIQPAY_PRIVATE_KEY']) our_sign = liqpay.str_to_sign(default_conf['LIQPAY_PRIVATE_KEY'] + data + default_conf['LIQPAY_PRIVATE_KEY']) if signature != our_sign: liqpay = LiqPay(additional_conf['LIQPAY_PUBLIC_KEY'], additional_conf['LIQPAY_PRIVATE_KEY']) our_sign = liqpay.str_to_sign(additional_conf['LIQPAY_PRIVATE_KEY'] + data + additional_conf['LIQPAY_PRIVATE_KEY']) if signature != our_sign: logger.warning('Invalid signature: our {}!={}'.format( our_sign, signature)) return HttpResponse(status=400) data = liqpay.decode_data_from_str(data) status = data.get('status') if status not in ('success', 'sandbox'): logger.warning('Status is not success: {} {} {} {}'.format(status, data.get('err_code'), data.get('err_description'), data)) return HttpResponse(status=400) try: order = LiqPayOrder.objects.get(order_id=data['order_id']) except LiqPayOrder.DoesNotExist: logger.warning('Wrong order_id: {}'.format(data['order_id'])) return HttpResponse(status=400) logger.info('Payment status={}: id={} amount={} {}'.format( status, order.order_id, data['amount'], data['currency'] )) result_received.send( sender=order, order_id=order.order_id, amount=data['amount'], currency=data['currency'], ) return HttpResponse('OK', status=200)
def post(self, request): liqpay = LiqPay(settings.LIQPAY_PUBLIC_KEY, settings.LIQPAY_PRIVATE_KEY) data = request.POST.get('data') signature = request.POST.get('signature') if not data or not signature: return Response({'POST data is not provided'}, status=status.HTTP_412_PRECONDITION_FAILED) sign = liqpay.str_to_sign(settings.LIQPAY_PRIVATE_KEY + data + settings.LIQPAY_PRIVATE_KEY) if sign == signature: response = liqpay.decode_data_from_str(data) end_date = datetime.fromtimestamp(int(response['end_date']) / 1e3) Payment.objects.create(payment_type=Payment.LiqPay, date=end_date, value=response['amount'], description=response['description'], liqpay_responce=response) return Response({'check': 'callback is valid'}, status=status.HTTP_200_OK) else: News.objects.create(title="Failed payment", text=data + ' ' + signature) return Response({'check': 'callback is not valid'}, status=status.HTTP_412_PRECONDITION_FAILED)
def post(self, request, *args, **kwargs): liqpay = LiqPay(settings.sandbox_i26660223217, settings.sandbox_u3BM9ppkXfPn0Phd5ZNhpkzieRiVWHmq12iJUJYb) data = request.POST.get('data') signature = request.POST.get('signature') sign = liqpay.str_to_sign(settings.sandbox_i26660223217 + data + settings.sandbox_u3BM9ppkXfPn0Phd5ZNhpkzieRiVWHmq12iJUJYb) if sign == signature: print('callback is valid') response = liqpay.decode_data_from_str(data) print('callback data', response) return HttpResponse()
def post(self, request, *args, **kwargs): liqpay = LiqPay(settings.LIQPAY_PUBLIC_KEY, settings.LIQPAY_PRIVATE_KEY) data = request.POST.get('data') signature = request.POST.get('signature') sign = liqpay.str_to_sign(settings.LIQPAY_PRIVATE_KEY + data + settings.LIQPAY_PRIVATE_KEY) if sign == signature: print('callback is valid') response = liqpay.decode_data_from_str(data) print('callback data', response) return HttpResponse()
def post(self, request, *args, **kwargs): liqpay = LiqPay(LIQPAY_PUBLIC_KEY, LIQPAY_PRIVATE_KEY) data = request.POST.get('data') signature = request.POST.get('signature') sign = liqpay.str_to_sign(LIQPAY_PRIVATE_KEY + data + LIQPAY_PRIVATE_KEY) if sign == signature: print('callback is valid') response = liqpay.decode_data_from_str(data) if len(response) != 0: oreder_id = response['order_id'] status = response['status'] rep = Replanishment.objects.get(id=oreder_id) rep.status = status rep.save() if status == 'sandbox': profile = Profile.objects.get(user_id=rep.user_replanishment_id) profile.account = profile.account + decimal.Decimal(rep.ammount) profile.save() print('callback data', response) return HttpResponse()
def post(self, request, *args, **kwargs): liqpay = LiqPay(settings.LIQPAY_PUBLIC_KEY, settings.LIQPAY_PRIVATE_KEY) data = request.POST.get('data') signature = request.POST.get('signature') sign = liqpay.str_to_sign(settings.LIQPAY_PRIVATE_KEY + data + settings.LIQPAY_PRIVATE_KEY) # if sign == signature: response =liqpay.decode_data_from_str(data) try: phone = response['sender_phone'] except: phone = '0' if phone != '0' and signature == sign: orders = Order.objects.get(id=response['order_id']) if response['status'] == 'success': orders.status_pay = 'pay' orders.save() x ='сумма платежа'+str(response['amount'])+ '... response order id==='+response['order_id']+'--status----'+response['status'] +'--phone'+phone +'Остальное -------'+str(response) send_mail('Платеж удачен!',x, "Yasoob",['*****@*****.**'], fail_silently=False) if response['status'] == 'failed': orders.status_pay='not_pay' orders.save() # x = '... response order id==='+response['order_id']+'--status----'+response['status'] +'--phone'+phone +'Остальное -------'+str(response) send_mail('Платеж отклонен!', "Yasoob",['*****@*****.**'], fail_silently=False) if response['status'] == 'reversed': orders.status_pay='reversed' orders.save() # x = '... response order id==='+response['order_id']+'--status----'+response['status'] +'--phone'+phone +'Остальное -------'+str(response) send_mail('Платеж возвращн', "Yasoob",['*****@*****.**'], fail_silently=False) if response['status'] == 'error': orders.status_pay = 'miss' orders.save() #написать если ошибка при оплате # x = ' ошибка при оплате '+' .order id==='+response['order_id']+'--status----'+response['status'] +'--phone'+phone +'Остальное -------'+str(response) send_mail('Платеж ошибка!', "Yasoob",['*****@*****.**'], fail_silently=False) result_url = 'https://mysite123456.herokuapp.com/' return HttpResponse()
def post(self, request, *args, **kwargs): liqpay = LiqPay(settings.LIQPAY_PUBLIC_KEY, settings.LIQPAY_PRIVATE_KEY) data = request.POST.get('data') signature = request.POST.get('signature') sign = liqpay.str_to_sign(settings.LIQPAY_PRIVATE_KEY + data + settings.LIQPAY_PRIVATE_KEY) if sign == signature: response = liqpay.decode_data_from_str(data) if settings.LIQPAY_SANDBOX_MODE: expected_status = 'sandbox' else: expected_status = 'success' if response['status'] == expected_status: task = Task.objects.get(pk=int(response['order_id'])) task.status = Task.DONE task.save() create_notification_task.delay( task.executor.id, task.id, 'Оплата завдання', 'Завдання #{} було оплачено.'.format(task.id) ) return HttpResponse("OK") return HttpResponse("Oops! Something went wrong.")