Esempio n. 1
0
    def comparison_bitcoin_address(self, bitcoin_address, status, amount):
        print(bitcoin_address, status, amount)
        comparison_bitcoin_address = User.query.filter(User.bitcoin_address ==
                                                         '{}'.format(bitcoin_address)).first()
        try:
            if (bitcoin_address == comparison_bitcoin_address.bitcoin_address) and (status == 'Deposit confirmed'):
                if comparison_bitcoin_address.referal_user is not None:
                    ref_balance = User.query.filter(User.user_id == int('{}'.format(
                        comparison_bitcoin_address.referal_user))).first()
                    print(ref_balance)
                    ref_balance.balance = format(float(ref_balance.balance) + float(amount) * 0.03, '.8f')
                    comparison_bitcoin_address.referal_user = None
                    db.session.add(ref_balance, comparison_bitcoin_address)
                    db.session.commit()
                zero_number = '0.00000000'
                amount_for_deposit = format(float(amount) + float(zero_number), '.8f')
                deposit_percent = format(float(amount) * 0.01, '.8f')
                user_id = comparison_bitcoin_address.user_id
                date_create = datetime.now().strftime('%d.%m.%Y')
                date_withdraw = datetime.now()+ relativedelta(days=30)
                deposit = Deposit(deposit_id=user_id, deposit=amount_for_deposit,
                deposit_with_percent=deposit_percent, data_create=date_create,
                data_withdraw=date_withdraw.strftime('%d.%m.%Y'))
                db.session.add(deposit)
                db.session.commit()
                bot.send_message(chat_id=user_id, text='Funds credited to your account.')

            else:
                print('error')
        except:
            db.session.rollback()
            raise
        finally:
            db.session.close()
Esempio n. 2
0
def reinvest_btc(message):
    chat_id = message.chat.id
    amount = message.text
    user_id = message.from_user.id
    database_user = User.query.filter(User.user_id == user_id).first()
    try:
        zero_number = '0.00000000'
        amount_for_deposit = format(float(amount) + float(zero_number), '.8f')
        balance_for_reinvest = database_user.balance
        if format(float(amount_for_deposit), '.8f') >= format(float('0.01000000'), '.8f'):
            if format(float(amount_for_deposit), '.8f') <= format(float(balance_for_reinvest), '.8f'):
                date_create = datetime.now().strftime('%d.%m.%Y')
                date_withdraw = datetime.now() + relativedelta(days=30)
                deposit = Deposit(deposit_id=user_id, deposit=amount_for_deposit,
                                  deposit_with_percent=amount_for_deposit, data_create=date_create,
                                  data_withdraw=date_withdraw.strftime('%d.%m.%Y'))
                database_user.balance = format(float(database_user.balance) - float(amount_for_deposit), '.8f')
                db.session.add(deposit, database_user)
                db.session.commit()
                bot.send_message(chat_id=user_id, text='A new deposit has been created.')
            else:
                bot.send_message(chat_id, "You've specified more than you have on your balance.")
        else:
            bot.send_message(chat_id, text='Minimum reinvestment amount 0.01 BTC')
    except:
        db.session.rollback()
        bot.send_message(chat_id, 'The operation failed, check the correct spelling.')
    finally:
        db.session.close()
Esempio n. 3
0
    def post(self):
        client_id = self.request.get_range('client_id')
        client = Client.get(client_id)
        if not client:
            self.response.set_status(400)
            self.render_json({"description": u'Клиент не найден'})
            return
        amount = self.request.get_range('amount', default=None)
        if amount is None or amount < 1:
            self.response.set_status(400)
            self.render_json({"description": u'Неверная сумма'})
            return

        wallet_source = "barista:%s:%s" % (self.user.login, int(time.time()))
        try:
            wallet_result = empatika_wallet.deposit(client_id, amount * 100, wallet_source)
        except EmpatikaWalletError as e:
            self.response.set_status(400)
            self.render_json({
                "description": e.message
            })
        else:
            self.user.deposit_history.append(Deposit(source=wallet_source, amount=amount))
            self.user.put()
            self.render_json({
                "balance": wallet_result["balance"] / 100.0
            })
Esempio n. 4
0
def test_deposit_creation_1(app):
    # given
    user = create_user()

    deposit = Deposit()
    deposit.user = user
    deposit.amount = 200
    deposit.source = "test money"

    # when
    PcObject.save(deposit)

    # then
    assert Deposit.query.count() == 1
Esempio n. 5
0
def create_deposit(user, amount=500, source='public'):
    deposit = Deposit()
    deposit.user = user
    deposit.source = source
    deposit.amount = amount
    return deposit
Esempio n. 6
0
def process_order(request):
    if request.method == 'POST':
        #Pull all data out of POST (some of it mightn't  be there)
        if request.POST.get('tickets'):
            tickets = int(request.POST.get('tickets', ''))
        if request.POST.get('deposits', ''):
            deposits = int(request.POST.get('deposits', ''))
        first_name = request.POST['first_name']
        last_name = request.POST['last_name']
        email = request.POST['email']
        phone = request.POST['phone']
        referring_ambassador_code = request.POST.get('referring_ambassador_code', '')
        deposit_code_one = request.POST.get('deposit_code_one', '')
        deposit_code_two = request.POST.get('deposit_code_two', '')
        deposit_code_three = request.POST.get('deposit_code_three', '')
        deposit_code_four = request.POST.get('deposit_code_four', '')
        deposit_code_five = request.POST.get('deposit_code_five', '')
        
        #First build the order
        order = Order(fname=first_name,
                      lname=last_name,
                      email=email,
                      phone=phone)
        order.save()
        
        #Initialise the lists to hold the possible ordered items
        ordered_tickets = []
        ordered_deposits = []
        ordered_balances = []
        
        
        if referring_ambassador_code: #Purchasing tickets and/or deposits
            referring_ambassador = Ambassador.objects.get(code=referring_ambassador_code)
            
            #Then generate tickets and deposits
            while tickets > 0:
                ticket = Ticket(order=order, ambassador=referring_ambassador)
                ticket.save()
                ordered_tickets.append(ticket)
                tickets -= 1
            
            while deposits > 0:
                deposit = Deposit(order=order, ambassador=referring_ambassador)
                deposit.save()
                ordered_deposits.append(deposit)
                deposits -= 1
        
        else: #Purchasing balances for paid deposits 
            if deposit_code_one != 'None':
                balance = Balance(order=order, deposit=Deposit.objects.get(code=deposit_code_one))
                balance.save()
                ordered_balances.append(balance)
            if deposit_code_two != 'None':
                balance = Balance(order=order, deposit=Deposit.objects.get(code=deposit_code_two))
                balance.save()
                ordered_balances.append(balance)
            if deposit_code_three != 'None':
                balance = Balance(order=order, deposit=Deposit.objects.get(code=deposit_code_three))
                balance.save()
                ordered_balances.append(balance)
            if deposit_code_four != 'None':
                balance = Balance(order=order, deposit=Deposit.objects.get(code=deposit_code_four))
                balance.save()
                ordered_balances.append(balance)
            if deposit_code_five != 'None':
                balance = Balance(order=order, deposit=Deposit.objects.get(code=deposit_code_five))
                balance.save()
                ordered_balances.append(balance)
            
        #Build the XML request for Google Checkout
        data = {"_type": "checkout-shopping-cart",
                "_charset_":""}
        itemcount = 0
        for ticket in ordered_tickets:
            itemcount += 1
            data['item_name_'+ str(itemcount)] = "1 x Summer Saturnalia 2011 Ticket"
            data['item_description_'+str(itemcount)] = 'One ticket including £2.50 booking fee. Unique ticket code: ' + str(ticket.code)
            data['item_price_'+str(itemcount)] = "57.50"
            data['item_currency_'+str(itemcount)] = "GBP"
            data['item_quantity_'+str(itemcount)] = "1"
            data['item_merchant_id_'+str(itemcount)] = ticket.code
            data['shopping-cart.items.item-'+str(itemcount)+'.digital-content.display-disposition'] = "OPTIMISTIC"
            data['shopping-cart.items.item-'+str(itemcount)+'.digital-content.description'] = "After your payment has been processed your printable ticket will be emailed to you; this normally takes less than a day."
        
        for deposit in ordered_deposits:
            itemcount += 1
            data['item_name_'+str(itemcount)] = "1 x Summer Saturnalia 2011 Deposit"
            data['item_description_'+str(itemcount)] = "One deposit including £2.50 booking fee. Unique deposit code: " + str(deposit.code)
            data['item_price_'+str(itemcount)] = "8"
            data['item_currency_'+str(itemcount)] = "GBP"
            data['item_quantity_'+str(itemcount)] = "1"
            data['item_merchant_id_'+str(itemcount)] = deposit.code
            data['shopping-cart.items.item-'+str(itemcount)+'.digital-content.display-disposition'] = "OPTIMISTIC"
            data['shopping-cart.items.item-'+str(itemcount)+'.digital-content.description'] = "Your deposit code is " + str(deposit.code) +".  You can use this code to pay the balance and obtain your ticket when payment has been processed.  This normally takes less than a day, after which a copy of this code will be emailed to you. "
        
        for balance in ordered_balances:
            itemcount += 1
            data['item_name_'+str(itemcount)] = "1 x Summer Saturnalia 2011 Balance Payment (Ticket)"
            data['item_description_'+str(itemcount)] = "The final payment for deposit number " + str(balance.deposit.code) + " - Booking already included in deposit."
            data['item_price_'+str(itemcount)] = "49.50"
            data['item_currency_'+str(itemcount)] = "GBP"
            data['item_quantity_'+str(itemcount)] = "1"
            data['item_merchant_id_'+str(itemcount)] = balance.deposit.code
            data['shopping-cart.items.item-'+str(itemcount)+'.digital-content.display-disposition'] = "OPTIMISTIC"
            data['shopping-cart.items.item-'+str(itemcount)+'.digital-content.description'] = "After your payment has been processed your printable ticket will be emailed to you; this normally takes less than a day."
        
        #Build the rest of the request and send to Google
        headers = {"Content-Type": 'application/xml; charset=UTF-8',
                   "Accpt": 'application/xml; charset=UTF-8'}

        h = Http()
        h.add_credentials('210280845590798', 'qqnL2K9V76aNWEVVXAoLtQ')

        resp, content = h.request("https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/210280845590798", 
                                  "POST",
                                  urlencode(data),
                                  headers=headers)
        #If everything worked, we can redirect the user to Google Checkout to complete payment
        
        location = resp['location']
        return redirect(location)
Esempio n. 7
0
def _create_initial_deposit(new_user):
    deposit = Deposit()
    deposit.amount = 499.99
    deposit.user = new_user
    deposit.source = 'test'
    return deposit