-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into is4657/payment-liveness-probes
- Loading branch information
Showing
31 changed files
with
1,102 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
from typing import TypeAlias | ||
from decimal import Decimal | ||
from typing import Any, ClassVar, TypeAlias | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
ProductName: TypeAlias = str | ||
|
||
|
||
class CreditResultGet(BaseModel): | ||
product_name: ProductName | ||
credit_amount: Decimal = Field(..., description="") | ||
|
||
class Config: | ||
schema_extra: ClassVar[dict[str, Any]] = { | ||
"examples": [ | ||
{"product_name": "s4l", "credit_amount": Decimal(15.5)}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
services/payments/src/simcore_service_payments/db/auto_recharge_repo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from typing import TypeAlias | ||
|
||
from models_library.api_schemas_webserver.wallets import PaymentMethodID | ||
from models_library.basic_types import NonNegativeDecimal | ||
from models_library.users import UserID | ||
from models_library.wallets import WalletID | ||
from pydantic import BaseModel, PositiveInt | ||
from simcore_postgres_database.utils_payments_autorecharge import AutoRechargeStmts | ||
|
||
from ..core.errors import InvalidPaymentMethodError | ||
from .base import BaseRepository | ||
|
||
AutoRechargeID: TypeAlias = PositiveInt | ||
|
||
|
||
class PaymentsAutorechargeDB(BaseModel): | ||
wallet_id: WalletID | ||
enabled: bool | ||
primary_payment_method_id: PaymentMethodID | ||
top_up_amount_in_usd: NonNegativeDecimal | ||
monthly_limit_in_usd: NonNegativeDecimal | None | ||
|
||
class Config: | ||
orm_mode = True | ||
|
||
|
||
class AutoRechargeRepo(BaseRepository): | ||
async def get_wallet_autorecharge( | ||
self, | ||
wallet_id: WalletID, | ||
) -> PaymentsAutorechargeDB | None: | ||
"""Annotates init-payment transaction | ||
Raises: | ||
PaymentAlreadyExistsError | ||
""" | ||
|
||
async with self.db_engine.begin() as conn: | ||
stmt = AutoRechargeStmts.get_wallet_autorecharge(wallet_id) | ||
result = await conn.execute(stmt) | ||
row = result.first() | ||
return PaymentsAutorechargeDB.from_orm(row) if row else None | ||
|
||
async def replace_wallet_autorecharge( | ||
self, | ||
user_id: UserID, | ||
wallet_id: WalletID, | ||
new: PaymentsAutorechargeDB, | ||
) -> PaymentsAutorechargeDB: | ||
""" | ||
Raises: | ||
InvalidPaymentMethodError: if `new` includes some invalid 'primary_payment_method_id' | ||
""" | ||
async with self.db_engine.begin() as conn: | ||
stmt = AutoRechargeStmts.is_valid_payment_method( | ||
user_id=user_id, | ||
wallet_id=new.wallet_id, | ||
payment_method_id=new.primary_payment_method_id, | ||
) | ||
|
||
if await conn.scalar(stmt) != new.primary_payment_method_id: | ||
raise InvalidPaymentMethodError( | ||
payment_method_id=new.primary_payment_method_id | ||
) | ||
|
||
stmt = AutoRechargeStmts.upsert_wallet_autorecharge( | ||
wallet_id=wallet_id, | ||
enabled=new.enabled, | ||
primary_payment_method_id=new.primary_payment_method_id, | ||
top_up_amount_in_usd=new.top_up_amount_in_usd, | ||
monthly_limit_in_usd=new.monthly_limit_in_usd, | ||
) | ||
result = await conn.execute(stmt) | ||
row = result.first() | ||
assert row # nosec | ||
return PaymentsAutorechargeDB.from_orm(row) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.