From 79742278c57a9973e4aa7bdf12c8e1c37d7e1524 Mon Sep 17 00:00:00 2001 From: forest Date: Tue, 14 Dec 2021 01:41:35 -0600 Subject: [PATCH] cleaning up validate_dollars --- capsulflask/payment.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/capsulflask/payment.py b/capsulflask/payment.py index 99be869..d621827 100644 --- a/capsulflask/payment.py +++ b/capsulflask/payment.py @@ -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: