update bank expiration logic
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from .enum import BankType, PaymentStatus
|
from .enum import BankType, PaymentStatus
|
||||||
@@ -23,19 +24,28 @@ class BankManager(models.Manager):
|
|||||||
return self.get_queryset().active()
|
return self.get_queryset().active()
|
||||||
|
|
||||||
def update_expire_records(self):
|
def update_expire_records(self):
|
||||||
|
now = timezone.now()
|
||||||
|
cutoff = now - datetime.timedelta(minutes=15)
|
||||||
|
|
||||||
count = (
|
count = (
|
||||||
self.active()
|
self.active()
|
||||||
.filter(
|
.filter(
|
||||||
status=PaymentStatus.RETURN_FROM_BANK,
|
status=PaymentStatus.RETURN_FROM_BANK,
|
||||||
update_at__lte=datetime.datetime.now() - datetime.timedelta(minutes=15),
|
update_at__lte=cutoff,
|
||||||
)
|
)
|
||||||
.update(status=PaymentStatus.EXPIRE_VERIFY_PAYMENT)
|
.update(status=PaymentStatus.EXPIRE_VERIFY_PAYMENT)
|
||||||
)
|
)
|
||||||
|
|
||||||
count = count + self.active().filter(
|
count = count + self.active().filter(
|
||||||
status=PaymentStatus.REDIRECT_TO_BANK,
|
status=PaymentStatus.REDIRECT_TO_BANK,
|
||||||
update_at__lt=datetime.datetime.now() - datetime.timedelta(minutes=15),
|
update_at__lt=cutoff,
|
||||||
).update(status=PaymentStatus.EXPIRE_GATEWAY_TOKEN)
|
).update(status=PaymentStatus.EXPIRE_GATEWAY_TOKEN)
|
||||||
|
|
||||||
|
count = count + self.active().filter(
|
||||||
|
status=PaymentStatus.WAITING,
|
||||||
|
update_at__lt=cutoff,
|
||||||
|
).update(status=PaymentStatus.EXPIRE_GATEWAY_TOKEN)
|
||||||
|
|
||||||
return count
|
return count
|
||||||
|
|
||||||
def filter_return_from_bank(self):
|
def filter_return_from_bank(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user