1
Fork 0
mirror of https://github.com/Steffo99/greed.git synced 2024-11-22 05:54:18 +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 file parameters
[Config] [Config]
; Config file version. DO NOT EDIT THIS! ; Config file version. DO NOT EDIT THIS!
version = 8 version = 9
; Set this to no when you are done editing the file ; Set this to no when you are done editing the file
is_template = yes is_template = yes
@ -37,9 +37,14 @@ credit_card_token = 123456789:YOUR_TOKEN_HERE_
min_amount = 10 min_amount = 10
# Maximum wallet payment accepted # Maximum wallet payment accepted
max_amount = 100 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 name_required = yes
# Require the email of the credit card owner # Require the email of the user
email_required = yes email_required = yes
# Require the phone number of the credit card owner # Require the phone number of the user
phone_required = yes phone_required = yes

View file

@ -42,7 +42,7 @@ class User(TableDeclarativeBase):
self.last_name = telegram_chat.last_name self.last_name = telegram_chat.last_name
self.username = telegram_chat.username self.username = telegram_chat.username
# The starting wallet value is 0 # The starting wallet value is 0
self.credit = decimal.Decimal("0") self.credit = 0
def __str__(self): def __str__(self):
"""Describe the user in the best way possible given the available data.""" """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: label of the labeled price on the invoice
payment_invoice_label = "Ricarica" payment_invoice_label = "Ricarica"
# Payment: label of the labeled price on the invoice
payment_invoice_fee_label = "Carta di credito"
# Info: informazioni sul bot # Info: informazioni sul bot
bot_info = 'Questo bot utilizza <a href="https://github.com/Steffo99/greed">greed</a>,' \ 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' \ ' un framework di @Steffo per i pagamenti su Telegram rilasciato sotto la' \

View file

@ -245,6 +245,13 @@ class ChatWorker(threading.Thread):
break break
# Set the invoice active invoice payload # Set the invoice active invoice payload
self.invoice_payload = str(uuid.uuid4()) 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 # The amount is valid, send the invoice
self.bot.send_invoice(self.chat.id, self.bot.send_invoice(self.chat.id,
title=strings.payment_invoice_title, title=strings.payment_invoice_title,
@ -253,7 +260,7 @@ class ChatWorker(threading.Thread):
provider_token=configloader.config["Credit Card"]["credit_card_token"], provider_token=configloader.config["Credit Card"]["credit_card_token"],
start_parameter="tempdeeplink", # TODO: no idea on how deeplinks should work start_parameter="tempdeeplink", # TODO: no idea on how deeplinks should work
currency=configloader.config["Payments"]["currency"], 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_name=configloader.config["Credit Card"]["name_required"] == "yes",
need_email=configloader.config["Credit Card"]["email_required"] == "yes", need_email=configloader.config["Credit Card"]["email_required"] == "yes",
need_phone_number=configloader.config["Credit Card"]["phone_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() successfulpayment = self.__wait_for_successfulpayment()
# Create a new database transaction # Create a new database transaction
transaction = db.Transaction(user=self.user, 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", provider="Credit Card",
telegram_charge_id=successfulpayment.telegram_payment_charge_id, telegram_charge_id=successfulpayment.telegram_payment_charge_id,
provider_charge_id=successfulpayment.provider_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_email = successfulpayment.order_info.email
transaction.payment_phone = successfulpayment.order_info.phone_number transaction.payment_phone = successfulpayment.order_info.phone_number
# Add the credit to the user account # 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 # Add and commit the transaction
self.session.add(transaction) self.session.add(transaction)
self.session.commit() self.session.commit()