FIX(settlement): add rollback_deposit_to_payee_balance
add rollback_deposit_to_payee_balance
This commit is contained in:
parent
0a179bf350
commit
a8b32a16f4
1 changed files with 23 additions and 9 deletions
|
|
@ -253,8 +253,8 @@ class Transaction(BaseModel):
|
||||||
else:
|
else:
|
||||||
raise UnprocessableEntity('not enough balance')
|
raise UnprocessableEntity('not enough balance')
|
||||||
|
|
||||||
def rollback_withdraw_to_payer_balance(self):
|
def rollback_withdraw_from_payer_balance(self):
|
||||||
logger.debug('start rollback deposit_to_payee_balance')
|
logger.debug('start rollback withdraw_from_payer_balance')
|
||||||
logger.info(f'payer_account balance {self.payer_account} -> {self.amount}')
|
logger.info(f'payer_account balance {self.payer_account} -> {self.amount}')
|
||||||
self.payer_account.balance = F('balance') + self.amount
|
self.payer_account.balance = F('balance') + self.amount
|
||||||
self.payer_account.save(update_fields=['balance'])
|
self.payer_account.save(update_fields=['balance'])
|
||||||
|
|
@ -265,6 +265,12 @@ class Transaction(BaseModel):
|
||||||
self.payee_account.balance = F('balance') + self.amount
|
self.payee_account.balance = F('balance') + self.amount
|
||||||
self.payee_account.save(update_fields=['balance'])
|
self.payee_account.save(update_fields=['balance'])
|
||||||
|
|
||||||
|
def rollback_deposit_to_payee_balance(self):
|
||||||
|
logger.debug('start rollback deposit_to_payee_balance')
|
||||||
|
logger.info(f'payee_account balance {self.payee_account} -> {self.amount}')
|
||||||
|
self.payee_account.balance = F('balance') - self.amount
|
||||||
|
self.payee_account.save(update_fields=['balance'])
|
||||||
|
|
||||||
# TODO: refactor
|
# TODO: refactor
|
||||||
def pay(self, payer_id=None, payer_type=None):
|
def pay(self, payer_id=None, payer_type=None):
|
||||||
if not self.payer_id and not (payer_id and payer_type):
|
if not self.payer_id and not (payer_id and payer_type):
|
||||||
|
|
@ -369,7 +375,7 @@ class Transaction(BaseModel):
|
||||||
raise APIException('this transaction is not pending')
|
raise APIException('this transaction is not pending')
|
||||||
|
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
self.rollback_withdraw_to_payer_balance()
|
self.rollback_withdraw_from_payer_balance()
|
||||||
self.change_state(
|
self.change_state(
|
||||||
[StateChoices.PENDING, StateChoices.DELAYED, StateChoices.INCOMPLETE],
|
[StateChoices.PENDING, StateChoices.DELAYED, StateChoices.INCOMPLETE],
|
||||||
StateChoices.CANCELED,
|
StateChoices.CANCELED,
|
||||||
|
|
@ -382,12 +388,20 @@ class Transaction(BaseModel):
|
||||||
raise APIException('this transaction is not pending')
|
raise APIException('this transaction is not pending')
|
||||||
|
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
self.rollback_withdraw_to_payer_balance()
|
self.rollback_withdraw_from_payer_balance()
|
||||||
|
if self.state == StateChoices.SUCCESS:
|
||||||
|
self.rollback_deposit_to_payee_balance()
|
||||||
self.change_state(
|
self.change_state(
|
||||||
[StateChoices.PENDING, StateChoices.SUCCESS, StateChoices.DELAYED, StateChoices.INCOMPLETE],
|
[StateChoices.SUCCESS],
|
||||||
StateChoices.ROLLED_BACK,
|
StateChoices.ROLLED_BACK,
|
||||||
error_message=_('TRANSACTION_STATE_NOT_SUITABLE_FOR_ROLLBACK')
|
error_message=_('TRANSACTION_STATE_NOT_SUITABLE_FOR_ROLLBACK')
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
self.change_state(
|
||||||
|
[StateChoices.PENDING, StateChoices.DELAYED, StateChoices.INCOMPLETE],
|
||||||
|
StateChoices.CANCELED,
|
||||||
|
error_message=_('TRANSACTION_STATE_NOT_SUITABLE_FOR_CANCEL')
|
||||||
|
)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get_role(self, entity):
|
def get_role(self, entity):
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue