From c471fc4773bfb9be30a5438fd3f4cbe9e4dfba1c Mon Sep 17 00:00:00 2001 From: CP Date: Fri, 20 Sep 2024 14:42:22 -0400 Subject: [PATCH 1/8] Quick hold --- payments/models.py | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/payments/models.py b/payments/models.py index 3469e892..a925a986 100644 --- a/payments/models.py +++ b/payments/models.py @@ -139,7 +139,7 @@ def choices(cls): ), ) - state = FSMField(default=STATE.PENDING, state_choices=STATE.choices()) + state = models.CharField(default=STATE.PENDING, choices=STATE.choices()) purchaser = models.ForeignKey( User, on_delete=models.CASCADE, @@ -200,7 +200,8 @@ def review(self): def errored(self): """Error this order""" - raise NotImplementedError + self.state = Order.STATE.ERRORED + self.save() def refund(self, *, api_response_data, **kwargs): """Issue a refund""" @@ -272,11 +273,6 @@ def send_ecommerce_order_receipt(self): TODO: add email """ - @transition( - field="state", - source=Order.STATE.PENDING, - target=Order.STATE.FULFILLED, - ) def fulfill(self, payment_data): """Fufill the order.""" # record the transaction @@ -287,6 +283,9 @@ def fulfill(self, payment_data): # send the receipt emails transaction.on_commit(self.send_ecommerce_order_receipt) + + self.state = Order.STATE.FULFILLED + self.save() class PendingOrder(FulfillableOrder, Order): @@ -385,11 +384,11 @@ def create_from_product(cls, product: Product, user: User): return cls._get_or_create(cls, [product], user) - @transition(field="state", source=Order.STATE.PENDING, target=Order.STATE.CANCELED) def cancel(self): """Cancel this order""" + self.state = Order.STATE.CANCELED + self.save() - @transition(field="state", source=Order.STATE.PENDING, target=Order.STATE.DECLINED) def decline(self): """ Decline this order. This additionally clears the discount redemptions @@ -400,10 +399,6 @@ def decline(self): return self - @transition(field="state", source=Order.STATE.PENDING, target=Order.STATE.ERRORED) - def error(self): - """Error this order""" - class Meta: """Model meta options""" @@ -413,10 +408,6 @@ class Meta: class FulfilledOrder(Order): """An order that has a fulfilled payment""" - @transition(field="state", source=Order.STATE.FULFILLED, target=Order.STATE.ERRORED) - def error(self): - """Error this order""" - @transition( field="state", source=Order.STATE.FULFILLED, @@ -486,10 +477,6 @@ class CanceledOrder(Order): The state of this can't be altered further. """ - @transition(field="state", source=Order.STATE.CANCELED, target=Order.STATE.ERRORED) - def error(self): - """Error this order""" - class Meta: """Model meta options.""" @@ -515,11 +502,6 @@ class DeclinedOrder(Order): The state of this can't be altered further. """ - - @transition(field="state", source=Order.STATE.DECLINED, target=Order.STATE.ERRORED) - def error(self): - """Error this order""" - class Meta: """Model meta options.""" From b8935eee66514db109cc07f19b3f5f92b4ea03c5 Mon Sep 17 00:00:00 2001 From: CP Date: Mon, 23 Sep 2024 12:17:25 -0400 Subject: [PATCH 2/8] migration --- .../0001_add_order_and_basket_models.py | 4 +- payments/migrations/0003_alter_order_state.py | 18 ++ payments/models.py | 238 ++++++++---------- 3 files changed, 123 insertions(+), 137 deletions(-) create mode 100644 payments/migrations/0003_alter_order_state.py diff --git a/payments/migrations/0001_add_order_and_basket_models.py b/payments/migrations/0001_add_order_and_basket_models.py index 02b8ae78..3033a935 100644 --- a/payments/migrations/0001_add_order_and_basket_models.py +++ b/payments/migrations/0001_add_order_and_basket_models.py @@ -269,7 +269,7 @@ class Migration(migrations.Migration): "indexes": [], "constraints": [], }, - bases=(payments.models.FulfillableOrder, "payments.order"), + bases=("payments.order",), ), migrations.CreateModel( name="RefundedOrder", @@ -289,7 +289,7 @@ class Migration(migrations.Migration): "indexes": [], "constraints": [], }, - bases=(payments.models.FulfillableOrder, "payments.order"), + bases=("payments.order",), ), migrations.AddConstraint( model_name="line", diff --git a/payments/migrations/0003_alter_order_state.py b/payments/migrations/0003_alter_order_state.py new file mode 100644 index 00000000..737f81bb --- /dev/null +++ b/payments/migrations/0003_alter_order_state.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.15 on 2024-09-23 15:31 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('payments', '0002_remove_system_slug_from_basket'), + ] + + operations = [ + migrations.AlterField( + model_name='order', + name='state', + field=models.CharField(choices=[('pending', 'Pending'), ('fulfilled', 'Fulfilled'), ('canceled', 'Canceled'), ('refunded', 'Refunded'), ('declined', 'Declined'), ('errored', 'Errored'), ('review', 'Review')], default='pending'), + ), + ] diff --git a/payments/models.py b/payments/models.py index a925a986..eb5a93d9 100644 --- a/payments/models.py +++ b/payments/models.py @@ -109,7 +109,6 @@ class Order(TimestampedModel): class STATE: """Possible states for an order.""" - PENDING = "pending" FULFILLED = "fulfilled" CANCELED = "canceled" @@ -118,28 +117,16 @@ class STATE: REFUNDED = "refunded" REVIEW = "review" PARTIALLY_REFUNDED = "partially_refunded" - - @classmethod - def choices(cls): - """Return the valid choices, their human-readable names, and the order class - they belong to. - """ - return ( - (cls.PENDING, "Pending", "PendingOrder"), - (cls.FULFILLED, "Fulfilled", "FulfilledOrder"), - (cls.CANCELED, "Canceled", "CanceledOrder"), - (cls.REFUNDED, "Refunded", "RefundedOrder"), - (cls.DECLINED, "Declined", "DeclinedOrder"), - (cls.ERRORED, "Errored", "ErroredOrder"), - (cls.REVIEW, "Review", "ReviewOrder"), - ( - cls.PARTIALLY_REFUNDED, - "Partially Refunded", - "PartiallyRefundedOrder", - ), - ) - - state = models.CharField(default=STATE.PENDING, choices=STATE.choices()) + + choices = [(PENDING, "Pending"), + (FULFILLED, "Fulfilled"), + (CANCELED, "Canceled"), + (REFUNDED, "Refunded"), + (DECLINED, "Declined"), + (ERRORED, "Errored"), + (REVIEW, "Review")] + + state = models.CharField(default=STATE.PENDING, choices=STATE.choices) purchaser = models.ForeignKey( User, on_delete=models.CASCADE, @@ -183,20 +170,34 @@ def is_fulfilled(self): return self.state == Order.STATE.FULFILLED def fulfill(self, payment_data): - """Fulfill this order""" - raise NotImplementedError + """Fufill the order.""" + # record the transaction + try: + self.create_transaction(payment_data) + + # trigger post-sale events + transaction.on_commit(self.handle_post_sale) + + # send the receipt emails + transaction.on_commit(self.send_ecommerce_order_receipt) + + self.state = Order.STATE.FULFILLED + self.save() + except Exception as e: + self.state = Order.STATE.ERRORED + self.save() def cancel(self): """Cancel this order""" - raise NotImplementedError + self.state = Order.STATE.CANCELED + self.save() def decline(self): """Decline this order""" - raise NotImplementedError + self.state = Order.STATE.DECLINED + self.save() - def review(self): - """Place order in review""" - raise NotImplementedError + return self def errored(self): """Error this order""" @@ -225,11 +226,7 @@ def __str__(self): def decode_reference_number(refno): """Decode the reference number""" return re.sub(rf"^.*-{settings.ENVIRONMENT}-", "", refno) - - -class FulfillableOrder: - """class to handle common logics like fulfill, enrollment etc""" - + def create_transaction(self, payment_data): """ Create the transaction record for the order. This contains payment @@ -272,23 +269,7 @@ def send_ecommerce_order_receipt(self): TODO: add email """ - - def fulfill(self, payment_data): - """Fufill the order.""" - # record the transaction - self.create_transaction(payment_data) - - # trigger post-sale events - transaction.on_commit(self.handle_post_sale) - - # send the receipt emails - transaction.on_commit(self.send_ecommerce_order_receipt) - - self.state = Order.STATE.FULFILLED - self.save() - - -class PendingOrder(FulfillableOrder, Order): +class PendingOrder(Order): """An order that is pending payment""" @transaction.atomic @@ -307,48 +288,52 @@ def _get_or_create(self, products: list[Product], user: User): Returns: PendingOrder: the retrieved or created PendingOrder. """ - # Get the details from each Product. - product_versions = [ - Version.objects.get_for_object(product).first() for product in products - ] - - # Get or create a PendingOrder - # TODO: we prefetched the discounts here - orders = Order.objects.select_for_update().filter( - lines__product_version__in=product_versions, - state=Order.STATE.PENDING, - purchaser=user, - ) - # Previously, multiple PendingOrders could be created for a single user - # for the same product, if multiple exist, grab the first. - if orders: - order = orders.first() - # TODO: this should clear discounts from the order here - - order.refresh_from_db() - else: - order = Order.objects.create( + try: + # Get the details from each Product. + product_versions = [ + Version.objects.get_for_object(product).first() for product in products + ] + + # Get or create a PendingOrder + # TODO: we prefetched the discounts here + orders = Order.objects.select_for_update().filter( + lines__product_version__in=product_versions, state=Order.STATE.PENDING, purchaser=user, - total_price_paid=0, - ) - - # TODO: Apply any discounts to the PendingOrder - - # Create or get Line for each product. - # Calculate the Order total based on Lines and discount. - total = 0 - for i, _ in enumerate(products): - line, _ = order.lines.get_or_create( - order=order, - defaults={ - "product_version": product_versions[i], - "quantity": 1, - }, ) - total += line.discounted_price - - order.total_price_paid = total + # Previously, multiple PendingOrders could be created for a single user + # for the same product, if multiple exist, grab the first. + if orders: + order = orders.first() + # TODO: this should clear discounts from the order here + + order.refresh_from_db() + else: + order = Order.objects.create( + state=Order.STATE.PENDING, + purchaser=user, + total_price_paid=0, + ) + + # TODO: Apply any discounts to the PendingOrder + + # Create or get Line for each product. + # Calculate the Order total based on Lines and discount. + total = 0 + for i, _ in enumerate(products): + line, _ = order.lines.get_or_create( + order=order, + defaults={ + "product_version": product_versions[i], + "quantity": 1, + }, + ) + total += line.discounted_price + + order.total_price_paid = total + + except Exception as e: + order.state = Order.STATE.ERRORED order.save() @@ -384,21 +369,6 @@ def create_from_product(cls, product: Product, user: User): return cls._get_or_create(cls, [product], user) - def cancel(self): - """Cancel this order""" - self.state = Order.STATE.CANCELED - self.save() - - def decline(self): - """ - Decline this order. This additionally clears the discount redemptions - for the order so the discounts can be reused. - """ - self.state = Order.STATE.DECLINED - self.save() - - return self - class Meta: """Model meta options""" @@ -408,12 +378,6 @@ class Meta: class FulfilledOrder(Order): """An order that has a fulfilled payment""" - @transition( - field="state", - source=Order.STATE.FULFILLED, - target=Order.STATE.REFUNDED, - custom={"admin": False}, - ) def refund(self, *, api_response_data: dict | None = None, **kwargs): """ Record the refund, then trigger any post-refund events. @@ -429,31 +393,35 @@ def refund(self, *, api_response_data: dict | None = None, **kwargs): Returns: - Object (Transaction): the refund transaction object for the refund. """ - amount = kwargs.get("amount") - reason = kwargs.get("reason") - - transaction_id = api_response_data.get("id") - if transaction_id is None: - exception_message = ( - "Failed to record transaction: Missing transaction id" - " from refund API response" + try: + amount = kwargs.get("amount") + reason = kwargs.get("reason") + + transaction_id = api_response_data.get("id") + if transaction_id is None: + exception_message = ( + "Failed to record transaction: Missing transaction id" + " from refund API response" + ) + raise ValidationError(exception_message) + + refund_transaction, _ = self.transactions.get_or_create( + transaction_id=transaction_id, + data=api_response_data, + amount=amount, + transaction_type=TRANSACTION_TYPE_REFUND, + reason=reason, ) - raise ValidationError(exception_message) - - refund_transaction, _ = self.transactions.get_or_create( - transaction_id=transaction_id, - data=api_response_data, - amount=amount, - transaction_type=TRANSACTION_TYPE_REFUND, - reason=reason, - ) - self.state = Order.STATE.REFUNDED - self.save() + self.state = Order.STATE.REFUNDED + self.save() - # TODO: send_order_refund_email.delay(self.id) - # (and any other post-refund events) + # TODO: send_order_refund_email.delay(self.id) + # (and any other post-refund events) - return refund_transaction + return refund_transaction + except Exception as e: + self.state = Order.STATE.ERRORED + self.save() class Meta: """Model meta options.""" @@ -461,7 +429,7 @@ class Meta: proxy = True -class ReviewOrder(FulfillableOrder, Order): +class ReviewOrder(Order): """An order that has been placed under review by the payment processor.""" class Meta: From 1cc3111a02d70692b04d93dcb2fbeb4f6f088666 Mon Sep 17 00:00:00 2001 From: CP Date: Mon, 23 Sep 2024 13:03:33 -0400 Subject: [PATCH 3/8] minor updates --- payments/models.py | 49 +++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/payments/models.py b/payments/models.py index eb5a93d9..0a98d0e7 100644 --- a/payments/models.py +++ b/payments/models.py @@ -184,8 +184,7 @@ def fulfill(self, payment_data): self.state = Order.STATE.FULFILLED self.save() except Exception as e: - self.state = Order.STATE.ERRORED - self.save() + self.errored() def cancel(self): """Cancel this order""" @@ -232,27 +231,30 @@ def create_transaction(self, payment_data): Create the transaction record for the order. This contains payment processor-specific data. """ - transaction_id = payment_data.get("transaction_id") - amount = payment_data.get("amount") - # There are two use cases: - # No payment required - no cybersource involved, so we need to generate - # a UUID as transaction id - # Payment STATE_ACCEPTED - there should always be transaction_id in payment - # data, if not, throw ValidationError - if amount == 0 and transaction_id is None: - transaction_id = uuid.uuid1() - elif transaction_id is None: - exception_message = ( - "Failed to record transaction: Missing transaction id" - " from payment API response" - ) - raise ValidationError(exception_message) + try: + transaction_id = payment_data.get("transaction_id") + amount = payment_data.get("amount") + # There are two use cases: + # No payment required - no cybersource involved, so we need to generate + # a UUID as transaction id + # Payment STATE_ACCEPTED - there should always be transaction_id in payment + # data, if not, throw ValidationError + if amount == 0 and transaction_id is None: + transaction_id = uuid.uuid1() + elif transaction_id is None: + exception_message = ( + "Failed to record transaction: Missing transaction id" + " from payment API response" + ) + raise ValidationError(exception_message) - self.transactions.get_or_create( - transaction_id=transaction_id, - data=payment_data, - amount=self.total_price_paid, - ) + self.transactions.get_or_create( + transaction_id=transaction_id, + data=payment_data, + amount=self.total_price_paid, + ) + except Exception as e: + self.errored() def handle_post_sale(self): """ @@ -420,8 +422,7 @@ def refund(self, *, api_response_data: dict | None = None, **kwargs): return refund_transaction except Exception as e: - self.state = Order.STATE.ERRORED - self.save() + self.errored() class Meta: """Model meta options.""" From 04010da9ead5f9b8a6cd81b0d45439becd28c56b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:05:30 +0000 Subject: [PATCH 4/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- payments/migrations/0003_alter_order_state.py | 20 ++++++++--- payments/models.py | 33 +++++++++++-------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/payments/migrations/0003_alter_order_state.py b/payments/migrations/0003_alter_order_state.py index 737f81bb..35d9e677 100644 --- a/payments/migrations/0003_alter_order_state.py +++ b/payments/migrations/0003_alter_order_state.py @@ -4,15 +4,25 @@ class Migration(migrations.Migration): - dependencies = [ - ('payments', '0002_remove_system_slug_from_basket'), + ("payments", "0002_remove_system_slug_from_basket"), ] operations = [ migrations.AlterField( - model_name='order', - name='state', - field=models.CharField(choices=[('pending', 'Pending'), ('fulfilled', 'Fulfilled'), ('canceled', 'Canceled'), ('refunded', 'Refunded'), ('declined', 'Declined'), ('errored', 'Errored'), ('review', 'Review')], default='pending'), + model_name="order", + name="state", + field=models.CharField( + choices=[ + ("pending", "Pending"), + ("fulfilled", "Fulfilled"), + ("canceled", "Canceled"), + ("refunded", "Refunded"), + ("declined", "Declined"), + ("errored", "Errored"), + ("review", "Review"), + ], + default="pending", + ), ), ] diff --git a/payments/models.py b/payments/models.py index 0a98d0e7..6e31e264 100644 --- a/payments/models.py +++ b/payments/models.py @@ -10,7 +10,6 @@ from django.core.exceptions import ValidationError from django.db import models, transaction from django.utils.functional import cached_property -from django_fsm import FSMField, transition from mitol.common.models import TimestampedModel from reversion.models import Version @@ -109,6 +108,7 @@ class Order(TimestampedModel): class STATE: """Possible states for an order.""" + PENDING = "pending" FULFILLED = "fulfilled" CANCELED = "canceled" @@ -117,14 +117,16 @@ class STATE: REFUNDED = "refunded" REVIEW = "review" PARTIALLY_REFUNDED = "partially_refunded" - - choices = [(PENDING, "Pending"), - (FULFILLED, "Fulfilled"), - (CANCELED, "Canceled"), - (REFUNDED, "Refunded"), - (DECLINED, "Declined"), - (ERRORED, "Errored"), - (REVIEW, "Review")] + + choices = [ + (PENDING, "Pending"), + (FULFILLED, "Fulfilled"), + (CANCELED, "Canceled"), + (REFUNDED, "Refunded"), + (DECLINED, "Declined"), + (ERRORED, "Errored"), + (REVIEW, "Review"), + ] state = models.CharField(default=STATE.PENDING, choices=STATE.choices) purchaser = models.ForeignKey( @@ -183,7 +185,7 @@ def fulfill(self, payment_data): self.state = Order.STATE.FULFILLED self.save() - except Exception as e: + except Exception: self.errored() def cancel(self): @@ -225,7 +227,7 @@ def __str__(self): def decode_reference_number(refno): """Decode the reference number""" return re.sub(rf"^.*-{settings.ENVIRONMENT}-", "", refno) - + def create_transaction(self, payment_data): """ Create the transaction record for the order. This contains payment @@ -253,7 +255,7 @@ def create_transaction(self, payment_data): data=payment_data, amount=self.total_price_paid, ) - except Exception as e: + except Exception: self.errored() def handle_post_sale(self): @@ -271,6 +273,8 @@ def send_ecommerce_order_receipt(self): TODO: add email """ + + class PendingOrder(Order): """An order that is pending payment""" @@ -334,7 +338,7 @@ def _get_or_create(self, products: list[Product], user: User): order.total_price_paid = total - except Exception as e: + except Exception: order.state = Order.STATE.ERRORED order.save() @@ -421,7 +425,7 @@ def refund(self, *, api_response_data: dict | None = None, **kwargs): # (and any other post-refund events) return refund_transaction - except Exception as e: + except Exception: self.errored() class Meta: @@ -471,6 +475,7 @@ class DeclinedOrder(Order): The state of this can't be altered further. """ + class Meta: """Model meta options.""" From 2336d09e14d583c4f9eed8089eab24d2fe944dfc Mon Sep 17 00:00:00 2001 From: CP Date: Mon, 23 Sep 2024 13:14:29 -0400 Subject: [PATCH 5/8] updates, lint --- payments/models.py | 12 ++++++------ poetry.lock | 10 +++++----- pyproject.toml | 1 - 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/payments/models.py b/payments/models.py index 0a98d0e7..d6c3531e 100644 --- a/payments/models.py +++ b/payments/models.py @@ -183,7 +183,7 @@ def fulfill(self, payment_data): self.state = Order.STATE.FULFILLED self.save() - except Exception as e: + except Exception as e: # pylint: disable=broad-except # noqa: BLE001 self.errored() def cancel(self): @@ -246,14 +246,14 @@ def create_transaction(self, payment_data): "Failed to record transaction: Missing transaction id" " from payment API response" ) - raise ValidationError(exception_message) + raise ValidationError(exception_message) # noqa: RSE102, TRY301 self.transactions.get_or_create( transaction_id=transaction_id, data=payment_data, amount=self.total_price_paid, ) - except Exception as e: + except Exception as e: # pylint: disable=broad-except # noqa: BLE001 self.errored() def handle_post_sale(self): @@ -334,7 +334,7 @@ def _get_or_create(self, products: list[Product], user: User): order.total_price_paid = total - except Exception as e: + except Exception as e: # pylint: disable=broad-except # noqa: BLE001 order.state = Order.STATE.ERRORED order.save() @@ -405,7 +405,7 @@ def refund(self, *, api_response_data: dict | None = None, **kwargs): "Failed to record transaction: Missing transaction id" " from refund API response" ) - raise ValidationError(exception_message) + raise ValidationError(exception_message) # noqa: RSE102, TRY301 refund_transaction, _ = self.transactions.get_or_create( transaction_id=transaction_id, @@ -421,7 +421,7 @@ def refund(self, *, api_response_data: dict | None = None, **kwargs): # (and any other post-refund events) return refund_transaction - except Exception as e: + except Exception as e: # pylint: disable=broad-except # noqa: BLE001 self.errored() class Meta: diff --git a/poetry.lock b/poetry.lock index faba2637..4837e149 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand. [[package]] name = "amqp" @@ -1050,13 +1050,13 @@ Django = ">=3.2" [[package]] name = "django-fsm" -version = "2.8.2" +version = "3.0.0" description = "Django friendly finite state machine support." optional = false python-versions = "*" files = [ - {file = "django-fsm-2.8.2.tar.gz", hash = "sha256:fe3be8fa916470360632b2a86aefcb342d67916fa4c5749caaa7760f88c0c49c"}, - {file = "django_fsm-2.8.2-py2.py3-none-any.whl", hash = "sha256:0b4d346a8de1c2c30c2206ced649e25695f567c072358030544a604fc937d235"}, + {file = "django-fsm-3.0.0.tar.gz", hash = "sha256:0112bcac573ad14051cf8ebe73bf296b6d5409f093e5f1677eb16e2196e263b3"}, + {file = "django_fsm-3.0.0-py2.py3-none-any.whl", hash = "sha256:fa28f84f47eae7ce9247585ac6c1895e4ada08efff93fb243a59e9ff77b2d4ec"}, ] [[package]] @@ -4126,4 +4126,4 @@ testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"] [metadata] lock-version = "2.0" python-versions = "^3.11.0" -content-hash = "6089bf6b57fa14d5a5481e7fada46c92b31f1e9f90b747313ca3586442e84dd9" +content-hash = "4e547569aee2e5f6b5210c679d32c39f4bf9c73885a7db91838cffe9998a8c2f" diff --git a/pyproject.toml b/pyproject.toml index 7d9dde2b..15d4b9c2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -75,7 +75,6 @@ mitol-django-common = "^2023.12.19" mitol-django-payment-gateway = "^2023.12.19" deepdiff = "^6.7.1" django-safedelete = "^1.3.3" -django-fsm = "^2.8.1" django-fsm-admin-maintained = {git = "https://github.com/7tg/django-fsm-admin-django-4.git"} python-slugify = "^8.0.1" django-oauth-toolkit = "^2.3.0" From 351d6c84db15c908b2e66bb256faa113441c42c6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:15:30 +0000 Subject: [PATCH 6/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- payments/models.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/payments/models.py b/payments/models.py index 0f10a34c..bb551b2d 100644 --- a/payments/models.py +++ b/payments/models.py @@ -185,7 +185,7 @@ def fulfill(self, payment_data): self.state = Order.STATE.FULFILLED self.save() - except Exception as e: # pylint: disable=broad-except # noqa: BLE001 + except Exception: # pylint: disable=broad-except # noqa: BLE001 self.errored() def cancel(self): @@ -248,14 +248,14 @@ def create_transaction(self, payment_data): "Failed to record transaction: Missing transaction id" " from payment API response" ) - raise ValidationError(exception_message) # noqa: RSE102, TRY301 + raise ValidationError(exception_message) # noqa: TRY301 self.transactions.get_or_create( transaction_id=transaction_id, data=payment_data, amount=self.total_price_paid, ) - except Exception as e: # pylint: disable=broad-except # noqa: BLE001 + except Exception: # pylint: disable=broad-except # noqa: BLE001 self.errored() def handle_post_sale(self): @@ -338,7 +338,7 @@ def _get_or_create(self, products: list[Product], user: User): order.total_price_paid = total - except Exception as e: # pylint: disable=broad-except # noqa: BLE001 + except Exception: # pylint: disable=broad-except # noqa: BLE001 order.state = Order.STATE.ERRORED order.save() @@ -409,7 +409,7 @@ def refund(self, *, api_response_data: dict | None = None, **kwargs): "Failed to record transaction: Missing transaction id" " from refund API response" ) - raise ValidationError(exception_message) # noqa: RSE102, TRY301 + raise ValidationError(exception_message) # noqa: TRY301 refund_transaction, _ = self.transactions.get_or_create( transaction_id=transaction_id, @@ -425,7 +425,7 @@ def refund(self, *, api_response_data: dict | None = None, **kwargs): # (and any other post-refund events) return refund_transaction - except Exception as e: # pylint: disable=broad-except # noqa: BLE001 + except Exception: # pylint: disable=broad-except # noqa: BLE001 self.errored() class Meta: From 5b0668b333f51f31c367e4a32464c83b30f499a7 Mon Sep 17 00:00:00 2001 From: CP Date: Mon, 23 Sep 2024 13:17:34 -0400 Subject: [PATCH 7/8] updated --- payments/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/payments/models.py b/payments/models.py index 0f10a34c..edc2aa51 100644 --- a/payments/models.py +++ b/payments/models.py @@ -424,7 +424,7 @@ def refund(self, *, api_response_data: dict | None = None, **kwargs): # TODO: send_order_refund_email.delay(self.id) # (and any other post-refund events) - return refund_transaction + return refund_transaction # noqa: TRY300 except Exception as e: # pylint: disable=broad-except # noqa: BLE001 self.errored() From 2738624360a1796702c4a25bf9651c7562881034 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:18:01 +0000 Subject: [PATCH 8/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- payments/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/payments/models.py b/payments/models.py index 5acd0073..4ac9855b 100644 --- a/payments/models.py +++ b/payments/models.py @@ -425,7 +425,7 @@ def refund(self, *, api_response_data: dict | None = None, **kwargs): # (and any other post-refund events) return refund_transaction # noqa: TRY300 - except Exception as e: # pylint: disable=broad-except # noqa: BLE001 + except Exception: # pylint: disable=broad-except # noqa: BLE001 self.errored() class Meta: