From 9e14286321c5314c696dc616a5f1d2d1426aacbb Mon Sep 17 00:00:00 2001 From: Syed Sajjad Hussain Shah Date: Thu, 19 Dec 2024 17:48:19 +0500 Subject: [PATCH] fix: multiple paypal refund transactions bug --- commerce_coordinator/apps/commercetools/tasks.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/commerce_coordinator/apps/commercetools/tasks.py b/commerce_coordinator/apps/commercetools/tasks.py index d61eb8da..4e71fa46 100644 --- a/commerce_coordinator/apps/commercetools/tasks.py +++ b/commerce_coordinator/apps/commercetools/tasks.py @@ -88,6 +88,10 @@ def refund_from_paypal_task( client = CommercetoolsAPIClient() try: payment = client.get_payment_by_transaction_interaction_id(paypal_capture_id) + if has_full_refund_transaction(payment): + logger.info(f"PayPal payment.capture.refunded event received, but Payment with ID {payment.id} " + f"already has a refund with id:{refund.id}. Skipping task to add refund transaction.") + return None updated_payment = client.create_return_payment_transaction( payment_id=payment.id, payment_version=payment.version,