taler-merchant-demos

Python-based Frontends for the Demonstration Web site
Log | Files | Refs | Submodules | README | LICENSE

commit 2ed2988c53dc2582f71ca9e9aa1e5f60b1623477
parent 4c379a2572366ca0c74dc647d83a8b164a116473
Author: Florian Dold <florian@dold.me>
Date:   Mon,  3 Nov 2025 12:56:53 +0100

feature-flag subscription tokens

Diffstat:
Mtalermerchantdemos/blog/blog.py | 73+++++++++++++++++++++++++++++++++++++++++++------------------------------
1 file changed, 43 insertions(+), 30 deletions(-)

diff --git a/talermerchantdemos/blog/blog.py b/talermerchantdemos/blog/blog.py @@ -67,6 +67,11 @@ ARTICLE_AMOUNT = CURRENCY + ":0.5" BACKEND_URL = config["frontend-demo-blog"]["backend_url"].value_string(required=True) APIKEY = config["frontend-demo-blog"]["backend_apikey"].value_string(required=True) +conf_tokens = config["frontend-demo-blog"]["enable_tokens"].value_string(default="NO") +ENABLE_TOKENS = "yes" == config["frontend-demo-blog"]["enable_tokens"].value_string( + default="NO" +) + SUBSCRIPTION_AMOUNT = CURRENCY + ":10" SUBSCRIPTION_SLUG_PREFIX = "blog_abo_" @@ -317,47 +322,55 @@ def render_article(article_name, lang, data, order_id, refundable): def post_order(article_name, article_url, session_id, lang): article_info = ARTICLES[lang].get(article_name) summary = f"Essay: {article_info.title}" - order = { - "version": 1, - "extra": { "article_name": article_name }, - "fulfillment_url": article_url, - "public_reorder_url": article_url, - "summary": summary, - "session_id": session_id, - "choices": [ - # regular price - { - "amount": ARTICLE_AMOUNT, - "description": "Buy an individual article", - }, - + choices = [ + # regular price + { + "amount": ARTICLE_AMOUNT, + "description": "Buy an individual article", + }, + ] + if ENABLE_TOKENS: + tok_choices = [ # buy monthly abo { "amount": SUBSCRIPTION_AMOUNT, "description": "Buy one month of unlimited access", - "outputs": [{ - "type": "token", - "token_family_slug": SUBSCRIPTION_SLUG_PREFIX + lang, - }], + "outputs": [ + { + "type": "token", + "token_family_slug": SUBSCRIPTION_SLUG_PREFIX + lang, + } + ], }, - # access with monthly abo { "amount": CURRENCY + ":0", - "inputs": [{ - "type": "token", - "token_family_slug": SUBSCRIPTION_SLUG_PREFIX + lang, - }], - "outputs": [{ - "type": "token", - "token_family_slug": SUBSCRIPTION_SLUG_PREFIX + lang, - }], + "inputs": [ + { + "type": "token", + "token_family_slug": SUBSCRIPTION_SLUG_PREFIX + lang, + } + ], + "outputs": [ + { + "type": "token", + "token_family_slug": SUBSCRIPTION_SLUG_PREFIX + lang, + } + ], }, - ], - + ] + choices.extend(tok_choices) + order = { + "version": 1, + "extra": {"article_name": article_name}, + "fulfillment_url": article_url, + "public_reorder_url": article_url, + "summary": summary, + "session_id": session_id, + "choices": choices, # FIXME: add support for i18n of summary! # 10 minutes time for a refund - "wire_transfer_deadline": { "t_s": int(time.time() + 15 * 30) }, + "wire_transfer_deadline": {"t_s": int(time.time() + 15 * 30)}, } order_resp = backend_post( BACKEND_URL,