feat: add withdraw
This commit is contained in:
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
from datetime import datetime,timezone
|
||||
from decimal import Decimal
|
||||
from typing import Any
|
||||
import re
|
||||
from ulid import ULID
|
||||
from src.application.abstractions import IUnitOfWork
|
||||
from src.application.contracts import IQueueMessanger,ILogger,IMozenSbpService,SbpBank
|
||||
@@ -48,14 +49,30 @@ class CreateSbpWithdrawalCommand:
|
||||
raise BadRequestException(message='SBP bank not found')
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _normalize_russian_phone(phone: str | None) -> str:
|
||||
digits=re.sub(r'\D','',phone or '')
|
||||
if len(digits)!=11:
|
||||
raise BadRequestException(message='Russian phone number is required for SBP withdrawal')
|
||||
if digits.startswith('8'):
|
||||
digits=f'7{digits[1:]}'
|
||||
if not digits.startswith('7'):
|
||||
raise BadRequestException(message='Russian phone number is required for SBP withdrawal')
|
||||
return f'+{digits}'
|
||||
|
||||
|
||||
@transactional
|
||||
async def __call__(self,*,user_id: str,bank_id: str,phone: str,usdt_amount: Decimal) -> SbpWithdrawalEntity:
|
||||
async def __call__(self,*,user_id: str,bank_id: str,usdt_amount: Decimal) -> SbpWithdrawalEntity:
|
||||
user=await self._unit_of_work.user_repository.get(user_id)
|
||||
if user is None:
|
||||
raise NotFoundException(message='User not found')
|
||||
wallet_address=str(settings.SBP_WITHDRAWAL_WALLET_ADDRESS or '').strip()
|
||||
phone=self._normalize_russian_phone(user.phone)
|
||||
wallet_address=str(settings.CRYPTO_USDT_CONTRACT_ADDRESS or '').strip()
|
||||
if not wallet_address:
|
||||
raise ServiceUnavailableException(message='SBP withdrawal wallet address unavailable')
|
||||
raise ServiceUnavailableException(message='USDT contract address unavailable')
|
||||
sender_wallet_address=str(user.erc20 or '').strip()
|
||||
if not sender_wallet_address:
|
||||
raise BadRequestException(message='User ERC20 wallet address is required for SBP withdrawal')
|
||||
trace_id=self._logger.get_trace_id()
|
||||
withdraw_id=str(ULID())
|
||||
bank_name=await self._bank_name(bank_id)
|
||||
@@ -66,7 +83,6 @@ class CreateSbpWithdrawalCommand:
|
||||
bank_id=bank_id,
|
||||
bank_name=bank_name,
|
||||
phone=phone,
|
||||
wallet_address=wallet_address,
|
||||
usdt_amount=quote.usdt_amount,
|
||||
rub_amount=quote.rub_amount,
|
||||
usdt_exchange_rate=quote.usdt_exchange_rate,
|
||||
@@ -83,6 +99,8 @@ class CreateSbpWithdrawalCommand:
|
||||
'usdt_amount':str(quote.usdt_amount),
|
||||
'trace_id':trace_id,
|
||||
'wallet_address':wallet_address,
|
||||
'sender_wallet_address':sender_wallet_address,
|
||||
'receiver_wallet_address':wallet_address,
|
||||
'withdraw_id':withdraw_id,
|
||||
'message_id':message_id,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user