cleaning up validate_dollars

This commit is contained in:
forest 2021-12-14 01:41:35 -06:00
parent f5d70c0b88
commit 79742278c5
1 changed files with 9 additions and 12 deletions

View File

@ -25,7 +25,7 @@ from capsulflask.shared import my_exec_info_message
bp = Blueprint("payment", __name__, url_prefix="/payment")
def validate_dollars(min: float, max: float):
def validate_dollars(min: decimal.Decimal, max: decimal.Decimal):
errors = list()
dollars = None
if "dollars" not in request.form:
@ -36,16 +36,13 @@ def validate_dollars(min: float, max: float):
dollars = decimal.Decimal(request.form["dollars"])
except:
errors.append("dollars must be a number")
minAsDecimal = decimal.Decimal(min)
maxAsDecimal = decimal.Decimal(max)
current_app.logger.info(f"{str(dollars)} {str(minAsDecimal)} {str(dollars < minAsDecimal)}")
#current_app.logger.info(f"{str(dollars)} {str(min)} {str(dollars < min)}")
if dollars and dollars < minAsDecimal:
errors.append(f"dollars must be {str(minAsDecimal)} or more")
elif dollars and dollars >= maxAsDecimal:
errors.append(f"dollars must be less than {str(maxAsDecimal)}")
if dollars and dollars < min:
errors.append(f"dollars must be {format(min, ".2f")} or more")
elif dollars and dollars >= max:
errors.append(f"dollars must be less than {format(max, ".2f")}")
current_app.logger.info(f"{len(errors)} {errors}")
return [dollars, errors]
@ -60,8 +57,8 @@ def btcpay_payment():
return redirect(url_for("console.account_balance"))
if request.method == "POST":
dollars, errors = validate_dollars(0.01, 1000)
current_app.logger.info(f"{len(errors)} {errors}")
dollars, errors = validate_dollars(decimal.Decimal(0.01), decimal.Decimal(1000))
#current_app.logger.info(f"{len(errors)} {errors}")
if len(errors) == 0:
try:
@ -153,7 +150,7 @@ def stripe_payment():
errors = list()
if request.method == "POST":
dollars, errors = validate_dollars(0.5, 1000000)
dollars, errors = validate_dollars(decimal.Decimal(0.5), decimal.Decimal(1000000))
if len(errors) == 0: