This repository has been archived by the owner on Jun 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
YC-1188 Update unpaid PF transactions status in cron task, refactor c…
…onfirm transaction code
- Loading branch information
1 parent
d0a1527
commit d1af953
Showing
12 changed files
with
225 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
geocity/apps/submissions/management/commands/update_payment_transactions_status.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import datetime | ||
|
||
from django.conf import settings | ||
from django.core.management import BaseCommand | ||
from django.utils import timezone | ||
from django.utils.translation import gettext | ||
|
||
from geocity.apps.submissions.payments.models import Transaction | ||
from geocity.apps.submissions.payments.postfinance.models import PostFinanceTransaction | ||
from geocity.apps.submissions.payments.services import get_payment_processor | ||
|
||
|
||
class Command(BaseCommand): | ||
help = gettext( | ||
"Update the status of transactions that are pending and not older than %s hours." | ||
% settings.PAYMENT_PENDING_TRANSACTION_MAX_AGE_MINS | ||
) | ||
|
||
def handle(self, *args, **options): | ||
self.stdout.write( | ||
"Checking status of unpaid transations that are not older than %s minutes..." | ||
% settings.PAYMENT_PENDING_TRANSACTION_MAX_AGE_MINS | ||
) | ||
|
||
nb_transactions_confirmed = 0 | ||
nb_transactions_failed = 0 | ||
# Get all unpaid transactions that are not older than the specified time | ||
transactions_to_update = PostFinanceTransaction.objects.filter( | ||
status=Transaction.STATUS_UNPAID, | ||
authorization_timeout_on__gte=timezone.now() | ||
- datetime.timedelta( | ||
minutes=settings.PAYMENT_PENDING_TRANSACTION_MAX_AGE_MINS | ||
), | ||
) | ||
|
||
for transaction in transactions_to_update: | ||
submission = transaction.submission_price.submission | ||
processor = get_payment_processor(submission.get_form_for_payment()) | ||
|
||
if processor.is_transaction_authorized(transaction): | ||
transaction.confirm_payment() | ||
nb_transactions_confirmed += 1 | ||
elif processor.is_transaction_failed(transaction): | ||
transaction.set_failed() | ||
nb_transactions_failed += 1 | ||
|
||
if nb_transactions_confirmed: | ||
self.stdout.write( | ||
"Marked %d transactions as confirmed." % nb_transactions_confirmed | ||
) | ||
if nb_transactions_failed: | ||
self.stdout.write( | ||
"Marked %d transactions as failed." % nb_transactions_failed | ||
) | ||
if not nb_transactions_confirmed and not nb_transactions_failed: | ||
self.stdout.write("No transactions to update.") |
27 changes: 27 additions & 0 deletions
27
.../apps/submissions/migrations/0031_historicalpostfinancetransaction_extra_data_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Generated by Django 4.2.11 on 2024-06-06 12:46 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("submissions", "0030_alter_servicefeetype_fix_price_editable"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="historicalpostfinancetransaction", | ||
name="extra_data", | ||
field=models.JSONField( | ||
default=dict, verbose_name="Données supplémentaires" | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="postfinancetransaction", | ||
name="extra_data", | ||
field=models.JSONField( | ||
default=dict, verbose_name="Données supplémentaires" | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.