fix(wallet): add logger
add logger
This commit is contained in:
parent
c0b3bb1889
commit
fd61b36375
1 changed files with 9 additions and 0 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import logging
|
||||
from functools import cached_property
|
||||
|
||||
from django.core.validators import MinValueValidator
|
||||
|
|
@ -17,6 +18,7 @@ from .constans import StateChoices, TypeChoices
|
|||
from apps.users.models import User
|
||||
from ..gooyal_oauth2.models import Application
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class CurrencyChoices(models.TextChoices):
|
||||
IRANIAN_RIAL = '166ab7ce33b34799950d45035a9997d6', _('IRANIAN RIAL') # uuid without dash
|
||||
|
|
@ -165,14 +167,19 @@ class Transaction(BaseModel):
|
|||
raise APIException(error_message)
|
||||
|
||||
def withdraw_from_payer_balance(self):
|
||||
logger.debug('start withdraw_from_payer_balance')
|
||||
payer_is_allowed_negative_balance = self.payer_account.owner_type == TypeChoices.APPLICATION.value and str(
|
||||
self.payer_account.owner_uuid) in settings.ALLOWED_NEGATIVE_BALANCE_APPLICATIONS
|
||||
if self.amount > self.payer_account.balance and not payer_is_allowed_negative_balance:
|
||||
logger.error('not enough balance')
|
||||
raise UnprocessableEntity('not enough balance')
|
||||
logger.info(f'payer_account balance {self.payee_account} -> {self.payer_account.balance} - {self.amount}')
|
||||
self.payer_account.balance = F('balance') - self.amount
|
||||
self.payer_account.save(update_fields=['balance'])
|
||||
|
||||
def deposit_to_payee_balance(self):
|
||||
logger.debug('start deposit_to_payee_balance')
|
||||
logger.info(f'payee_account balance {self.payee_account} -> {self.payer_account.balance} + {self.amount}')
|
||||
self.payee_account.balance = F('balance') + self.amount
|
||||
self.payee_account.save(update_fields=['balance'])
|
||||
|
||||
|
|
@ -242,9 +249,11 @@ class Transaction(BaseModel):
|
|||
|
||||
if not self.payer_account.wallet.currency == self.payee_account.wallet.currency:
|
||||
self.change_state(from_state=self.state, to_state=StateChoices.FAILED)
|
||||
logger.info(f'payer({self.payer_account.wallet.currency}) and payee({self.payee_account.wallet.currency}) account currency not equal')
|
||||
raise APIException('payer and payee account currency not equal')
|
||||
|
||||
if not self.state == StateChoices.CREATED:
|
||||
logger.debug( f'this transaction is not ready to pay(UUID:{self.uuid}, state:{self.state})')
|
||||
raise APIException('this transaction is not ready to pay')
|
||||
|
||||
with transaction.atomic():
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue