From db4797c044f7870f4419816ff3975c49e7c3145e Mon Sep 17 00:00:00 2001 From: forest Date: Tue, 14 Dec 2021 01:27:25 -0600 Subject: [PATCH] validate_dollars to support different values for stripe vs btcpay --- capsulflask/payment.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/capsulflask/payment.py b/capsulflask/payment.py index 8e10b61..09d3191 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(): +def validate_dollars(min: float, max: float): errors = list() dollars = None if "dollars" not in request.form: @@ -37,10 +37,12 @@ def validate_dollars(): except: errors.append("dollars must be a number") - if dollars and dollars < decimal.Decimal(1): - errors.append("dollars must be >= 1") - elif dollars and dollars >= decimal.Decimal(1000000): - errors.append("dollars must be < 1,000,000") + minAsDecimal = decimal.Decimal(min) + maxAsDecimal = decimal.Decimal(max) + 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)}") return [errors, dollars] @@ -54,7 +56,7 @@ def btcpay_payment(): return redirect(url_for("console.account_balance")) if request.method == "POST": - result = validate_dollars() + result = validate_dollars(0.01, 1000) errors = result[0] dollars = result[1] @@ -148,7 +150,7 @@ def stripe_payment(): errors = list() if request.method == "POST": - result = validate_dollars() + result = validate_dollars(0.5, 1000000) errors = result[0] dollars = result[1]