def save(slack_user_id, synapse_user, params): """Create a Synapse transaction from one node to another.""" user = User.from_slack_id(slack_user_id) debit_node = Node.by_id(user=synapse_user, id=user.debit_node_id) savings_node = Node.by_id(user=synapse_user, id=user.savings_node_id) amount = remove_dollar_signs(first_word(params)) if not amount: # invalid params return invalid_params_warning('send') if 'every' in params: # recurring transaction periodicity = word_after(params, 'every') return create_recurring_transaction(amount=amount, from_id=debit_node.id, to_id=savings_node.id, periodicity=periodicity, slack_user_id=slack_user_id) process_in = None if 'in' in params: # scheduled transaction process_in = word_after(params, 'in') return create_transaction(amount=amount, debit_node=debit_node, savings_node_id=savings_node.id, process_in=process_in)
def getAddenda(userId, wyre_amount, wyre_date): user = User.by_id(synapseClient, userId) addenda = "" options = {'page': 1, 'per_page': 20, 'type': 'SUBACCOUNT-US'} nodes = Node.all(user, **options) if not nodes: return addenda nodeid = getattr(nodes[0], 'id') node = Node.by_id(user, nodeid) transactions = Transaction.all(node, **options) x = len(transactions) print("transactions\n") print(x) for translist in range(0, x): amount = getattr(transactions[translist], 'amount') timelines = getattr(transactions[translist], 'timelines') real_amount = amount.get("amount") if real_amount == wyre_amount: for d in timelines: if d.get("status") == "CREATED": if d.get("date") == wyre_date: from_info = getattr(transactions[translist], 'from') addenda = from_info.get("meta").get("addenda") print("addenda:", addenda) return addenda
def process(): threading.Timer(2 * 60, process).start() for pendingDeactiveNode in getPendingDoc(db.deactive_nodes): userId = pendingDeactiveNode.get('userId') if userId is not None: user = User.by_id(client, userId, 'yes') nodes = Node.all(user) for node in nodes: client.nodes.delete(userId, node.id) # set to DONE markDel(userId,'DEACTIVATED-NODE') markDoneDoc(db.deactive_nodes, userId) for pendingDeactiveNode in getPendingDoc(db.lock_users): userId = pendingDeactiveNode.get('userId') if userId is not None: user = User.by_id(client, userId, 'yes') if user.permission != 'MAKE-IT-GO-AWAY': payload = { 'permission': 'MAKE-IT-GO-AWAY' } client.users.update(userId, payload) # set to DONE markDel(userId,'LOCKED-USER') markDoneDoc(db.lock_users, userId)
def list_nodes(slack_user_id, synapse_user, params): """Return information on the the user's Synapse nodes.""" nodes = Node.all(user=synapse_user) if nodes: return '\n'.join([node_summary(node) for node in nodes]) else: return '*No nodes found for user.*'
def cancel(slack_user_id, synapse_user, params): """Cancel a transaction by Synapse transaction ID.""" user = User.from_slack_id(slack_user_id) debit_node = Node.by_id(user=synapse_user, id=user.debit_node_id) trans_id = first_word(params) transaction = Transaction.by_id(node=debit_node, id=trans_id) transaction = transaction.cancel() return ('*Transaction cancelled.*\n' + transaction_summary(transaction))
def history(slack_user_id, synapse_user, params): """Return information on the the Synapse nodes's transactions.""" user = User.from_slack_id(slack_user_id) debit_node = Node.by_id(user=synapse_user, id=user.debit_node_id) transactions = Transaction.all(node=debit_node) if transactions: return '\n'.join([transaction_summary(trans) for trans in transactions]) else: return '*No transactions found.*'
def balance(slack_user_id, synapse_user, params): """Return balance on SYNAPSE-US savings account.""" user = User.from_slack_id(slack_user_id) savings_node = Node.by_id(user=synapse_user, id=user.savings_node_id) if savings_node: balance = format_currency(savings_node.balance) return '```Savings: {0}```'.format(balance) else: return '*No savings node found for user.*'
def verify_node(slack_user_id, synapse_user, params): """Activate a node with Synapse via microdeposits and return node info.""" user = User.from_slack_id(slack_user_id) amount1 = first_word(params) amount2 = word_after(params, amount1) if not amount1 or not amount2: return invalid_params_warning('verify') node = Node.by_id(user=synapse_user, id=user.debit_node_id) node = node.verify_microdeposits(amount1=amount1, amount2=amount2) return ('*Node verified.*\n' + node_summary(node))
def getSynapseData(userId, nodeId, subnetId): user = User.by_id(client, userId) node = Node.by_id(user, nodeId) subnet = Subnet.by_id(node, subnetId) return user, node, subnet