From 2be0c7ee6059261286565d680ed092937db219a0 Mon Sep 17 00:00:00 2001 From: Alisson Date: Fri, 25 Aug 2023 15:38:59 -0300 Subject: [PATCH] check if invoice has amount --- connect/common/tasks.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/connect/common/tasks.py b/connect/common/tasks.py index c5f9a8d5..6d652c83 100644 --- a/connect/common/tasks.py +++ b/connect/common/tasks.py @@ -486,16 +486,22 @@ def capture_invoice(): for invoice in Invoice.objects.filter( payment_status=Invoice.PAYMENT_STATUS_PENDING, capture_payment=True ): - gateway = billing.get_gateway("stripe") - purchase_result = gateway.purchase( - money=invoice.invoice_amount, - identification=invoice.organization.organization_billing.stripe_customer, - options={"id": invoice.pk}, - ) - if purchase_result.get("status") == "FAILURE": - invoice.capture_payment = False - invoice.save(update_fields=["capture_payment"]) - # add send email + if invoice.invoice_amount: + gateway = billing.get_gateway("stripe") + purchase_result = gateway.purchase( + money=invoice.invoice_amount, + identification=invoice.organization.organization_billing.stripe_customer, + options={"id": invoice.pk}, + ) + if purchase_result.get("status") == "FAILURE": + invoice.capture_payment = False + invoice.save(update_fields=["capture_payment"]) + # add send email + return + + invoice.capture_payment = False + invoice.save(update_fields=["capture_payment"]) + return @app.task()