From b3a92a4a9a03f7f00badeab02287be76de9081bf Mon Sep 17 00:00:00 2001 From: Laurence Cope Date: Wed, 1 May 2024 00:27:35 +0100 Subject: [PATCH] Revert "Fix stripe api breaking change in plugin. (#14951)" This reverts commit 692be3196ab48b78b9580a90a7682a90cb1d5fb4. --- .../gateways/stripe/tests/test_webhooks.py | 44 ------------------- saleor/payment/gateways/stripe/webhooks.py | 13 +----- 2 files changed, 1 insertion(+), 56 deletions(-) diff --git a/saleor/payment/gateways/stripe/tests/test_webhooks.py b/saleor/payment/gateways/stripe/tests/test_webhooks.py index 207600ca1485..229b906f8345 100644 --- a/saleor/payment/gateways/stripe/tests/test_webhooks.py +++ b/saleor/payment/gateways/stripe/tests/test_webhooks.py @@ -1260,50 +1260,6 @@ def test_handle_refund_already_processed( assert payment.captured_amount == payment.total - Decimal("10") -@patch("saleor.payment.gateways.stripe.webhooks.stripe.Charge.retrieve") -def test_handle_refund_missing_refunds( - charge_retrieve, stripe_plugin, payment_stripe_for_order, channel_USD -): - # given - payment = payment_stripe_for_order - payment.captured_amount = payment.total - payment.save() - payment.transactions.create( - is_success=True, - action_required=True, - kind=TransactionKind.CAPTURE, - amount=payment.total, - currency=payment.currency, - token="ABC", - gateway_response={}, - ) - plugin = stripe_plugin() - - charge = StripeObject() - charge["payment_intent"] = "ABC" - - refund = StripeObject(id="refund_id") - refund["amount"] = price_to_minor_unit(payment.total, payment.currency) - refund["currency"] = payment.currency - refund["last_response"] = None - - charge_retrieve_obj = charge - charge_retrieve_obj["refunds"] = StripeObject() - charge_retrieve_obj["refunds"]["data"] = [refund] - - charge_retrieve.return_value = charge_retrieve_obj - - # when - handle_refund(charge, plugin.config, channel_USD.slug) - - # then - payment.refresh_from_db() - - assert payment.charge_status == ChargeStatus.FULLY_REFUNDED - assert payment.is_active is False - assert payment.captured_amount == Decimal("0") - - @pytest.mark.parametrize("called", [True, False]) @patch( "saleor.payment.gateways.stripe.webhooks._update_payment_with_new_transaction", diff --git a/saleor/payment/gateways/stripe/webhooks.py b/saleor/payment/gateways/stripe/webhooks.py index 7f5acb6938ff..8f181d0f8dfd 100644 --- a/saleor/payment/gateways/stripe/webhooks.py +++ b/saleor/payment/gateways/stripe/webhooks.py @@ -1,7 +1,6 @@ import logging from typing import Optional, cast -import stripe from django.core.exceptions import ValidationError from django.core.handlers.wsgi import WSGIRequest from django.db.models import Prefetch @@ -497,21 +496,11 @@ def handle_successful_payment_intent( def handle_refund( - charge: StripeObject, gateway_config: "GatewayConfig", channel_slug: str + charge: StripeObject, _gateway_config: "GatewayConfig", channel_slug: str ): payment_intent_id = charge.payment_intent payment = _get_payment(payment_intent_id) - # stripe introduced breaking change and in newer version of api - # charge object doesn't contain refunds by default - if not getattr(charge, "refunds", None): - api_key = gateway_config.connection_params["secret_api_key"] - charge_with_refunds = stripe.Charge.retrieve( - charge.stripe_id, - api_key=api_key, - expand=["refunds"], - ) - charge.refunds = charge_with_refunds.refunds refund = charge.refunds.data[0] if not payment: logger.warning(