cleaning up validate_dollars
This commit is contained in:
parent
f5d70c0b88
commit
79742278c5
@ -25,7 +25,7 @@ from capsulflask.shared import my_exec_info_message
|
|||||||
|
|
||||||
bp = Blueprint("payment", __name__, url_prefix="/payment")
|
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()
|
errors = list()
|
||||||
dollars = None
|
dollars = None
|
||||||
if "dollars" not in request.form:
|
if "dollars" not in request.form:
|
||||||
@ -37,15 +37,12 @@ def validate_dollars(min: float, max: float):
|
|||||||
except:
|
except:
|
||||||
errors.append("dollars must be a number")
|
errors.append("dollars must be a number")
|
||||||
|
|
||||||
minAsDecimal = decimal.Decimal(min)
|
#current_app.logger.info(f"{str(dollars)} {str(min)} {str(dollars < min)}")
|
||||||
maxAsDecimal = decimal.Decimal(max)
|
|
||||||
|
|
||||||
current_app.logger.info(f"{str(dollars)} {str(minAsDecimal)} {str(dollars < minAsDecimal)}")
|
if dollars and dollars < min:
|
||||||
|
errors.append(f"dollars must be {format(min, ".2f")} or more")
|
||||||
if dollars and dollars < minAsDecimal:
|
elif dollars and dollars >= max:
|
||||||
errors.append(f"dollars must be {str(minAsDecimal)} or more")
|
errors.append(f"dollars must be less than {format(max, ".2f")}")
|
||||||
elif dollars and dollars >= maxAsDecimal:
|
|
||||||
errors.append(f"dollars must be less than {str(maxAsDecimal)}")
|
|
||||||
|
|
||||||
current_app.logger.info(f"{len(errors)} {errors}")
|
current_app.logger.info(f"{len(errors)} {errors}")
|
||||||
return [dollars, errors]
|
return [dollars, errors]
|
||||||
@ -60,8 +57,8 @@ def btcpay_payment():
|
|||||||
return redirect(url_for("console.account_balance"))
|
return redirect(url_for("console.account_balance"))
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
dollars, errors = validate_dollars(0.01, 1000)
|
dollars, errors = validate_dollars(decimal.Decimal(0.01), decimal.Decimal(1000))
|
||||||
current_app.logger.info(f"{len(errors)} {errors}")
|
#current_app.logger.info(f"{len(errors)} {errors}")
|
||||||
|
|
||||||
if len(errors) == 0:
|
if len(errors) == 0:
|
||||||
try:
|
try:
|
||||||
@ -153,7 +150,7 @@ def stripe_payment():
|
|||||||
errors = list()
|
errors = list()
|
||||||
|
|
||||||
if request.method == "POST":
|
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:
|
if len(errors) == 0:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user