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")
|
bp = Blueprint("payment", __name__, url_prefix="/payment")
|
||||||
|
|
||||||
def validate_dollars():
|
def validate_dollars(min: float, max: float):
|
||||||
errors = list()
|
errors = list()
|
||||||
dollars = None
|
dollars = None
|
||||||
if "dollars" not in request.form:
|
if "dollars" not in request.form:
|
||||||
@ -37,10 +37,12 @@ def validate_dollars():
|
|||||||
except:
|
except:
|
||||||
errors.append("dollars must be a number")
|
errors.append("dollars must be a number")
|
||||||
|
|
||||||
if dollars and dollars < decimal.Decimal(1):
|
minAsDecimal = decimal.Decimal(min)
|
||||||
errors.append("dollars must be >= 1")
|
maxAsDecimal = decimal.Decimal(max)
|
||||||
elif dollars and dollars >= decimal.Decimal(1000000):
|
if dollars and dollars < minAsDecimal:
|
||||||
errors.append("dollars must be < 1,000,000")
|
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]
|
return [errors, dollars]
|
||||||
|
|
||||||
@ -54,7 +56,7 @@ 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":
|
||||||
result = validate_dollars()
|
result = validate_dollars(0.01, 1000)
|
||||||
errors = result[0]
|
errors = result[0]
|
||||||
dollars = result[1]
|
dollars = result[1]
|
||||||
|
|
||||||
@ -148,7 +150,7 @@ def stripe_payment():
|
|||||||
errors = list()
|
errors = list()
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
result = validate_dollars()
|
result = validate_dollars(0.5, 1000000)
|
||||||
errors = result[0]
|
errors = result[0]
|
||||||
dollars = result[1]
|
dollars = result[1]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user