fix!: removed .commit() from repository level
This commit is contained in:
@@ -2,12 +2,11 @@ import math
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from config import cfg
|
||||
from core.deps import get_auth_context, get_pally_client
|
||||
from db.models.orders import OrderStatus
|
||||
from db.session import get_db
|
||||
from db.session import UnitOfWork, get_uow
|
||||
from external.pally import PallyClient
|
||||
from repositories import AddonsRepository, PricingRepository
|
||||
from repositories.invoices import InvoiceRepository
|
||||
@@ -31,13 +30,13 @@ router = APIRouter(prefix="/orders")
|
||||
async def checkout(
|
||||
order: OrderDetails,
|
||||
ctx: AuthContext = Depends(get_auth_context),
|
||||
session: AsyncSession = Depends(get_db),
|
||||
uow: UnitOfWork = Depends(get_uow),
|
||||
pally: PallyClient = Depends(get_pally_client),
|
||||
):
|
||||
addons_repo = AddonsRepository(session)
|
||||
pricing_repo = PricingRepository(session)
|
||||
invoices_repo = InvoiceRepository(session)
|
||||
orders_repo = OrderRepository(session)
|
||||
addons_repo = AddonsRepository(uow)
|
||||
pricing_repo = PricingRepository(uow)
|
||||
invoices_repo = InvoiceRepository(uow)
|
||||
orders_repo = OrderRepository(uow)
|
||||
|
||||
pricing = await get_pricing_model(addons_repo, pricing_repo)
|
||||
price = math.ceil(await calculate_price(addons_repo=addons_repo, order=order, pricing=pricing))
|
||||
@@ -72,7 +71,7 @@ async def checkout(
|
||||
raise HTTPException(500, detail="failed to create invoice")
|
||||
else:
|
||||
await deduct_order_balance(
|
||||
session,
|
||||
uow.session,
|
||||
user=ctx.user,
|
||||
order=order_entry,
|
||||
description=f"order {order_entry.id} paid from balance",
|
||||
@@ -85,7 +84,7 @@ async def checkout(
|
||||
now=now,
|
||||
):
|
||||
await apply_order_now(
|
||||
session,
|
||||
uow.session,
|
||||
user=ctx.user,
|
||||
order=order_entry,
|
||||
pricing=pricing,
|
||||
@@ -95,9 +94,12 @@ async def checkout(
|
||||
await queue_order_for_later(
|
||||
order=order_entry, subscription=ctx.user.subscription, now=now
|
||||
)
|
||||
await session.commit()
|
||||
await uow.commit()
|
||||
payment_link = None
|
||||
|
||||
if amount_to_pay > 0:
|
||||
await uow.commit()
|
||||
|
||||
return CheckoutResponse(
|
||||
order_id=str(order_entry.id),
|
||||
total_amount=price,
|
||||
|
||||
Reference in New Issue
Block a user