Exemplo n.º 1
0
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
Exemplo n.º 3
0
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))
Exemplo n.º 4
0
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.*'
Exemplo n.º 5
0
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.*'
Exemplo n.º 6
0
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))
Exemplo n.º 7
0
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