fix!: removed .commit() from repository level
This commit is contained in:
@@ -6,7 +6,8 @@ from datetime import UTC, datetime
|
||||
|
||||
from config import cfg
|
||||
from db.models.orders import OrderStatus
|
||||
from db.models.transactions import BalanceTransaction, BalanceTxType
|
||||
from db.models.transactions import BalanceTxType
|
||||
from db.session import UnitOfWork
|
||||
from repositories import AddonsRepository
|
||||
from repositories.invoices import InvoiceRepository
|
||||
from repositories.orders import OrderRepository
|
||||
@@ -32,16 +33,17 @@ def validate_pally_signature(out_sum: str, inv_id: str, signature_value: str) ->
|
||||
|
||||
|
||||
async def process_subscription_purchase( # noqa: PLR0911, PLR0912
|
||||
session,
|
||||
uow: UnitOfWork,
|
||||
*,
|
||||
invoice_id: int,
|
||||
trs_id: str,
|
||||
amount: int,
|
||||
) -> None:
|
||||
invoice_repo = InvoiceRepository(session)
|
||||
orders_repo = OrderRepository(session)
|
||||
users_repo = UserRepository(session)
|
||||
pricing_repo = PricingRepository(session)
|
||||
session = uow.session
|
||||
invoice_repo = InvoiceRepository(uow)
|
||||
orders_repo = OrderRepository(uow)
|
||||
users_repo = UserRepository(uow)
|
||||
pricing_repo = PricingRepository(uow)
|
||||
|
||||
invoice = await invoice_repo.get_by_id(invoice_id)
|
||||
|
||||
@@ -99,7 +101,7 @@ async def process_subscription_purchase( # noqa: PLR0911, PLR0912
|
||||
|
||||
subscription = user.subscription
|
||||
now = datetime.now(UTC)
|
||||
pricing = await get_pricing_model(AddonsRepository(session), pricing_repo)
|
||||
pricing = await get_pricing_model(AddonsRepository(uow), pricing_repo)
|
||||
|
||||
logger.info(
|
||||
"Processing payment: bill_id=%s, order_id=%s, user_id=%s, amount=%s",
|
||||
@@ -142,19 +144,14 @@ async def process_subscription_purchase( # noqa: PLR0911, PLR0912
|
||||
if referal_id is not None:
|
||||
referal_amount = math.floor(amount * (cfg.referal_bonus / 100))
|
||||
if referal_amount > 0:
|
||||
referal_user = await session.get(type(user), referal_id)
|
||||
referal_user = await users_repo.get_user_by_id(referal_id)
|
||||
if referal_user is not None:
|
||||
session.add(
|
||||
BalanceTransaction(
|
||||
user_id=referal_id,
|
||||
amount=referal_amount,
|
||||
tx_type=BalanceTxType.REFERRAL_BONUS,
|
||||
balance_before=referal_user.balance,
|
||||
balance_after=referal_user.balance + referal_amount,
|
||||
description=f"referral reward for user {invoice.creator_id} (TrsId: {trs_id})",
|
||||
)
|
||||
await users_repo.increase_balance(
|
||||
referal_id,
|
||||
referal_amount,
|
||||
BalanceTxType.REFERRAL_BONUS,
|
||||
f"referral reward for user {invoice.creator_id} (TrsId: {trs_id})",
|
||||
)
|
||||
referal_user.balance += referal_amount
|
||||
|
||||
logger.info(
|
||||
"Referral bonus processed: referrer_id=%s, amount=%s",
|
||||
@@ -169,6 +166,6 @@ async def process_subscription_purchase( # noqa: PLR0911, PLR0912
|
||||
trs_id,
|
||||
)
|
||||
|
||||
await session.commit()
|
||||
await uow.commit()
|
||||
|
||||
logger.info("Bill %s marked as PAID for TrsId %s", invoice_id, trs_id)
|
||||
|
||||
Reference in New Issue
Block a user