Пример #1
0
def confirm_deposit():
    if request.method == 'POST':
        form = request.form
        psid = int(form.get('paymentSystemId', None))
        amount = float(form.get('amount', None))
        # ipid = form.get('invPlanId', None)
        # unit = form.get('unit', None)
        if psid and amount:
            from sbb import application
            if (psid == 1 or psid
                    == 3) and amount < application.config['MINUSDDEPOSIT']:
                flash('Deposit value range violation')
                return redirect(url_for('userprofile.makedeposit'))
            elif (psid == 1 or psid
                  == 3) and amount > application.config['MAXUSDDEPOSIT']:
                flash('Deposit value range violation')
                return redirect(url_for('userprofile.makedeposit'))
            if (psid == 2 or psid
                    == 4) and amount < application.config['MINBTCDEPOSIT']:
                flash('Deposit value range violation')
                return redirect(url_for('userprofile.makedeposit'))
            elif (psid == 2 or psid
                  == 4) and amount > application.config['MAXBTCDEPOSIT']:
                flash('Deposit value range violation')
                return redirect(url_for('userprofile.makedeposit'))

            from sbb import db
            from models import InvestmentPlan
            from models import PaymentSystems
            from models import Transaction
            from models import TransactionType
            from models import AccountInvestments

            # TBD taxes
            if psid == 1 and amount > current_user.account.balance:
                flash('You have not enough USD on your referral balance')
                return redirect(url_for('userprofile.makedeposit'))
            elif psid == 2 and amount > current_user.account.bitcoin:
                flash('You have not enough BTC on your referral balance')
                return redirect(url_for('userprofile.makedeposit'))

            trType = TransactionType.query.filter_by(id=3).first()
            ps = PaymentSystems.query.filter_by(id=psid).first()
            # active investmment plan
            ip = InvestmentPlan.query.filter_by(active=1).first()

            dep_act = Transaction(date=datetime.datetime.now(),
                                  amount=amount,
                                  status=0)
            dep_act.account = current_user.account
            dep_act.transactionType = trType
            dep_act.paymentSystem = ps
            dep_act.investmentPlan = ip
            dep_act.unit = ps.unit
            db.session.add(dep_act)
            db.session.commit()

            if psid == 1 or psid == 2:
                return render_template('profile/confirm_ref_deposit.html',
                                       invPlan=ip,
                                       paymentSystem=ps,
                                       amount=amount,
                                       depId=dep_act.id,
                                       unit=dep_act.unit,
                                       dn=application.config['DOMAIN_NAME'])
            else:
                return render_template('profile/confirm_deposit.html',
                                       invPlan=ip,
                                       paymentSystem=ps,
                                       amount=amount,
                                       depId=dep_act.id,
                                       unit=dep_act.unit,
                                       dn=application.config['DOMAIN_NAME'])
        else:
            flash('Invalid data supplied in deposit form {} - {}'.format(
                psid, amount))
            return redirect(url_for('userprofile.makedeposit'))

    else:
        return redirect(url_for('userprofile.makedeposit'))