def add_balance(): """For GET requests, display the login form. For POSTS, login the current user by processing the form.""" form = BalanceForm() if form.validate_on_submit(): user = User.query.get(form.email.data) if user: if user.balance is None: user.balance = UserBalance() user.balance.amount = 0.0 user.balance.amount += form.amount.data txn_id = str(uuid.uuid4())[:8] reason = "ABU - Admin Balance update" credit_transaction = Transaction() credit_transaction.txn_id = txn_id credit_transaction.party = form.email.data credit_transaction.counter_party = "Admin" credit_transaction.amount = form.amount.data credit_transaction.type = 'Cr' credit_transaction.reason = reason db.session.add(user.balance) db.session.add(credit_transaction) db.session.commit() return redirect(url_for("user_page")) else: flash('Invalid User Id') return render_template("add_balance.html", form=form)
def post(self): data = flatten_arguments(self.request.arguments) from models import Transaction, Invoice from pprint import pformat invoice_id = data.get('invoice') if invoice_id: invoice = Invoice.get_by_id(int(invoice_id, 10)) txn = Transaction(invoice=invoice) txn.identifier = data.get('txn_id') txn.subscription_id = data.get("subscr_id") txn.transaction_type = data.get('txn_type') txn.currency = data.get('mc_currency') txn.amount = data.get('mc_gross', data.get('mc_amount3')) txn.data = pformat(data) txn.put() if self.verify(data): r = self.process(data, txn=txn, invoice=invoice) else: r = self.process_invalid(data, txn=txn, invoice=invoice) if r: self.write(r) else: self.write('Nothing to see here.') else: # error. invoice id was not found. pass
def storeTransactions(jsonTxs): # avoid serializers for now since all the blockchains will be nuanced and transaction mappings are # likely to differ. #print "Set Size: " + str(len(jsonTxs)) try: for tx in jsonTxs: #---------NEW ACCOUNT TEST ---------- # check if we have an account registered with the address querySet = Account.objects.filter(bitcoinAddress=tx['address']) owner = None if (len(querySet) == 0): print('About to add a covert account for address: ' + tx['address']) # store the address as a 'covert' account acc = Account() acc.owner = User.objects.filter(username="******")[0] acc.bitcoinAddress = tx['address'] acc.bitcoinBalance = 0.0 acc.ethereumAddress = "TBA" acc.ethereumBalance = 0.0 acc.pendingTx = "[]" acc.latestTx = "[]" acc.save() owner = acc.owner else: owner = querySet.first().owner # ----------------------------------- transaction = Transaction() transaction.target = owner transaction.involvesWatchonly = tx['involvesWatchonly'] transaction.account = tx['account'] transaction.address = tx['address'] transaction.category = tx['category'] transaction.amount = tx['amount'] transaction.label = tx['label'] transaction.confirmations = tx['confirmations'] transaction.blockhash = tx['blockhash'] transaction.blockindex = tx['blockindex'] transaction.blocktime = tx['blocktime'] transaction.txid = tx['txid'] transaction.vout = tx['vout'] transaction.walletconflicts = tx['walletconflicts'] transaction.time = tx['time'] transaction.timereceived = tx['timereceived'] transaction.bip125replaceable = tx['bip125-replaceable'] transaction.save() # since this is getting more interesting, let's store the unknown accounts as well # even though the addresses may not be part of the exchange it can infer balances # and patterns in the future an discovery services! :) except: print traceback.print_exc()
def GetTransactionData(self,dataPost, amount): transactionModel = Transaction() transactionModel.stripe_token = dataPost['stripeToken'] transactionModel.date = datetime.datetime.now() transactionModel.amount = amount transactionModel.address = dataPost['address'] transactionModel.city = dataPost['city'] transactionModel.zip = dataPost['zip'] return transactionModel
def post(self): company = Company.query.get(request.form['company_id']) if company is None: return jsonify(message='Company does not exists') transaction = Transaction() transaction.company_id = company.id transaction.type = request.form['type'] transaction.amount = request.form['amount'] transaction.date = request.form['date'] db.session.add(transaction) db.session.commit() return jsonify(transaction.serialize)
def dummy_transaction(request): transaction = Transaction() transaction.user_id = 0 transaction.bank_id = 0 transaction.category_id = 0 transaction.description = 'test' transaction.amount = 1337.37 transaction.date = datetime.now() def teardown(): pass # db_session.delete(transaction) # transaction not even added to db at first request.addfinalizer(teardown) return transaction
def charge_players(): """For GET requests, display the login form. For POSTS, login the current user by processing the form.""" form = ChargePlayersForm() if form.validate_on_submit(): date_str = form.play_date.data total_amount = form.total_amount.data reason = form.reason.data play_date = parser.parse(date_str).date() played_date = PlayScheduledDates.query.filter(PlayScheduledDates.play_date==play_date).first() attending_players = [ attendee for attendee in played_date.attendees if attendee.status=='Yes'] total_players = len(attending_players) if len(attending_players) else 1 amount_per_head = total_amount/float(total_players) low_balance_users = {} for attendee in attending_players: user = User.query.get(attendee.attendee_email) if user: user.debit_balance(amount_per_head) txn_id = str(uuid.uuid4())[:8] debit_transaction = Transaction() debit_transaction.txn_id = txn_id debit_transaction.party = user.email debit_transaction.counter_party = "Admin" debit_transaction.amount = -amount_per_head debit_transaction.type = 'Dr' debit_transaction.reason = reason db.session.add(debit_transaction) db.session.add(user) if user.get_balance() < 10 : low_balance_users[user.email] = (user.first_name, user.get_balance()) played_date.is_charged = True; db.session.commit() send_bulk_emails(low_balance_users) return redirect(url_for("user_page")) return render_template("charge_players.html", form=form)
def send_money(): """For GET requests, display the login form. For POSTS, login the current user by processing the form.""" form = PayForm() if form.validate_on_submit(): transaction_amount = form.amount.data sender = current_user receiver = User.query.get(form.receiver_email.data) if receiver is None: flash('Receiver Does Not exist in system') return render_template("pay.html", form=form) if sender.balance is None or sender.balance.amount < transaction_amount: flash('You have insufficient balance') return render_template("pay.html", form=form) if transaction_amount <= 0: flash('Wrong amount entered') return render_template("pay.html", form=form) if sender.email == receiver.email: flash('Sender and Receiver Cant be same') return render_template("pay.html", form=form) sender.debit_balance(transaction_amount) receiver.credit_balance(transaction_amount) txn_id = str(uuid.uuid4())[:8] reason = "SNM - Send Money" debit_transaction = Transaction() debit_transaction.txn_id = txn_id debit_transaction.party = sender.email debit_transaction.counter_party = receiver.email debit_transaction.amount = -transaction_amount debit_transaction.type = 'Dr' debit_transaction.reason = reason credit_transaction = Transaction() credit_transaction.txn_id = txn_id credit_transaction.party = receiver.email credit_transaction.counter_party = sender.email credit_transaction.amount = transaction_amount credit_transaction.type = 'Cr' credit_transaction.reason = reason db.session.add(sender.balance) db.session.add(receiver.balance) db.session.add(debit_transaction) db.session.add(credit_transaction) db.session.commit() if current_user.get_balance() < 10 : send_low_balance_email(current_user.email, current_user.first_name, current_user.get_balance()) return redirect(url_for("user_page")) return render_template("send_money.html", form=form)