validate_dollars to support different values for stripe vs btcpay
This commit is contained in:
parent
59ec894f17
commit
db4797c044
@ -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]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user