1
Fork 0
mirror of https://github.com/Steffo99/greed.git synced 2024-11-25 15:24:17 +00:00

Add support for credit card user fees

This commit is contained in:
Steffo 2018-01-15 10:16:04 +01:00
parent c26621223d
commit ad38019afb
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: C27544372FBB445D
4 changed files with 24 additions and 9 deletions

View file

@ -3,7 +3,7 @@
# Config file parameters
[Config]
; Config file version. DO NOT EDIT THIS!
version = 8
version = 9
; Set this to no when you are done editing the file
is_template = yes
@ -37,9 +37,14 @@ credit_card_token = 123456789:YOUR_TOKEN_HERE_
min_amount = 10
# Maximum wallet payment accepted
max_amount = 100
# Require the name of the credit card owner
# Make the user pay a fee when loading the wallet with a credit card
# Credit card fee percentage (set to 0.0 to disable)
fee_percentage = 2.9
# Credit card fee fixed (in miniumum currency units, $1.00 = 100 units) (set to 0 to disable)
fee_fixed = 30
# Require the name of the user
name_required = yes
# Require the email of the credit card owner
# Require the email of the user
email_required = yes
# Require the phone number of the credit card owner
# Require the phone number of the user
phone_required = yes

View file

@ -42,7 +42,7 @@ class User(TableDeclarativeBase):
self.last_name = telegram_chat.last_name
self.username = telegram_chat.username
# The starting wallet value is 0
self.credit = decimal.Decimal("0")
self.credit = 0
def __str__(self):
"""Describe the user in the best way possible given the available data."""

View file

@ -65,6 +65,9 @@ payment_invoice_description = "Pagando questa ricevuta verranno aggiunti {amount
# Payment: label of the labeled price on the invoice
payment_invoice_label = "Ricarica"
# Payment: label of the labeled price on the invoice
payment_invoice_fee_label = "Carta di credito"
# Info: informazioni sul bot
bot_info = 'Questo bot utilizza <a href="https://github.com/Steffo99/greed">greed</a>,' \
' un framework di @Steffo per i pagamenti su Telegram rilasciato sotto la' \

View file

@ -245,6 +245,13 @@ class ChatWorker(threading.Thread):
break
# Set the invoice active invoice payload
self.invoice_payload = str(uuid.uuid4())
# Create the price array
prices = [telegram.LabeledPrice(label=strings.payment_invoice_label, amount=int(selection * (10 ** int(configloader.config["Payments"]["currency_exp"]))))]
# If the user has to pay a fee when using the credit card, add it to the prices list
fee_percentage = Decimal(configloader.config["Credit Card"]["fee_percentage"])
fee_fixed = Decimal(configloader.config["Credit Card"]["fee_fixed"])
total_fee = (selection * fee_percentage + fee_fixed).quantize(Decimal("1.00"))
prices.append(telegram.LabeledPrice(label=strings.payment_invoice_fee_label, amount=int(total_fee)))
# The amount is valid, send the invoice
self.bot.send_invoice(self.chat.id,
title=strings.payment_invoice_title,
@ -253,7 +260,7 @@ class ChatWorker(threading.Thread):
provider_token=configloader.config["Credit Card"]["credit_card_token"],
start_parameter="tempdeeplink", # TODO: no idea on how deeplinks should work
currency=configloader.config["Payments"]["currency"],
prices=[telegram.LabeledPrice(label=strings.payment_invoice_label, amount=int(selection * (10 ** int(configloader.config["Payments"]["currency_exp"]))))],
prices=prices,
need_name=configloader.config["Credit Card"]["name_required"] == "yes",
need_email=configloader.config["Credit Card"]["email_required"] == "yes",
need_phone_number=configloader.config["Credit Card"]["phone_required"] == "yes")
@ -266,7 +273,7 @@ class ChatWorker(threading.Thread):
successfulpayment = self.__wait_for_successfulpayment()
# Create a new database transaction
transaction = db.Transaction(user=self.user,
value=successfulpayment.total_amount,
value=successfulpayment.total_amount - int(total_fee * (10 ** int(configloader.config["Payments"]["currency_exp"]))),
provider="Credit Card",
telegram_charge_id=successfulpayment.telegram_payment_charge_id,
provider_charge_id=successfulpayment.provider_payment_charge_id)
@ -275,7 +282,7 @@ class ChatWorker(threading.Thread):
transaction.payment_email = successfulpayment.order_info.email
transaction.payment_phone = successfulpayment.order_info.phone_number
# Add the credit to the user account
self.user.credit += successfulpayment.total_amount
self.user.credit += (successfulpayment.total_amount - int(total_fee * (10 ** int(configloader.config["Payments"]["currency_exp"]))))
# Add and commit the transaction
self.session.add(transaction)
self.session.commit()