Пример #1
0
def voucher_generate(request):
    is_seller = voucher_service.is_seller(request.user)
    if not is_seller:
        raise PermissionDenied(CORE_UI_STRINGS.UI_PAGE_NOT_ALLOWED)
    page_title = _("Voucher Generator") + ' | ' + settings.SITE_NAME
    template_name = "voucher/voucher_generate.html"
    if request.method == "POST":
        postdata = utils.get_postdata(request)
        form = VoucherCreationForm(postdata)
        if form.is_valid():
            name = form.cleaned_data['name']
            amount = form.cleaned_data['amount']
            number = form.cleaned_data['number']
            logger.info("Submitted Voucher Creation Form is valid.")
            logger.info(
                f"Voucher creation request by user {request.user.username} : Name : {name} - Amout : {amount} - Number : {number}"
            )
            generate_voucher.apply_async(
                args=[{
                    'name': name,
                    'amount': amount,
                    'number': number,
                    'user': request.user.pk
                }],
                queue=settings.CELERY_VOUCHER_GENERATE_QUEUE,
                routing_key=settings.CELERY_VOUCHER_ROUTING_KEY)
            logger.info("Voucher Creation pushed in the Queue")
            return redirect('voucher:voucher-home')
    context = {
        'page_title': page_title,
        'template_name': template_name,
    }
    context['content_title'] = CORE_UI_STRINGS.UI_VOUCHER_GENERATE_TITLE
    return render(request, template_name, context)
Пример #2
0
def recharge_user_account_view(request):

    is_seller = voucher_service.is_seller(request.user)
    if not is_seller:
        raise PermissionDenied(CORE_UI_STRINGS.UI_PAGE_NOT_ALLOWED)

    page_title = _("Recharge User Account") + ' - ' + settings.SITE_NAME
    template_name = "voucher/recharge.html"

    logger.info("User Recharge Account view requested by user %s",
                request.user.get_full_name())
    if request.method == "POST":
        logger.info("Received new Recharge request for user account")
        postdata = utils.get_postdata(request)
        form = RechargeCustomerAccountByStaff(postdata)
        if form.is_valid():
            seller = form.cleaned_data['seller']
            customer = form.cleaned_data['customer']
            amount = form.cleaned_data['amount']
            logger.info(
                "recharge_user_account_view() : Received form is valid. Customer = %s - Seller = %s - Amount = %s .",
                customer, seller, amount)
            customer = get_object_or_404(User, pk=customer)
            seller = get_object_or_404(User, pk=seller)
            #result = voucher_service.VoucherService.process_recharge_user_account(seller=seller, customer=customer, amount=amount)
            result = voucher_service.VoucherService.recharge_balance(
                seller=seller, customer=customer, amount=amount)
            if result.get('succeed', False):
                messages.success(
                    request,
                    _("The customer balance has been successfully recharged"))
                logger.info(
                    "recharge_user_account_view() : Customer %s was successfully recharge with the Amount = %s .",
                    customer, amount)
                return redirect('voucher:voucher-home')
            else:
                messages.error(
                    request,
                    _("Your request could not processed. You might need to check that the submitted data are correct."
                      ))
                logger.info(
                    "recharge_user_account_view() : Customer = %s could not be recharge with the  Amount = %s .",
                    customer, amount)
        else:

            context['errors'] = _(
                "The submitted form is not valid. Verify the form fields")
            context['form'] = form
            messages.error(
                request,
                _("The submitted form is not valid. Verify the form fields"))
            logger.info(
                "recharge_user_account_view() : Received form is invalid")
            logger.error(form.errors)
    elif request.method == "GET":
        form = RechargeCustomerAccountByStaff()
    context = {'form': form, 'page_title': page_title}
    context['content_title'] = CORE_UI_STRINGS.UI_BALANCE_RECHARGE_TITLE
    return render(request, template_name, context)
Пример #3
0
def update_idcard(request, idcard_uuid):
    logger.info(f"API: update idcard request from user {request.user.username}")
    if request.method != 'POST':
        return Response({'status': False, 'errror': 'Bad request. Use POST instead'}, status=status.HTTP_400_BAD_REQUEST)
    
    data = payment_service.update_idcard(idcard_uuid, utils.get_postdata(request), request.FILES)
    
    return Response(data=data, status=status.HTTP_200_OK)
Пример #4
0
def payments(request):
    status_code = status.HTTP_200_OK
    try: 
        result = payment_service.get_payments(request.user, data=utils.get_postdata(request))
        if not result['is_valid']:
            status_code  = status.HTTP_400_BAD_REQUEST
    except Exception as e:
        logger.warn("Exception occured on payments api ", e)
        status_code  = status.HTTP_500_INTERNAL_SERVER_ERROR
    
    return Response(data=result, status=status_code)
Пример #5
0
def make_transfer(request):
    data = utils.get_postdata(request)
    transfer = payment_service.create_transfer(data)
    response_data = None
    if transfer:
        response_data = {
            'success' : True,
            'amount': transfer.amount,
            'redirect_url' : reverse('payments:payment-home')
        }
    else:
        response_data = {
            'success' : False,
            'redirect_url' : reverse('payments:payment-home')
        }
    return Response(response_data)
Пример #6
0
def make_payment(request):
    logger.info("api make payment")
    data = utils.get_postdata(request)
    payment = payment_service.create_payment(data)
    response_data = None
    if payment:
        response_data = {
            'success' : True,
            'amount': payment.amount,
            'redirect_url' : reverse('payments:payment-home')
        }
    else:
        response_data = {
            'success' : False,
            'redirect_url' : reverse('payments:payment-home')
        }
    return Response(response_data)
Пример #7
0
def make_recharge(request):
    data = utils.get_postdata(request)
    result = payment_service.create_recharge(data, request.user)
    response_data = None
    if result.get('success'):
        response_data = {
            'success' : True,
            'message': result.get('message'),
            'amount': result.get('amount'),
            'redirect_url' : reverse('payments:payment-home')
        }
    else:
        response_data = {
            'success' : False,
            'message': result.get('message'),
            'redirect_url' : reverse('payments:payment-home')
        }
    return Response(response_data)
Пример #8
0
def dummy(request):
    logger.info("api dummy request")
    data = utils.get_postdata(request)
    logger.info(f"Dummy Submitted Data : {data}")
    return Response({'dummy': 'request dummy', 'test': 'test result', 'user': request.user.username, 'submitted_data': data})
Пример #9
0
def transfers(request):
    result = payment_service.get_transfers(request.user, data=utils.get_postdata(request))
    return Response(data=result)