示例#1
0
    def get(cls):
        """
        Checks whether wallet exists or not. If it exists Then checks whether Kyc is True or not.
        :param : data is received in the form of payload like {"mobile_number": "value"}
        :return: encrypted response
            if there is some error in finding wallet or kyc not done then return {"message": "encrypted message"}
            else return wallet data like {"amount": "encrypted value",
                                          "kyc": "Encrypted value",
                                          "mobile_number": "Encrypted Value"
                                          }
        """
        data = request.get_json()
        data = Decryption.decrypt(request.get_json())
        mobile_number = data["mobile_number"]
        wallet = WalletModel.find_by_mobile_number(mobile_number)
        if wallet is None:
            return Encryption.encrypt(
                {"message":
                 gettext("WALLET_NOT_FOUND").format(mobile_number)}), 404

        if not wallet.kyc_status:
            return Encryption.encrypt(
                {"message":
                 gettext("KYC_NOT_DONE").format(mobile_number)}), 404

        return Encryption.encrypt(wallet_schema.dump(wallet)), 200
示例#2
0
    def post(cls):
        # data is received in the form like {"mobile_number = "*****", "amount" = "***"}
        data = request.get_json()
        wallet = WalletModel.find_by_mobile_number(data["mobile_number"])
        if wallet is None:
            wallet = WalletModel()
            return {
                "message":
                gettext("WALLET_NOT_FOUND").format(data["mobile_number"])
            }, 400

        if not wallet.kyc_status:
            return {
                "message":
                gettext("KYC_NOT_DONE").format(data["mobile_number"])
            }, 400

        if wallet.amount < data["amount"]:
            return {
                "message":
                gettext("NOT_ENOUGH_BALANCE").format(data["mobile_number"])
            }, 400

        wallet.reduce_amount(data["amount"])
        return {"message": gettext("PAYMENT_SUCCESSFUL")}, 200
示例#3
0
    def put(cls):
        """
        payload = {"mobile_number = "*****", "amount" = "***"}
        :return:
        """
        data = request.get_json()
        # data = Decyption.decrypt(request.get_json())
        wallet = WalletModel.find_by_mobile_number(data["mobile_number"])
        if wallet is None:
            return Encryption.encrypt({
                "message":
                gettext("WALLET_NOT_FOUND").format(data["mobile_number"])
            }), 404

        if not wallet.kyc_status:
            return Encryption.encrypt({
                "message":
                gettext("KYC_NOT_DONE").format(data["mobile_number"])
            }), 404

        if wallet.amount < data["amount"]:
            return Encryption.encrypt({
                "message":
                gettext("NOT_ENOUGH_BALANCE").format(data["mobile_number"])
            }), 404

        wallet.reduce_amount(float(data["amount"]))
        try:
            wallet.save_to_db()
        except:
            return Encryption.encrypt(
                {"message": gettext("ERROR_IN_SENDING_MONEY")}), 500
        return Encryption.encrypt({"message":
                                   gettext("PAYMENT_SUCCESSFUL")}), 200
示例#4
0
    def get(cls):
        data = request.get_json()
        wallet = WalletModel.find_by_mobile_number(data["mobile_number"])
        if wallet is None:
            return {
                "message": gettext("WALLET_NOT_FOUND").format(mobile_number)
            }, 400

        if not wallet.kyc_status:
            return {
                "message": gettext("KYC_NOT_DONE").format(mobile_number)
            }, 400

        return wallet_schema.dump(wallet), 200
示例#5
0
 def put(cls):
     data = request.get_json()
     wallet = WalletModel.find_by_mobile_number(data["mobile_number"])
     if wallet:
         wallet.add_amount(data["amount"])
     else:
         wallet = wallet_schema.load(data)
     try:
         wallet.save_to_db()
     except:
         return {
             "message":
             gettext("ERROR_IN_SAVING_WALLET").format(data["mobile_number"])
         }, 500
     return wallet_schema.dump(wallet), 200
示例#6
0
 def put(cls):
     data = request.get_json()
     # data = Decyption.decrypt(request.get_json())
     wallet = WalletModel.find_by_mobile_number(data["mobile_number"])
     if wallet is None:
         return Encryption.encrypt({
             "message":
             gettext("WALLET_NOT_FOUND").format(data[mobile_number])
         }), 400
     try:
         wallet.add_amount(float(data["amount"]))
         wallet.save_to_db()
     except:
         return Encryption.encrypt(
             {"message": gettext("ERROR_IN_ADDING_MONEY")}), 500
     return Encryption.encrypt(
         {"message": gettext("MONEY_ADDED_SUCCESSFULLY")}), 200
示例#7
0
    def get(cls):
        """
        Checks whether wallet exists or not. If it exists Then checks whether Kyc is done or not.
        :param mobile_number:
        :return:
        """
        data = request.get_json()
        # data = Decyption.decrypt(request.get_json())
        mobile_number = data["mobile_number"]
        wallet = WalletModel.find_by_mobile_number(mobile_number)
        if wallet is None:
            return Encryption.encrypt(
                {"message":
                 gettext("WALLET_NOT_FOUND").format(mobile_number)}), 404

        if not wallet.kyc_status:
            return Encryption.encrypt(
                {"message":
                 gettext("KYC_NOT_DONE").format(mobile_number)}), 404

        return Encryption.encrypt(wallet_schema.dump(wallet)), 200
示例#8
0
 def put(cls):
     """
         This method is used mainly during rollback to add amount back in the wallet if the transaction fails.
         payload = {"mobile_number": "********", "amount":13131}
         returns a encrypted message.
     """
     data = request.get_json()
     data = Decryption.decrypt(request.get_json())
     wallet = WalletModel.find_by_mobile_number(data["mobile_number"])
     if wallet is None:
         return Encryption.encrypt({
             "message":
             gettext("WALLET_NOT_FOUND").format(data["mobile_number"])
         }), 400
     try:
         wallet.add_amount(data["amount"])
         wallet.save_to_db()
     except:
         return Encryption.encrypt(
             {"message": gettext("ERROR_IN_ADDING_MONEY")}), 500
     return Encryption.encrypt(
         {"message": gettext("MONEY_ADDED_SUCCESSFULLY")}), 200
示例#9
0
    def put(cls):
        """
        This method is mainly used for checking whether enough money is present in the wallet during payment or not.
        If enough amount exists then it reduces the amount for that person in the database
        and return encrypted message.
        payload = {"mobile_number = "*****", "amount" = "***"}
        :return: {"message": "Encrypted message"}
        """
        data = request.get_json()
        data = Decryption.decrypt(request.get_json())
        wallet = WalletModel.find_by_mobile_number(data["mobile_number"])
        if wallet is None:
            return Encryption.encrypt({
                "message":
                gettext("WALLET_NOT_FOUND").format(data["mobile_number"])
            }), 404

        if not wallet.kyc_status:
            return Encryption.encrypt({
                "message":
                gettext("KYC_NOT_DONE").format(data["mobile_number"])
            }), 404

        if wallet.amount < data["amount"]:
            return Encryption.encrypt({
                "message":
                gettext("NOT_ENOUGH_BALANCE").format(data["mobile_number"])
            }), 404

        wallet.reduce_amount(data["amount"])
        try:
            wallet.save_to_db()
        except:
            return Encryption.encrypt(
                {"message": gettext("ERROR_IN_SENDING_MONEY")}), 500
        return Encryption.encrypt({"message":
                                   gettext("PAYMENT_SUCCESSFUL")}), 200
示例#10
0
 def post(cls):
     """
     This endpoint is mainly for Testing purposes...
     payload = {"mobile_number = "*****", "amount" = 8090 , "kyc_status" : true/false}
     """
     data = request.get_json()
     # data = Decyption.decrypt(request.get_json())
     wallet = WalletModel.find_by_mobile_number(data["mobile_number"])
     if wallet:
         return {
             "message":
             gettext("WALLET_EXIST").format(data["mobile_number"])
         }, 400
     else:
         data["amount"] = float(data["amount"])
         wallet = wallet_schema.load(data)
     try:
         wallet.save_to_db()
     except:
         return {
             "message":
             gettext("ERROR_IN_SAVING_WALLET").format(data["mobile_number"])
         }, 500
     return wallet_schema.dump(wallet), 201