feat(promo): Добавлена поддержка промокодов на скидку для всех платёжных систем
This commit is contained in:
@@ -18,6 +18,7 @@ async def pay_crypto_callback_handler(
|
||||
i18n_data: dict,
|
||||
session: AsyncSession,
|
||||
cryptopay_service: CryptoPayService,
|
||||
promo_code_service=None,
|
||||
):
|
||||
current_lang = i18n_data.get("current_language", settings.DEFAULT_LANGUAGE)
|
||||
i18n: Optional[JsonI18n] = i18n_data.get("i18n_instance")
|
||||
@@ -65,6 +66,7 @@ async def pay_crypto_callback_handler(
|
||||
amount=price_amount,
|
||||
description=payment_description,
|
||||
sale_mode=sale_mode,
|
||||
promo_code_service=promo_code_service,
|
||||
)
|
||||
|
||||
if invoice_url:
|
||||
|
||||
@@ -10,6 +10,7 @@ from bot.middlewares.i18n import JsonI18n
|
||||
from bot.services.freekassa_service import FreeKassaService
|
||||
from config.settings import Settings
|
||||
from db.dal import payment_dal
|
||||
from bot.handlers.user.subscription.payment_discount_helper import apply_discount_to_payment
|
||||
|
||||
router = Router(name="user_subscription_payments_freekassa_router")
|
||||
|
||||
@@ -21,6 +22,7 @@ async def pay_fk_callback_handler(
|
||||
i18n_data: dict,
|
||||
freekassa_service: FreeKassaService,
|
||||
session: AsyncSession,
|
||||
promo_code_service=None,
|
||||
):
|
||||
current_lang = i18n_data.get("current_language", settings.DEFAULT_LANGUAGE)
|
||||
i18n: Optional[JsonI18n] = i18n_data.get("i18n_instance")
|
||||
@@ -68,14 +70,22 @@ async def pay_fk_callback_handler(
|
||||
)
|
||||
currency_code = getattr(freekassa_service, "default_currency", None) or settings.DEFAULT_CURRENCY_SYMBOL or "RUB"
|
||||
|
||||
# Apply active discount if exists
|
||||
final_price_rub, discount_amount, promo_code_id = await apply_discount_to_payment(
|
||||
session, user_id, price_rub, promo_code_service
|
||||
)
|
||||
|
||||
payment_record_payload = {
|
||||
"user_id": user_id,
|
||||
"amount": price_rub,
|
||||
"amount": final_price_rub,
|
||||
"original_amount": price_rub if discount_amount else None,
|
||||
"discount_applied": discount_amount,
|
||||
"currency": currency_code,
|
||||
"status": "pending_freekassa",
|
||||
"description": payment_description,
|
||||
"subscription_duration_months": int(months),
|
||||
"provider": "freekassa",
|
||||
"promo_code_id": promo_code_id,
|
||||
}
|
||||
|
||||
try:
|
||||
@@ -101,7 +111,7 @@ async def pay_fk_callback_handler(
|
||||
payment_db_id=payment_record.payment_id,
|
||||
user_id=payment_record.user_id,
|
||||
months=months,
|
||||
amount=price_rub,
|
||||
amount=final_price_rub,
|
||||
currency=freekassa_service.default_currency,
|
||||
payment_method_id=freekassa_service.payment_method_id,
|
||||
ip_address=freekassa_service.server_ip,
|
||||
|
||||
@@ -10,6 +10,7 @@ from bot.middlewares.i18n import JsonI18n
|
||||
from bot.services.platega_service import PlategaService
|
||||
from config.settings import Settings
|
||||
from db.dal import payment_dal
|
||||
from bot.handlers.user.subscription.payment_discount_helper import apply_discount_to_payment
|
||||
|
||||
router = Router(name="user_subscription_payments_platega_router")
|
||||
|
||||
@@ -21,6 +22,7 @@ async def pay_platega_callback_handler(
|
||||
i18n_data: dict,
|
||||
platega_service: PlategaService,
|
||||
session: AsyncSession,
|
||||
promo_code_service=None,
|
||||
):
|
||||
current_lang = i18n_data.get("current_language", settings.DEFAULT_LANGUAGE)
|
||||
i18n: Optional[JsonI18n] = i18n_data.get("i18n_instance")
|
||||
@@ -68,14 +70,22 @@ async def pay_platega_callback_handler(
|
||||
)
|
||||
currency_code = settings.DEFAULT_CURRENCY_SYMBOL or "RUB"
|
||||
|
||||
# Apply active discount if exists
|
||||
final_price_rub, discount_amount, promo_code_id = await apply_discount_to_payment(
|
||||
session, user_id, price_rub, promo_code_service
|
||||
)
|
||||
|
||||
payment_record_payload = {
|
||||
"user_id": user_id,
|
||||
"amount": price_rub,
|
||||
"amount": final_price_rub,
|
||||
"original_amount": price_rub if discount_amount else None,
|
||||
"discount_applied": discount_amount,
|
||||
"currency": currency_code,
|
||||
"status": "pending_platega",
|
||||
"description": payment_description,
|
||||
"subscription_duration_months": int(months),
|
||||
"provider": "platega",
|
||||
"promo_code_id": promo_code_id,
|
||||
}
|
||||
|
||||
try:
|
||||
@@ -110,7 +120,7 @@ async def pay_platega_callback_handler(
|
||||
payment_db_id=payment_record.payment_id,
|
||||
user_id=user_id,
|
||||
months=months,
|
||||
amount=price_rub,
|
||||
amount=final_price_rub,
|
||||
currency=currency_code,
|
||||
description=payment_description,
|
||||
payload=payload_meta,
|
||||
|
||||
@@ -9,6 +9,7 @@ from bot.middlewares.i18n import JsonI18n
|
||||
from bot.services.severpay_service import SeverPayService
|
||||
from config.settings import Settings
|
||||
from db.dal import payment_dal
|
||||
from bot.handlers.user.subscription.payment_discount_helper import apply_discount_to_payment
|
||||
|
||||
router = Router(name="user_subscription_payments_severpay_router")
|
||||
|
||||
@@ -20,6 +21,7 @@ async def pay_severpay_callback_handler(
|
||||
i18n_data: dict,
|
||||
severpay_service: SeverPayService,
|
||||
session: AsyncSession,
|
||||
promo_code_service=None,
|
||||
):
|
||||
current_lang = i18n_data.get("current_language", settings.DEFAULT_LANGUAGE)
|
||||
i18n: Optional[JsonI18n] = i18n_data.get("i18n_instance")
|
||||
@@ -67,14 +69,22 @@ async def pay_severpay_callback_handler(
|
||||
)
|
||||
currency_code = settings.DEFAULT_CURRENCY_SYMBOL or "RUB"
|
||||
|
||||
# Apply active discount if exists
|
||||
final_price_rub, discount_amount, promo_code_id = await apply_discount_to_payment(
|
||||
session, user_id, price_rub, promo_code_service
|
||||
)
|
||||
|
||||
payment_record_payload = {
|
||||
"user_id": user_id,
|
||||
"amount": price_rub,
|
||||
"amount": final_price_rub,
|
||||
"original_amount": price_rub if discount_amount else None,
|
||||
"discount_applied": discount_amount,
|
||||
"currency": currency_code,
|
||||
"status": "pending_severpay",
|
||||
"description": payment_description,
|
||||
"subscription_duration_months": int(months),
|
||||
"provider": "severpay",
|
||||
"promo_code_id": promo_code_id,
|
||||
}
|
||||
|
||||
try:
|
||||
@@ -100,7 +110,7 @@ async def pay_severpay_callback_handler(
|
||||
payment_db_id=payment_record.payment_id,
|
||||
user_id=user_id,
|
||||
months=months,
|
||||
amount=price_rub,
|
||||
amount=final_price_rub,
|
||||
currency=currency_code,
|
||||
description=payment_description,
|
||||
)
|
||||
|
||||
@@ -19,6 +19,7 @@ async def pay_stars_callback_handler(
|
||||
i18n_data: dict,
|
||||
session: AsyncSession,
|
||||
stars_service: StarsService,
|
||||
promo_code_service=None,
|
||||
):
|
||||
current_lang = i18n_data.get("current_language", settings.DEFAULT_LANGUAGE)
|
||||
i18n: Optional[JsonI18n] = i18n_data.get("i18n_instance")
|
||||
@@ -66,6 +67,7 @@ async def pay_stars_callback_handler(
|
||||
stars_price=stars_price,
|
||||
description=payment_description,
|
||||
sale_mode=sale_mode,
|
||||
promo_code_service=promo_code_service,
|
||||
)
|
||||
|
||||
if payment_db_id:
|
||||
|
||||
Reference in New Issue
Block a user