コード例 #1
0
def sendMoney(user_pin, receipientPhoneNumber, amount):
    connection = dbConnector()
    cursor = connection.cursor()
    sender_balance = sender_account_balance(user_pin)
    if (amount > sender_balance):
        print("You have Insufficient Balance,Please top up :")
        exit()

    elif (sender_balance >= amount):
        receiver_balance = receiver_account_balance(receipientPhoneNumber)
        transaction_fee = 0.01 * amount
        amount_to_send = amount
        new_sender_balance = sender_balance - transaction_fee - amount_to_send
        new_receiver_balance = receiver_balance + amount_to_send
        sender_id = getSenderID(user_pin)
        sender_name = getSenderName(user_pin)
        receiver_id = getReceiverID(receipientPhoneNumber)
        receiver_name = getReceiverName(receipientPhoneNumber)

        print(
            'Hi {} ,You are about to send {} to {} of phone number {}'.format(
                sender_name, amount_to_send, receiver_name,
                receipientPhoneNumber))
        feedback = int(input('1.Confirm\n2.Cancel\n:'))
        if (feedback == 1):
            #update_sender_balance
            sql = "UPDATE accounts SET accountBalance=%s WHERE customer_id=%s;"
            values = (new_sender_balance, sender_id)
            cursor.execute(sql, values)
            connection.commit()

            print(
                '{} sent to {}, Transaction fee is : {} your new balance is {}'
                .format(amount_to_send, receiver_name, transaction_fee,
                        new_sender_balance))

            #update receiver balance
            sql = "UPDATE accounts SET accountBalance=%s WHERE customer_id=%s;"
            values = (new_receiver_balance, receiver_id)
            cursor.execute(sql, values)
            connection.commit()

            print(
                'Hi {} , you have received {} from {}.\nYour new balance is {}.Thank you'
                .format(receiver_name, amount_to_send, sender_name,
                        new_receiver_balance))

        elif (feedback == 2):
            print('Transaction Canceled.')
            exit()

        else:
            print('Invalid Input')
    else:
        print('Invalid Input')
        exit()
コード例 #2
0
def getReceiverName(receipientPhoneNumber):
    connection = dbConnector()
    cursor = connection.cursor()
    myquery = "select * from customers where mobileNumber=%s;"
    phoneNum = (receipientPhoneNumber,)
    cursor.execute(myquery,phoneNum)
    receiver_data = cursor.fetchone()
    
    #grab sender name,id and phone
    receiver_name = receiver_data[0]
    return receiver_name
コード例 #3
0
def add_Currency(currency):
    connection = dbConnector()
    cursor = connection.cursor()

    #insert customers account detail

    sql = "insert into currency(currencyName,currencyCode,customer_id) values (%s,%s,%s);"
    values = (currency.code, currency.currencyname, currency.customer_id)
    cursor.execute(sql, values)
    connection.commit()
    print(cursor.rowcount, "record inserted.")
コード例 #4
0
def getSenderName(user_pin):
    connection = dbConnector()
    cursor = connection.cursor()
    myquery = "select * from customers where pin=%s;"
    pin = (user_pin,)
    cursor.execute(myquery,pin)
    phone_pin_data = cursor.fetchone()
    
    #grab sender name,id and phone
    sender_name = phone_pin_data[0]
    return sender_name
コード例 #5
0
def add_Account(account):
    connection = dbConnector()
    cursor = connection.cursor()

    #insert customers account detail

    sql = "insert into accounts(accountName,accountNumber,accountType,accountBalance,customer_id) values (%s,%s,%s,%s,%s);"
    values = (account.accountName, account.accountNumber, account.accountType,
              account.accountBalance, account.customer_id)
    cursor.execute(sql, values)
    connection.commit()
    print(cursor.rowcount, "record inserted.")
コード例 #6
0
def fetch_CusomerId(customer):
    connection = dbConnector()
    cursor = connection.cursor()

    #grab automatically generated customer id

    myquery = "select * from customers where idNumber=%s;"
    customer_idNumber = (customer.idNumber, )
    cursor.execute(myquery, customer_idNumber)
    inserted_id = cursor.fetchone()
    customer_id = inserted_id[5]
    return customer_id
コード例 #7
0
def add_customer(customer):
    connection = dbConnector()
    cursor = connection.cursor()

    #insert customers details

    sql = "insert into customers(customerName,idNumber,uniqueID,mobileNumber,pin) values (%s,%s,%s,%s,%s);"
    values = (customer.name, customer.idNumber, customer.uniqueID,
              customer.mobileNo, customer.Pin)
    cursor.execute(sql, values)

    connection.commit()

    print(cursor.rowcount, "record inserted.")
コード例 #8
0
def ValidateRecipientPhoneNumber(receipientPhoneNumber):
    connection = dbConnector()
    cursor = connection.cursor()
    myquery = "SELECT mobileNumber FROM banking_app.customers;"
    cursor.execute(myquery)
    phones = []
    phones_Numcolumn = cursor.fetchall()
    for phone_num_container in phones_Numcolumn:
        for num in phone_num_container:
            phones.append(num)
    if (receipientPhoneNumber in phones):
        pass
    else:
        print('Invalid Phone')
        exit()
コード例 #9
0
def validatePin(user_pin):
    connection = dbConnector()
    cursor = connection.cursor()
    
    #validate pin
    
    myquery = "select pin from customers;"
    cursor.execute(myquery)
    phone_pin_data = cursor.fetchall()
    pins = []
    for row_one_pin in phone_pin_data:
        for one_pin in row_one_pin:
            pins.append(one_pin)
    if user_pin in pins:
        pass
    else:
        print('Invalid Pin')
        exit()
コード例 #10
0
ファイル: checkbalance.py プロジェクト: peterwaf/code_village
def checkBalance(user_pin):
    connection = dbConnector()
    cursor = connection.cursor()

    myquery = "select * from customers where pin=%s;"
    customer_pin = (user_pin, )
    cursor.execute(myquery, customer_pin)
    inserted_pindata = cursor.fetchone()

    #fetch customer id

    customer_id = inserted_pindata[5]

    #fetch account balance from currency

    myquery = "select * from banking_app.accounts where customer_id=%s;"
    thecustomer_id = (customer_id, )
    cursor.execute(myquery, thecustomer_id)
    inserted_accountsdata = cursor.fetchone()
    account_balance = inserted_accountsdata[3]
    print('Account balance :', account_balance)
コード例 #11
0
def validatePin_Phone(user_pin,phone_number):
    connection = dbConnector()
    cursor = connection.cursor()
    
    #validate pin
    
    myquery = "select * from customers where pin=%s;"
    pin = (user_pin,)
    cursor.execute(myquery,pin)
    phone_pin_datas = []
    phone_pin_data = cursor.fetchone()
    for num in phone_pin_data:
        phone_pin_datas.append(num)
            
    #validate phone number & pin
    
    if str(phone_number) in phone_pin_datas and user_pin in phone_pin_datas:
        print('Confirmed')
        checkBalance(user_pin)
    else:
        print('Incorrect Phone Number and or Pin')
        exit()
コード例 #12
0
def getReceiverID(receipientPhoneNumber):
    connection = dbConnector()
    cursor = connection.cursor()
    myquery = "select * from customers where mobileNumber=%s;"
    phonenum = (receipientPhoneNumber,)
    cursor.execute(myquery,phonenum)
    phone_num_data = cursor.fetchone()
    #grab sender name,id and phone
    receiver_id = phone_num_data[5]
    return receiver_id


#getReceiverID(254785698741)
#sender_account_balance(7878)
#receiver_account_balance(254785698741) 
#ValidateRecipientPhoneNumber(2547856987418)



    
    
    
コード例 #13
0
def receiver_account_balance(receipientPhoneNumber):
    connection = dbConnector()
    cursor = connection.cursor()
    myquery = "select * from customers where mobileNumber=%s;"
    phonenum = (receipientPhoneNumber,)
    cursor.execute(myquery,phonenum)
    phone_num_data = cursor.fetchone()
    
    #grab sender name,id and phone
    
    receiver_name = phone_num_data[0]
    receiver_id = phone_num_data[5]
    receiver_phone = phone_num_data[4]
    
    #grab sender account info
    
    myquery = "select * from accounts where customer_id=%s;"
    customer_id = (receiver_id,)
    cursor.execute(myquery,customer_id)
    accounts_data = cursor.fetchone()
    
    #accounts balance 
    account_bal = accounts_data[3]
    return account_bal
コード例 #14
0
def sender_account_balance(user_pin):
    connection = dbConnector()
    cursor = connection.cursor()
    myquery = "select * from customers where pin=%s;"
    pin = (user_pin,)
    cursor.execute(myquery,pin)
    phone_pin_data = cursor.fetchone()
    
    #grab sender name,id and phone
    
    sender_name = phone_pin_data[0]
    sender_id = phone_pin_data[5]
    sender_phone = phone_pin_data[4]
    
    #grab sender account info
    
    myquery = "select * from accounts where customer_id=%s;"
    customer_id = (sender_id,)
    cursor.execute(myquery,customer_id)
    accounts_data = cursor.fetchone()
    
    #accounts balance 
    account_bal = accounts_data[3]
    return account_bal