def refer_withdraw_done(request): if 'user_email' in request.session: if request.method=="POST": withdraw_amount=request.POST['amount'] paypal_email = request.POST['paypal_email'] email=request.session['user_email'] obj=user_data.objects.get(email=email) refbalance=obj.refer_balance if (float(withdraw_amount) >= 100.00): if(float(withdraw_amount)<=float(refbalance)): add_with = withdraws(paypal_email=paypal_email, user_email=email, withdraw_amount=withdraw_amount, status='pending') add_with.save() txn_id = gen_order(5) txns = transection(txn_id=txn_id, amount=withdraw_amount, email=email, status='SUCCESS', details="DEBITED", message="WITHDRAW") obj.refer_balance=float(refbalance)-float(withdraw_amount) obj.save() messages.success(request, "Withdraw Successfull !!") return redirect('refer') else: messages.error(request, "Insufficiant Fund !!") return redirect('refer_withdraw') else: messages.error(request, "MINIMUM WTIHDRAW IS $100.") return redirect('refer_withdraw') else: messages.success(request, "Your Session Has Expired Login To Access") return redirect('login')
def add_fund(request): for Inv_Detail in Invest_Detail.objects.all(): if str(Inv_Detail.investment) == "running": plan_det = get_plan(Inv_Detail.plan) interest = plan_det['interest'] month = plan_det['month'] type = plan_det['type'] if (datetime.now()).strftime("%Y-%m-%d") == ((Inv_Detail.date_time + timedelta(days=month * 30)).date()).strftime("%Y-%m-%d"): xx = Invest_Detail.objects.get(email=Inv_Detail.email,invest_id=Inv_Detail.invest_id) xx.investment="completed" xx.save() print(u.withdrawable_balance, xx.amount) u = user_data.objects.get(email=Inv_Detail.email) u.balance = float(u.balance) + float(xx.amount) u.withdrawable_balance = float(u.withdrawable_balance) + float(xx.amount) u.save() else: ppd = cal_interest(Inv_Detail.plan, Inv_Detail.amount) u = user_data.objects.get(email=Inv_Detail.email) u.balance = u.balance + float(ppd['profit_day']) u.withdrawable_balance = u.withdrawable_balance + float(ppd['profit_day']) u.save() txn_id = gen_order(10) txns = transection(txn_id=txn_id, amount=ppd['profit_day'], email=Inv_Detail.email, status='SUCCESS', details="CREDIT", message="INTEREST") txns.save() print('The User Email is : ', Inv_Detail.email, 'Will Recived : $', ppd['profit_day'], 'today') return HttpResponse('success')
def withdraw(request): if 'user_email' in request.session: email=request.session['user_email'] data=user_data.objects.get(email=email) if request.method=="POST": paypal_email = request.POST['paypal_email'] amount = request.POST['amount'] if float(data.withdrawable_balance) < float(amount) : messages.error(request,'Insufficiant Fund !!') return redirect('withdraw') else: add_with=withdraws(paypal_email=paypal_email,user_email=email,withdraw_amount=amount,status='pending') add_with.save() data.withdrawable_balance=float(data.withdrawable_balance)-float(amount) data.balance=float(data.balance)-float(amount) data.save() txn_id=gen_order(5) txns = transection(txn_id=txn_id, amount=amount, email=email, status='SUCCESS', details="DEBITED", message="WITHDRAW") txns.save() messages.success(request, 'Withdraw Successfull !! You Will Recive Payment Within ') return redirect('withdraw') else: context={ 'balance':data.balance, 'withdraw_amount':data.withdrawable_balance, } return render(request,"user/withdraw.html",context) else: messages.success(request, "Your Session Has Expired Login To Access") return redirect('login')
def add_funds(request): #user=user_data.objects.all() for user in user_data.objects.all(): email = user.email In_det= Invest_Detail.objects.filter(email=email) for Inv_Detail in In_det: plan_det=get_plan(Inv_Detail.plan) interest=plan_det['interest'] month = plan_det['month'] type = plan_det['type'] ppd=cal_interest(Inv_Detail.plan,Inv_Detail.amount) u = user_data.objects.get(email=email) u.balance = u.balance + float(ppd['profit_day']) u.withdrawable_balance = u.withdrawable_balance + float(ppd['profit_day']) u.save() txn_id=gen_order(10) txns = transection(txn_id=txn_id, amount=ppd['profit_day'], email=email, status='SUCCESS', details="CREDIT",message="INTEREST") txns.save() print('amount',Inv_Detail.amount) print('The User Email is : ',email,'Will Recived : $',ppd['profit_day'],'today') return HttpResponse('success')
def make_invest(request): if 'user_email' in request.session: if request.method=="POST": if request.POST['pay'] == 'pay': plan_det = get_plan(request.POST['plan']) interest = plan_det['interest'] month = plan_det['month'] type = plan_det['type'] amount = request.POST['amount'] context = { 'plan': request.POST['plan'], 'amount': amount, 'amount_pay': float(amount) * 100, 'interest': interest, 'month': month, 'type': type, 'key': settings.STRIPE_PUBLISHABLE_KEY, } return render(request, 'user/pay.html', context) else: if request.POST['create_order'] == 'True': email = request.session['user_email'] plan = request.POST['plan'] amount = request.POST['amount'] plan_det = get_plan(plan) interest = plan_det['interest'] month = plan_det['month'] type = plan_det['type'] invest_id = gen_order(15) o = user_data.objects.get(email=email) referbalance = o.refer_balance refbalance = (float(amount) / 100) * 1.5 finalreferbalance = referbalance + refbalance refcode = o.refer_code if refcode=="NULL": pass else: oob = user_data.objects.get(id=refcode) oob.refer_balance = finalreferbalance oob.save() try: charges = stripe.Charge.create( shipping={ 'name': 'Jenny Rosen', 'address': { 'line1': '510 Townsend St', 'postal_code': '98140', 'city': 'San Francisco', 'state': 'CA', 'country': 'US', }, }, amount=int(amount) * 100, currency="usd", source=request.POST['stripeToken'], description="Payment For Plan", metadata={'invest_id': invest_id} ) if charges["status"] == "succeeded": txn_id=charges['balance_transaction'] obj = Invest_Detail(plan=plan, amount=amount, email=email, invest_id=invest_id, intrest=interest, month=month, invest_type=type) cont = "Congrates You Have Successfully invested : $"+amount+"Your TXN_ID is "+txn_id send_mail( "Investment successfull", cont, settings.EMAIL_HOST_USER, [email], fail_silently=False, ) obj.save() # updating balance u = user_data.objects.get(email=email) u.balance = u.balance + float(amount) u.save() txns=transection(txn_id=txn_id,amount=amount,email=email,status='SUCCESS',details="CREDIT",message="INVESTED") txns.save() return render(request, 'user/payment_success.html', {'amount': amount}) else: messages.success(request, 'Payment Failed !! Try Again') return redirect('dashboard') except: return redirect('invest') else: messages.success(request, "Your Session Has Expired Login To Access") return redirect('login')