diff --git a/c3l_membership/__init__.py b/c3l_membership/__init__.py --- a/c3l_membership/__init__.py +++ b/c3l_membership/__init__.py @@ -36,23 +36,7 @@ def create_app(): app.config.setdefault("REGULAR_FEE", 120) app.config.setdefault("DIGICASH_ENABLED", True) - app.config.setdefault("BITCOIN_ENABLED", True) - app.config.setdefault("ETHEREUM_ENABLED", True) - app.config.setdefault("MONERO_ENABLED", True) - app.config.setdefault("ZCASH_ENABLED", True) - - app.config.setdefault( - "BITCOIN_CONVERSION_SCRIPT", "/usr/local/share/btc/BTC_Membership.pl" - ) - app.config.setdefault( - "ETHEREUM_CONVERSION_SCRIPT", "/usr/local/share/eth/ETH_Membership.pl" - ) - app.config.setdefault( - "MONERO_CONVERSION_SCRIPT", "/usr/local/share/xmr/XMR_Membership.pl" - ) - app.config.setdefault( - "ZCASH_CONVERSION_SCRIPT", "/usr/local/share/zcash/ZCASH_Membership.pl" - ) + app.config.setdefault("CRYPTOCURRENCIES", dict()) @babel.localeselector def get_locale(): diff --git a/c3l_membership/templates/member.html b/c3l_membership/templates/member.html --- a/c3l_membership/templates/member.html +++ b/c3l_membership/templates/member.html @@ -87,57 +87,18 @@ {% elif form.payment.data == 'cash' %}

{% trans %}Please bring {{ price }}€ with you the next time you meet us!{% endtrans %}

- {% elif form.payment.data == 'bitcoin' %} -
-
- -
- {% set bitcoin_url="bitcoin:" + config["BITCOIN_ADDRESS"] + "?amount={amount}&label=Membership Fee {year} {username}&message=Membership Fee {year} {username}".format(amount=price, year=year, username=form.username.data) %} -
-
- {% elif form.payment.data == 'ethereum' %} + {% elif form.payment.data in config["CRYPTOCURRENCIES"] %}
-
- {% set ethereum_url=config["ETHEREUM_ADDRESS"] %} -
-
- {% elif form.payment.data == 'monero' %} -
-
-
- {% set monero_url=config["MONERO_ADDRESS"] %} -
-
- {% elif form.payment.data == 'zcash' %} -
-
- -
- {% set zcash_url=config["ZCASH_ADDRESS"] %} -
+ {% set crypto_url={{ config["CRYPTOCURRENCIES"][form.payment.data]["URL"] }}.format(amount=price, year=year, username=form.username.data) %} +
{% elif form.payment.data == 'digicash' %}
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