diff --git a/c3l_membership/views.py b/c3l_membership/views.py --- a/c3l_membership/views.py +++ b/c3l_membership/views.py @@ -34,15 +34,18 @@ def index(): ("wire transfer", gettext("by wire transfer")), ] - for k, v in ( - ("DIGICASH_ENABLED", ("digicash", gettext("by DigiCash"))), - ("BITCOIN_ENABLED", ("bitcoin", gettext("by bitcoin"))), - ("ETHEREUM_ENABLED", ("ethereum", gettext("by ethereum"))), - ("MONERO_ENABLED", ("monero", gettext("by monero"))), - ("ZCASH_ENABLED", ("zcash", gettext("by zcash"))), - ): - if current_app.config[k]: - choices.append(v) + if current_app.config["DIGICASH_ENABLED"]: + choices.append(("digicash", gettext("by DigiCash"))) + + for cryptocurrency_label, options in current_app.config["CRYPTOCURRENCIES"].items(): + if options["ENABLED"]: + choices.append( + ( + cryptocurrency_label, + " ".format((gettext("by"), options)), + ), + ) + form.payment.choices = choices if form.validate_on_submit(): @@ -87,22 +90,16 @@ def index(): ) xml_data["address"] = re.sub("\s+", " ", xml_data["address"]) - if form.payment.data == "bitcoin": - price = subprocess.check_output( - [current_app.config["BITCOIN_CONVERSION_SCRIPT"], str(price)] - ).decode("utf-8") - elif form.payment.data == "ethereum": - price = subprocess.check_output( - [current_app.config["ETHEREUM_CONVERSION_SCRIPT"], str(price)] - ).decode("utf-8") - elif form.payment.data == "monero": - price = subprocess.check_output( - [current_app.config["MONERO_CONVERSION_SCRIPT"], str(price)] - ).decode("utf-8") - elif form.payment.data == "zcash": - price = subprocess.check_output( - [current_app.config["ZCASH_CONVERSION_SCRIPT"], str(price)] - ).decode("utf-8") + if form.payment.data in current_app.config["CRYPTOCURRENCIES"]: + price = subprocess.run( + [ + current_app.config["CRYPTOCURRENCIES_CONVERSION_SCRIPT"], + str(price), + form.payment.data, + ], + capture_output=True, + encoding="utf-8", + ).stdout elif form.payment.data == "digicash": price = price * 100