def pay_user_ajax(request, recipient_username): data = {} recipient = get_object_or_404(Profile, user__username=recipient_username) if recipient == request.profile: raise Http404 # TODO: Don't recompute max_amount on form submit? Cache, or put in form # as hidden field? max_amount = ripple.max_payment(request.profile, recipient) if request.method == 'POST': form = AcknowledgementForm(request.POST, max_ripple=max_amount) if form.is_valid(): acknowledgement = form.send_acknowledgement( request.profile, recipient) create_notification(notifier=request.profile, recipient=recipient, type=Notification.PAYMENT) has_referral = Referral.objects.filter(referrer=request.profile, recipient=recipient).all() # send_acknowledgement_notification(acknowledgement) messages.info(request, MESSAGES['acknowledgement_sent']) data['stat'] = 'ok' data['recipient'] = recipient_username data['refer'] = True if has_referral else False return JsonResponse({'data': data}) else: form = AcknowledgementForm(max_ripple=max_amount, initial=request.GET) can_ripple = max_amount > 0 profile = recipient # For profile_base.html. data['stat'] = 'error' return JsonResponse({'data': data})
def blank_payment(request): listing_form = ListingsForms() received_payments = FeedItem.objects.filter( recipient_id=request.profile.id, item_type='acknowledgement').order_by('-date') made_payments = FeedItem.objects.filter( poster_id=request.profile.id, item_type='acknowledgement').order_by('-date') form = BlankPaymentForm(max_ripple=None, initial=request.GET) if request.method == 'POST': if not request.POST['recipient']: messages.add_message(request, messages.ERROR, 'The recipient is invalid, please verify') return django_render(request, 'blank_payment.html', { 'form': form, 'listing_form': listing_form }) recipient = get_object_or_404(Profile, user__username=request.POST['recipient']) max_amount = ripple.max_payment(request.profile, recipient) form = BlankPaymentForm(request.POST, max_ripple=max_amount) if recipient == request.profile: messages.add_message(request, messages.ERROR, 'You cant send a payment to yourself') return django_render(request, 'blank_payment.html', { 'form': form, 'listing_form': listing_form }) can_ripple = max_amount > 0 if not can_ripple and request.POST['ripple'] == 'routed': messages.add_message( request, messages.ERROR, 'There are no available paths through the trust network, ' 'so you can only send direct trust') form = BlankPaymentForm(max_ripple=None, initial=request.GET) return django_render(request, 'blank_payment.html', { 'form': form, 'listing_form': listing_form }) payment = form.send_payment(request.profile, recipient, request.POST) create_notification(notifier=request.profile, recipient=recipient, type=Notification.PAYMENT) # send_payment_notification(payment) messages.add_message(request, messages.INFO, 'Payment sent.') return HttpResponseRedirect(reverse('blank_payment_user')) else: form = BlankPaymentForm(max_ripple=None, initial=request.GET) return django_render( request, 'blank_payment.html', { 'form': form, 'listing_form': listing_form, 'received_payments': received_payments, 'made_payments': made_payments })
def acknowledge_user_ajax(request, recipient_username): data = {} recipient = get_object_or_404(Profile, user__username=recipient_username) if recipient == request.profile: data['stat'] = 'You cannot send a payment to yourself' return JsonResponse({'data': data}) else: max_amount = ripple.max_payment(request.profile, recipient) can_ripple = max_amount > 0 data['stat'] = 'ok' data['can_ripple'] = can_ripple data['max_amount'] = max_amount data['recipient'] = recipient_username return JsonResponse({'data': data})
def get_user_photo(request, profile_username): """ This method is used to catpure user_photo path, payment list summary and max trust amount in payments :param request: :param profile_id: :return: """ data = {} payments = [] profile = Profile.objects.get(user__username=profile_username) if profile == request.profile: data['error'] = "same_user" data['error_message'] = "You can't send a trust to yourself" return JsonResponse({'data': data}) payment_list = FeedItem.objects.filter(poster_id=request.profile.id, recipient_id=profile.id).all() recipient = get_object_or_404(Profile, id=profile.id) try: trust = Endorsement.objects.get(endorser=request.profile, recipient=recipient) except Endorsement.DoesNotExist: trust = None max_amount = ripple.max_payment(request.profile, recipient) can_ripple = max_amount > 0 if payment_list: for each_payment in payment_list: payments.append('{0} paid {1} in {2}'.format( each_payment.poster.name, each_payment.recipient.name, each_payment.date.date())) if trust: refer = Referral.objects.filter(referrer=request.profile, recipient=recipient) if refer: data['refer'] = True data['has_trust'] = True data['credit_limit'] = trust.weight data['text'] = trust.text data['updated'] = trust.updated profile_photo_path = '/uploads/' + str(profile.photo) data['profile_photo_path'] = profile_photo_path data['payment_list'] = payments data['max_amount'] = max_amount data['can_ripple'] = can_ripple data['recipient'] = recipient.name return JsonResponse({'data': data})
def pay(request): if not request.profile: messages.add_message(request, messages.WARNING, 'You must be logged in to send this trust') return render(request, 'pre_payment.html') username = request.GET.get('username') hours = request.GET.get('hours') text = request.GET.get('text') if not username or not hours: messages.add_message(request, messages.ERROR, 'Invalid parameters, please verify') return render(request, 'pre_payment.html') try: recipient = Profile.objects.get(user__username=username) except Profile.DoesNotExist: messages.add_message(request, messages.ERROR, 'The user is invalid') return render(request, 'pre_payment.html') if recipient == request.profile: messages.add_message(request, messages.WARNING, "You can't send a trust to yourself") return render(request, 'pre_payment.html') else: if request.method == 'POST': payment_type = request.POST.get('ripple') if text: text = text.encode('UTF-8') if hours: hours = hours.encode('UTF-8') if payment_type: payment_type = payment_type.encode('UTF-8') send_payment(request.profile, recipient, float(hours), text, payment_type) create_notification(notifier=request.profile, recipient=recipient, type=Notification.PAYMENT) messages.add_message(request, messages.SUCCESS, 'Successfully sent payment') return HttpResponseRedirect(reverse('frontend:home')) else: max_amount = ripple.max_payment(request.profile, recipient) can_ripple = max_amount > 0 return render(request, 'pre_payment.html', {'recipient': recipient, 'hours': hours, 'text': text, 'can_ripple': can_ripple, 'max_amount': max_amount})
def acknowledge_user(request, recipient_username): recipient = get_object_or_404(Profile, user__username=recipient_username) if recipient == request.profile: raise Http404 # TODO: Don't recompute max_amount on form submit? Cache, or put in form # as hidden field? max_amount = ripple.max_payment(request.profile, recipient) if request.method == 'POST': form = AcknowledgementForm(request.POST, max_ripple=max_amount) if form.is_valid(): acknowledgement = form.send_acknowledgement( request.profile, recipient) create_notification(notifier=request.profile, recipient=recipient, type=Notification.PAYMENT) send_acknowledgement_notification(acknowledgement) messages.info(request, MESSAGES['acknowledgement_sent']) return HttpResponseRedirect(acknowledgement.get_absolute_url()) else: form = AcknowledgementForm(max_ripple=max_amount, initial=request.GET) can_ripple = max_amount > 0 profile = recipient # For profile_base.html. return locals()