Ejemplo n.º 1
0
def process_confirm(from_, code):
    # step one: delete all the old confirm codes
    db = sqlite3.connect(pending_db)
    db.execute("DELETE FROM pending_transfers WHERE time - ? > 600",
               (time.time(), ))
    db.commit()

    # step two: check if this (from, code) combo is valid.
    r = db.execute(
        "SELECT from_acct, to_acct, amount FROM pending_transfers WHERE code=? AND from_acct=?",
        (code, from_))
    res = r.fetchone()
    if res and len(res) == 3:
        from_acct, to_acct, amount = res
        from_num = vbts_credit._number_from_name(from_acct)
        to_num = vbts_credit._number_from_name(to_acct)
        reason = "SMS transfer from %s to %s" % (from_num, to_num)
        consoleLog('info', "KURTIS|" + str(reason) + "\n")
        vbts_credit.transfer(int(amount), from_acct, to_acct, reason)
        new_from_balance = vbts_credit.get(from_acct)
        new_to_balance = vbts_credit.get(to_acct)

        # let the recipient know they got credit
        resp = conf["received"] % (amount, from_num, new_to_balance)
        db.execute(
            "DELETE FROM pending_transfers WHERE code=? AND from_acct=?",
            (code, from_))
        db.commit()
        _send_to_freeswitch(to=to_num, body=resp)

        return True, conf['confirm'] % (amount, to_num, new_from_balance)
    return False, conf["code_fail"]
def process_confirm(from_, code):
    # step one: delete all the old confirm codes
    db = sqlite3.connect(pending_db)
    db.execute("DELETE FROM pending_transfers WHERE time - ? > 600", (time.time(),))
    db.commit()

    # step two: check if this (from, code) combo is valid.
    r = db.execute("SELECT from_acct, to_acct, amount FROM pending_transfers WHERE code=? AND from_acct=?", (code, from_))
    res = r.fetchone()
    if res and len(res) == 3:
        from_acct, to_acct, amount = res
        from_num = vbts_credit._number_from_name(from_acct)
        to_num = vbts_credit._number_from_name(to_acct)
        reason = "SMS transfer from %s to %s" % (from_num, to_num)
        consoleLog('info', "KURTIS|" + str(reason) + "\n")
        vbts_credit.transfer(int(amount), from_acct, to_acct, reason)
        new_from_balance = vbts_credit.get(from_acct)
        new_to_balance = vbts_credit.get(to_acct)

        # let the recipient know they got credit
        resp = conf["received"] % (amount, from_num, new_to_balance)
        db.execute("DELETE FROM pending_transfers WHERE code=? AND from_acct=?", (code, from_))
        db.commit()
        _send_to_freeswitch(to=to_num, body=resp)

        return True, conf['confirm'] % (amount, to_num, new_from_balance)
    return False, conf["code_fail"]
def process_transfer(from_, to, amount):
    from_balance = vbts_credit.get(from_)
    consoleLog('info', "KURTIS|" + str(from_) + ":" +  str(from_balance) + "\n")
    if not from_balance or from_balance < amount:
        return False, conf['no_credit']
    if not to or vbts_credit.get(to) == None: # could be 0! Need to check if doesn't exist.
        return False, conf["wrong_number"]

    # add the pending transfer
    code = ''
    for r in range(code_length):
        code += str(random.randint(0,9))
    db = sqlite3.connect(pending_db)
    db.execute("INSERT INTO pending_transfers VALUES (?, ?, ?, ?, ?)", (code, time.time(), from_, to, amount))
    db.commit()
    db.close()

    to_num = vbts_credit._number_from_name(to)
    response = conf["reply_with_code"] % (str(code), str(amount), str(to_num))
    return True, response
Ejemplo n.º 4
0
def process_transfer(from_, to, amount):
    from_balance = vbts_credit.get(from_)
    consoleLog('info', "KURTIS|" + str(from_) + ":" + str(from_balance) + "\n")
    if not from_balance or from_balance < amount:
        return False, conf['no_credit']
    if not to or vbts_credit.get(
            to) == None:  # could be 0! Need to check if doesn't exist.
        return False, conf["wrong_number"]

    # add the pending transfer
    code = ''
    for r in range(code_length):
        code += str(random.randint(0, 9))
    db = sqlite3.connect(pending_db)
    db.execute("INSERT INTO pending_transfers VALUES (?, ?, ?, ?, ?)",
               (code, time.time(), from_, to, amount))
    db.commit()
    db.close()

    to_num = vbts_credit._number_from_name(to)
    response = conf["reply_with_code"] % (str(code), str(amount), str(to_num))
    return True, response
Ejemplo n.º 5
0
def _send_to_freeswitch(to, body):
    to = vbts_credit._number_from_name(to)
    if to:
        fsm.send_smqueue_sms("", str(to), str(app_number), str(body), False)
        return True  # TODO return something more sensible
    return False
def _send_to_freeswitch(to, body):
    to = vbts_credit._number_from_name(to)
    if to:
        fsm.send_smqueue_sms("", str(to), str(app_number), str(body), False)
        return True # TODO return something more sensible
    return False