FIX(wallet): add cancel state and add success to rollback init states
add cancel state and add success to rollback init states
This commit is contained in:
parent
fd244950e1
commit
7e378e5b54
3 changed files with 33 additions and 1 deletions
|
|
@ -11,6 +11,7 @@ class StateChoices(IntegerChoices):
|
||||||
FAILED = 6 , _('failed')
|
FAILED = 6 , _('failed')
|
||||||
EXPECTED_FAILURE = 7 , _('expected_failure') # no exact data available but guessed to be failed
|
EXPECTED_FAILURE = 7 , _('expected_failure') # no exact data available but guessed to be failed
|
||||||
ROLLED_BACK = 8 , _('ROLLED_BACK')
|
ROLLED_BACK = 8 , _('ROLLED_BACK')
|
||||||
|
CANCELED = 9, _('CANCELED')
|
||||||
|
|
||||||
|
|
||||||
class TypeChoices(IntegerChoices):
|
class TypeChoices(IntegerChoices):
|
||||||
|
|
|
||||||
18
apps/wallet/migrations/0018_alter_transaction_state.py
Normal file
18
apps/wallet/migrations/0018_alter_transaction_state.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 5.1.7 on 2026-02-14 11:48
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('wallet', '0017_transaction_reference_alter_transaction_state_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='transaction',
|
||||||
|
name='state',
|
||||||
|
field=models.IntegerField(choices=[(1, 'created'), (2, 'delayed'), (3, 'pending'), (4, 'incomplete'), (5, 'success'), (6, 'failed'), (7, 'expected_failure'), (8, 'ROLLED_BACK'), (9, 'CANCELED')], default=1),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -356,7 +356,7 @@ class Transaction(BaseModel):
|
||||||
)
|
)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def rollback(self):
|
def cancel(self):
|
||||||
if self.state not in [StateChoices.PENDING, StateChoices.DELAYED, StateChoices.INCOMPLETE]:
|
if self.state not in [StateChoices.PENDING, StateChoices.DELAYED, StateChoices.INCOMPLETE]:
|
||||||
raise APIException('this transaction is not pending')
|
raise APIException('this transaction is not pending')
|
||||||
|
|
||||||
|
|
@ -364,6 +364,19 @@ class Transaction(BaseModel):
|
||||||
self.rollback_withdraw_to_payer_balance()
|
self.rollback_withdraw_to_payer_balance()
|
||||||
self.change_state(
|
self.change_state(
|
||||||
[StateChoices.PENDING, StateChoices.DELAYED, StateChoices.INCOMPLETE],
|
[StateChoices.PENDING, StateChoices.DELAYED, StateChoices.INCOMPLETE],
|
||||||
|
StateChoices.CANCELED,
|
||||||
|
error_message=_('TRANSACTION_STATE_NOT_SUITABLE_FOR_CANCELING')
|
||||||
|
)
|
||||||
|
return self
|
||||||
|
|
||||||
|
def rollback(self):
|
||||||
|
if self.state not in [StateChoices.PENDING, StateChoices.SUCCESS, StateChoices.DELAYED, StateChoices.INCOMPLETE]:
|
||||||
|
raise APIException('this transaction is not pending')
|
||||||
|
|
||||||
|
with transaction.atomic():
|
||||||
|
self.rollback_withdraw_to_payer_balance()
|
||||||
|
self.change_state(
|
||||||
|
[StateChoices.PENDING, StateChoices.SUCCESS, StateChoices.DELAYED, StateChoices.INCOMPLETE],
|
||||||
StateChoices.ROLLED_BACK,
|
StateChoices.ROLLED_BACK,
|
||||||
error_message=_('TRANSACTION_STATE_NOT_SUITABLE_FOR_ROLLBACK')
|
error_message=_('TRANSACTION_STATE_NOT_SUITABLE_FOR_ROLLBACK')
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue