Example #1
0
    def post(self):
        postedData = request.get_json()
        username = postedData["username"]
        password = postedData["password"]
        money = postedData["amount"]
        phone = postedData["fromPhone"]
        network = getNetworkName(phone)

        retJson, error = verifyCredentials(phone, password)
        if error:
            return jsonify(retJson)

        cash = cashWithUser(phone)
        debt = debtWithUser(phone)
        # update accounts
        updateAccount(phone, round(float(cash + money), 2))
        updateDebt(phone, round(float(debt + money), 2))

        # Insert data into take loan Collection
        mongo.db.Takeloan.insert_one({
            "Username": username,
            "Loan_Amount": round(float(money), 2),
            "Network": network,
            "Phone": phone,
            "TransactionID": transaction_id(),
            "DateTime": date_time()
        })
        return jsonify(
            generateReturnDictionary(
                200, "Loan Amount Added to Your Account Successfully",
                "SUCCESS"))
Example #2
0
def signup():
    '''User Registeration'''
    form = RegisterForm(request.form)
    if request.method == 'POST' and form.validate():
        # fields
        firstname = form.firstname.data
        lastname = form.lastname.data
        email = form.email.data
        phone = form.phone.data
        username = form.username.data
        password = form.password.data
        network = getNetworkName(phone)

        # check if phone/username number exist
        if not UserExist(phone):
            # return jsonify(generateReturnDictionary(301, 'Phone number already Exist', "FAILURE"))
            error = 'Phone number already Exists'
            return render_template('login.html', error=error)
        if not UserExist(username):
            return jsonify(
                generateReturnDictionary(301, 'Username already Exist',
                                         "FAILURE"))

        reg = mongo.db.Register
        existing_user = reg.find_one({"Phone": phone})
        if existing_user is None:
            # hash password
            hashed_pw = sha256_crypt.hash(password)
            # insert into db
            userReg = UsersRegisteration(firstname,
                                         lastname,
                                         email,
                                         phone,
                                         network,
                                         username,
                                         hashed_pw,
                                         balance=0.0,
                                         debt=0.0)
            reg.insert_one({
                "FirstName": userReg.firstname,
                "LastName": userReg.lastname,
                "Email": userReg.email,
                "Phone": userReg.phone,
                "Network": userReg.network,
                "Username": userReg.username,
                "Password": userReg.password,
                "Balance": userReg.balance,
                "Debt": userReg.debt,
                "DateTimeCreated": date_time(),
                "apiKeys": generateApiKeys()
            })

        flash(
            'You successfully signed up for the mobile money wallet, you can now log-in',
            'success')
        return redirect(url_for('login'))
    return render_template('signup.html', form=form)
Example #3
0
    def post(self):
        postedData = request.get_json()
        username = postedData["username"]
        password = postedData["password"]
        money = postedData["amount"]
        phone = postedData["fromPhone"]
        network = getNetworkName(phone)

        retJson, error = verifyCredentials(phone, password)
        if error:
            return jsonify(retJson)

        cash = cashWithUser(phone)
        debt = debtWithUser(phone)

        if cash < money:
            return jsonify(
                generateReturnDictionary(303,
                                         "Not enough cash in your account",
                                         "FAILURE"))
        elif money > debt:
            return jsonify(
                generateReturnDictionary(303, "You can't overpay your loan",
                                         "FAILURE"))
        elif debt < float(0):
            return jsonify(
                generateReturnDictionary(303, "Your debt is in negative",
                                         "FAILURE"))

        # update accounts
        updateAccount(phone, round(float(cash - money), 2))
        updateDebt(phone, round(float(debt - money), 2))

        # Insert data into payloan Collection
        mongo.db.Payloan.insert_one({
            "Username": username,
            "AmountPaid": round(float(money), 2),
            "Network": network,
            "Phone": phone,
            "TransactionID": transaction_id(),
            "DateTime": date_time()
        })
        return jsonify(
            generateReturnDictionary(200, "Loan Amount Paid Successfully",
                                     "SUCCESS"))
Example #4
0
    def post(self):
        postedData = request.get_json()
        username = postedData["username"]
        password = postedData["password"]
        money = postedData["amount"]
        phone = postedData["fromPhone"]
        network = getNetworkName(phone)

        retJson, error = verifyCredentials(phone, password)
        if error:
            return jsonify(retJson)

        # Current Balance
        balance = cashWithUser(phone)

        if balance < money:
            return jsonify(
                generateReturnDictionary(303, "Not Enough Cash in your wallet",
                                         "FAILURE"))
        elif money < float(0):
            return jsonify(
                generateReturnDictionary(
                    303, "You cannot withdraw negative amount", "FAILURE"))
        elif balance < float(0):
            return jsonify(
                generateReturnDictionary(
                    303,
                    "Your balance is in negative, please TopUp with some cash",
                    "FAILURE"))

        updateAccount(phone, balance - money)

        # Insert data into Withdrawal Collection
        mongo.db.Withdrawal.insert_one({
            "Username": username,
            "Amount": round(float(money), 2),
            "Network": network,
            "Phone": phone,
            "Transaction_Id": transaction_id(),
            "DateTime": date_time()
        })
        return jsonify(
            generateReturnDictionary(200, "Money Withdrawn from your wallet",
                                     "SUCCESS"))
Example #5
0
    def post(self):
        # get json data
        postedData = request.get_json()
        username = postedData["username"]
        password = postedData["password"]
        money = postedData["amount"]
        phone = postedData["fromPhone"]
        network = getNetworkName(phone)

        retJson, error = verifyCredentials(phone, password)
        if error:
            return jsonify(retJson)

        if money <= float(0):
            return jsonify(
                generateReturnDictionary(
                    304, "The money amount entered must be greater than 0",
                    "FAILURE"))

        cash = cashWithUser(phone)
        # Transaction fee
        fees = transactionFee(money)
        money = round(money - fees, 2)

        # Add transaction fee to bank account
        bank_cash = cashWithUser("0240000000")
        updateAccount("0240000000", round(float(bank_cash + fees), 2))
        # Add remaining money to user account
        updateAccount(phone, round(float(cash + money), 2))

        # Insert data into TopUp Collection
        mongo.db.TopUps.insert_one({
            "Username": username,
            "Amount": round(float(money), 2),
            "Network": network,
            "Phone": phone,
            "TransactionID": transaction_id(),
            "DateTime": date_time()
        })
        return jsonify(
            generateReturnDictionary(200,
                                     "Amount Added Successfully to account",
                                     "SUCCESS"))
Example #6
0
    def post(self):
        # Step 1 is to get posted data by the user
        # postedData = request.get_json()
        # # Get the data
        # firstname = postedData["firstname"]
        # lastname = postedData["lastname"]
        # email = postedData["email"]
        # phone = postedData["fromPhone"]
        # username = postedData["username"]
        # password = postedData["password"]

        args = argParser.parse_args()

        firstname = args.get("firstname")
        lastname = args.get("lastname")
        email = args.get("email")
        phone = args.get("fromPhone")
        username = args.get("username")
        password = args.get("password")
        network = getNetworkName(phone)
        hashed_pw = sha256_crypt.hash(password)

        users = UsersRegisteration(firstname,
                                   lastname,
                                   email,
                                   phone,
                                   username,
                                   hashed_pw,
                                   network,
                                   balance=0.0,
                                   debt=0.0)

        if UserExist(phone):
            return jsonify(
                generateReturnDictionary(400, "Username/Phone Already Exists",
                                         "FAILURE"))

        # Store username,pw, phone, network into the database
        try:
            mongo.db.Register.insert_one({
                "FirstName": users.firstname,
                "LastName": users.lastname,
                "Email": users.email,
                "Phone": users.phone,
                "Network": users.network,
                "Username": users.username,
                "Password": users.hashed_pw,
                "Balance": users.balance,
                "Debt": users.debt,
                "DateCreated": date_time(),
                "DateUpdated": date_time(),
                "apiKeys": generateApiKeys()
            })

            retJson = {
                "code": 201,
                "msg": "You successfully signed up for mobile money wallet",
                "status": "SUCCESS"
            }
            return jsonify(retJson)
        except Exception as e:
            retJson = {
                "code": 409,
                "msg":
                "There was an error while trying to create your account -> , try again!",
                "status": "FAILURE: {0}".format(e.message)
            }
            return jsonify(retJson)
Example #7
0
    def post(self):
        # get json data
        postedData = request.get_json()
        username = postedData["username"]
        password = postedData["password"]
        money = postedData["amount"]
        fromPhone = postedData["fromPhone"]
        toPhone = postedData["toPhone"]
        # extract network name
        fromNetwork = getNetworkName(fromPhone)
        toNetwork = getNetworkName(toPhone)

        # verify sender credentials
        retJson, error = verifyCredentials(fromPhone, password)
        if error:
            return jsonify(retJson)

        # cash = cashWithUser(username)
        cash_from = cashWithUser(fromPhone)
        cash_to = cashWithUser(toPhone)
        bank_cash = cashWithUser("0240000000")

        if cash_from <= float(0):
            return jsonify(
                generateReturnDictionary(
                    303,
                    "You are out of money, Please Topup some Cash or take a loan",
                    "FAILURE"))
        elif money <= float(1):
            return jsonify(
                generateReturnDictionary(
                    304, "The amount entered must be greater than GHS 1.00",
                    "FAILURE"))

        if not UserExist(toPhone):
            return jsonify(
                generateReturnDictionary(301,
                                         "Received username/phone is invalid",
                                         "FAILURE"))

        fees = transactionFee(money)
        money_after = round(money - fees, 2)
        try:
            updateAccount("0240000000", round(float(bank_cash + fees),
                                              2))  # add fees to bank
            updateAccount(toPhone, round(float(cash_to + money_after),
                                         2))  # add to receiving account
            updateAccount(fromPhone,
                          round(float(cash_from - money_after),
                                2))  # deduct money from sending account
        except ValueError as err:
            print("Update to DB was not successful : {}" + err)

        # save to transfer collection
        mongo.db.Transfer.insert_one({
            "Username":
            username,
            "AmountBeforeFees":
            round(float(money), 2),
            "AmountAfterFees":
            round(float(money_after), 2),
            "FromPhone":
            fromPhone,
            "ToPhone":
            toPhone,
            "ToNetwork":
            toNetwork,
            "FromNetwork":
            fromNetwork,
            "TransactionID":
            transaction_id(),
            "DateTime":
            date_time()
        })
        return jsonify(
            generateReturnDictionary(200,
                                     "Amount added successfully to account",
                                     "SUCCESS"))