From be22e9351a15306af2d4052d03e01b45a8a4f7ee Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 3 Jan 2018 15:23:08 +0100 Subject: [PATCH] Add invoice generation --- config/template_config.ini | 8 ++++++-- strings.py | 9 +++++++++ worker.py | 11 ++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/config/template_config.ini b/config/template_config.ini index 57bac43..467f40e 100644 --- a/config/template_config.ini +++ b/config/template_config.ini @@ -3,7 +3,7 @@ # Config file parameters [Config] ; Config file version. DO NOT EDIT THIS! -version = 6 +version = 7 ; Set this to no when you are done editing the file is_template = yes @@ -33,4 +33,8 @@ credit_card_token = 123456789:YOUR_TOKEN_HERE_ # Minimum wallet payment accepted min_amount = 10 # Maximum wallet payment accepted -max_amount = 100 \ No newline at end of file +max_amount = 100 +# ISO currency code +currency = EUR +# Currency exp parameter. You can find that on https://core.telegram.org/bots/payments/currencies.json +currency_exp = 2 \ No newline at end of file diff --git a/strings.py b/strings.py index 619b973..5355522 100644 --- a/strings.py +++ b/strings.py @@ -57,6 +57,15 @@ payment_cash = "Puoi pagare in contanti alla sede fisica del negozio.\n" \ # Payment: invoice amount payment_cc_amount = "Quanti fondi vuoi aggiungere al tuo portafoglio?" +# Payment: add funds invoice title +payment_invoice_title = "Aggiunta di fondi" + +# Payment: add funds invoice description +payment_invoice_description = "Pagando questa ricevuta verranno aggiunti {amount} al portafoglio." + +# Payment: label of the labeled price on the invoice +payment_invoice_label = "Ricarica" + # Info: informazioni sul bot bot_info = 'Questo bot utilizza greed,' \ ' un framework di @Steffo per i pagamenti su Telegram rilasciato sotto la' \ diff --git a/worker.py b/worker.py index 9024c22..02bc2b9 100644 --- a/worker.py +++ b/worker.py @@ -210,7 +210,16 @@ class ChatWorker(threading.Thread): self.bot.send_message(self.chat.id, strings.error_payment_amount_under_min.format(min_amount=strings.currency_format_string.format(symbol=strings.currency_symbol, value=configloader.config["Payments"]["min_amount"]))) continue # The amount is valid, send the invoice - print(selection) + self.bot.send_invoice(self.chat.id, + title=strings.payment_invoice_title, + description=strings.payment_invoice_description.format(amount=strings.currency_format_string.format(symbol=strings.currency_symbol, value=selection)), + payload="temppayload", # TODO: change this + provider_token=configloader.config["Payment Methods"]["credit_card_token"], + start_parameter="tempdeeplink", # TODO: change this + currency=configloader.config["Payments"]["currency"], + prices=[telegram.LabeledPrice(label=strings.payment_invoice_label, amount=int(selection * (10 ** int(configloader.config["Payments"]["currency_exp"]))))]) + # TODO: what should happen now? + break def __bot_info(self): """Send information about the bot."""