Skip to content

Commit

Permalink
Revert "Fix stripe api breaking change in plugin. (saleor#14951)"
Browse files Browse the repository at this point in the history
This reverts commit 692be31.
  • Loading branch information
amityweb committed Apr 30, 2024
1 parent 5416b4b commit b3a92a4
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 56 deletions.
44 changes: 0 additions & 44 deletions saleor/payment/gateways/stripe/tests/test_webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 1 addition & 12 deletions saleor/payment/gateways/stripe/webhooks.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit b3a92a4

Please sign in to comment.