1
|
from django.core.management.base import BaseCommand
|
2
|
from django.utils import timezone
|
3
|
|
4
|
from facturier.models import TransactionEvent
|
5
|
|
6
|
|
7
|
class Command(BaseCommand):
|
8
|
|
9
|
def handle(self, *args, **options):
|
10
|
delta = timezone.now() - timezone.timedelta(minutes=10)
|
11
|
for event in TransactionEvent.objects.filter(status='CREATED', date__lte=delta):
|
12
|
if not TransactionEvent.objects.filter(invoice_id=event.invoice_id,
|
13
|
status__in=['CANCELED', 'ERROR', 'PAID', 'DENIED']).exists():
|
14
|
TransactionEvent.objects.create(transaction_id=event.transaction_id,
|
15
|
status='CANCELED',
|
16
|
invoice_id=event.invoice_id, regie=event.regie,
|
17
|
details='{"message": "%s canceled because expired"}' % event.transaction_id)
|