Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add plugin_manager parameter to payment gateways methods
IKarbowiak0aab32944981
diff --git a/saleor/checkout/checkout_cleaner.py b/saleor/checkout/checkout_cleaner.pyindex 536e26ac31..8ae2206263 100644--- a/saleor/checkout/checkout_cleaner.py+++ b/saleor/checkout/checkout_cleaner.py@@ -74,7 +74,7 @@ def clean_checkout_payment():clean_billing_address(checkout_info, error_code)if not is_fully_paid(manager, checkout_info, lines, discounts):- gateway.payment_refund_or_void(last_payment)+ gateway.payment_refund_or_void(last_payment, manager)raise ValidationError("Provided payment methods can not cover the checkout's total amount",code=error_code.CHECKOUT_NOT_FULLY_PAID.value,diff --git a/saleor/checkout/complete_checkout.py b/saleor/checkout/complete_checkout.pyindex cea971cf14..c7bfa9e82c 100644--- a/saleor/checkout/complete_checkout.py+++ b/saleor/checkout/complete_checkout.py@@ -519,14 +519,14 @@ def _process_payment("""Process the payment assigned to checkout."""try:if payment.to_confirm:- txn = gateway.confirm(payment, additional_data=payment_data)+ txn = gateway.confirm(payment, plugin_manager, additional_data=payment_data)else:txn = gateway.process_payment(payment=payment,token=payment.token,+ plugin_manager=plugin_manager,store_source=store_source,additional_data=payment_data,- plugin_manager=plugin_manager,)payment.refresh_from_db()if not txn.is_success:@@ -570,7 +570,7 @@ def complete_checkout(try:order_data = _get_order_data(manager, checkout_info, lines, discounts)except ValidationError as exc:- gateway.payment_refund_or_void(payment)+ gateway.payment_refund_or_void(payment, manager)raise exctxn = _process_payment(@@ -601,7 +601,7 @@ def complete_checkout(checkout.delete()except InsufficientStock as e:release_voucher_usage(order_data)- gateway.payment_refund_or_void(payment)+ gateway.payment_refund_or_void(payment, manager)error = prepare_insufficient_stock_checkout_validation_error(e)raise errorreturn order, action_required, action_datadiff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.pyindex bf89a192cb..871f0f1500 100644--- a/saleor/core/utils/random_data.py+++ b/saleor/core/utils/random_data.py@@ -544,21 +544,22 @@ def create_fake_payment(mock_email_confirmation, order):total=order.total.gross.amount,currency=order.total.gross.currency,)+ manager = get_plugins_manager()# Create authorization transaction- gateway.authorize(payment, payment.token)+ gateway.authorize(payment, payment.token, manager)# 20% chance to void the transaction at this stageif random.choice([0, 0, 0, 0, 1]):- gateway.void(payment)+ gateway.void(payment, manager)return payment# 25% to end the payment at the authorization stageif not random.choice([1, 1, 1, 0]):return payment# Create capture transaction- gateway.capture(payment)+ gateway.capture(payment, manager)# 25% to refund the paymentif random.choice([0, 0, 0, 1]):- gateway.refund(payment)+ gateway.refund(payment, manager)return paymentdiff --git a/saleor/graphql/account/resolvers.py b/saleor/graphql/account/resolvers.pyindex a820f61d0e..4c4338f98c 100644--- a/saleor/graphql/account/resolvers.py+++ b/saleor/graphql/account/resolvers.py@@ -111,15 +111,17 @@ def resolve_address_validation_rules()-def resolve_payment_sources(user: models.User):+def resolve_payment_sources(info, user: models.User):+ manager = info.context.pluginsstored_customer_accounts = (- (gtw.id, fetch_customer_id(user, gtw.id)) for gtw in gateway.list_gateways()+ (gtw.id, fetch_customer_id(user, gtw.id))+ for gtw in gateway.list_gateways(manager))return list(chain(*[prepare_graphql_payment_sources_type(- gateway.list_payment_sources(gtw, customer_id)+ gateway.list_payment_sources(gtw, customer_id, manager))for gtw, customer_id in stored_customer_accountsif customer_id is not Nonediff --git a/saleor/graphql/account/types.py b/saleor/graphql/account/types.pyindex a24bbdeb8c..77a2733e0e 100644--- a/saleor/graphql/account/types.py+++ b/saleor/graphql/account/types.py@@ -352,7 +352,7 @@ class User(CountableDjangoObjectType):from .resolvers import resolve_payment_sourcesif root == info.context.user:- return resolve_payment_sources(root)+ return resolve_payment_sources(info, root)raise PermissionDenied()@staticmethoddiff --git a/saleor/graphql/checkout/tests/test_checkout_complete.py b/saleor/graphql/checkout/tests/test_checkout_complete.pyindex 2e29deadb2..23d39127c3 100644--- a/saleor/graphql/checkout/tests/test_checkout_complete.py+++ b/saleor/graphql/checkout/tests/test_checkout_complete.py@@ -1,5 +1,5 @@from decimal import Decimal-from unittest.mock import patch+from unittest.mock import ANY, patchimport grapheneimport pytest@@ -779,7 +779,7 @@ def test_checkout_complete_insufficient_stock_payment_refunded(assert data["checkoutErrors"][0]["message"] == "Insufficient product stock: 123"assert orders_count == Order.objects.count()- gateway_refund_mock.assert_called_once_with(payment)+ gateway_refund_mock.assert_called_once_with(payment, ANY)@patch("saleor.checkout.complete_checkout.gateway.void")@@ -834,7 +834,7 @@ def test_checkout_complete_insufficient_stock_payment_voided(assert data["checkoutErrors"][0]["message"] == "Insufficient product stock: 123"assert orders_count == Order.objects.count()- gateway_void_mock.assert_called_once_with(payment)+ gateway_void_mock.assert_called_once_with(payment, ANY)def test_checkout_complete_without_redirect_url(@@ -956,7 +956,7 @@ def test_checkout_complete_payment_payment_total_different_than_checkout()assert orders_count == Order.objects.count()- gateway_refund_or_void_mock.assert_called_with(payment)+ gateway_refund_or_void_mock.assert_called_with(payment, ANY)def test_order_already_exists(diff --git a/saleor/graphql/order/mutations/orders.py b/saleor/graphql/order/mutations/orders.pyindex ebc395d465..d4f09aefed 100644--- a/saleor/graphql/order/mutations/orders.py+++ b/saleor/graphql/order/mutations/orders.py@@ -433,7 +433,13 @@ class OrderCapture(BaseMutation):clean_order_capture(payment)transaction = try_payment_action(- order, info.context.user, payment, gateway.capture, payment, amount+ order,+ info.context.user,+ payment,+ gateway.capture,+ payment,+ info.context.plugins,+ amount,)# Confirm that we changed the status to capture. Some payment can receive# asynchronous webhook with update status@@ -463,7 +469,12 @@ class OrderVoid(BaseMutation):clean_void_payment(payment)transaction = try_payment_action(- order, info.context.user, payment, gateway.void, payment+ order,+ info.context.user,+ payment,+ gateway.void,+ payment,+ info.context.plugins,)# Confirm that we changed the status to void. Some payment can receive# asynchronous webhook with update status@@ -504,7 +515,13 @@ class OrderRefund(BaseMutation):clean_refund_payment(payment)transaction = try_payment_action(- order, info.context.user, payment, gateway.refund, payment, amount+ order,+ info.context.user,+ payment,+ gateway.refund,+ payment,+ info.context.plugins,+ amount,)# Confirm that we changed the status to refund. Some payment can receive@@ -553,7 +570,7 @@ class OrderConfirm(ModelMutation):payment = order.get_last_payment()manager = info.context.pluginsif payment and payment.is_authorized and payment.can_capture():- gateway.capture(payment)+ gateway.capture(payment, info.context.plugins)order_captured(order, info.context.user, payment.total, payment, manager)order_confirmed(order, info.context.user, manager, send_confirmation_email=True)return OrderConfirm(order=order)diff --git a/saleor/graphql/order/tests/test_fulfillment_refund_products.py b/saleor/graphql/order/tests/test_fulfillment_refund_products.pyindex c16b5a866d..3a187572ac 100644--- a/saleor/graphql/order/tests/test_fulfillment_refund_products.py+++ b/saleor/graphql/order/tests/test_fulfillment_refund_products.py@@ -1,5 +1,5 @@from decimal import Decimal-from unittest.mock import patch+from unittest.mock import ANY, patchimport graphenefrom prices import Money, TaxedMoney@@ -81,7 +81,7 @@ def test_fulfillment_refund_products_amount_and_shipping_costs(staff_api_client.post_graphql(ORDER_FULFILL_REFUND_MUTATION, variables)mocked_refund.assert_called_with(- payment_dummy, quantize_price(amount_to_refund, fulfilled_order.currency)+ payment_dummy, ANY, quantize_price(amount_to_refund, fulfilled_order.currency))@@ -117,7 +117,7 @@ def test_fulfillment_refund_products_order_lines(assert refund_fulfillment["lines"][0]["orderLine"]["id"] == line_idassert refund_fulfillment["lines"][0]["quantity"] == 2mocked_refund.assert_called_with(- payment_dummy, line_to_refund.unit_price_gross_amount * 2+ payment_dummy, ANY, line_to_refund.unit_price_gross_amount * 2)@@ -222,7 +222,9 @@ def test_fulfillment_refund_products_fulfillment_lines(assert refund_fulfillment["lines"][0]["orderLine"]["id"] == order_line_idassert refund_fulfillment["lines"][0]["quantity"] == 2mocked_refund.assert_called_with(- payment_dummy, fulfillment_line_to_refund.order_line.unit_price_gross_amount * 2+ payment_dummy,+ ANY,+ fulfillment_line_to_refund.order_line.unit_price_gross_amount * 2,)@@ -339,7 +341,7 @@ def test_fulfillment_refund_products_fulfillment_lines_include_shipping_costs(assert refund_fulfillment["lines"][0]["quantity"] == 2amount = fulfillment_line_to_refund.order_line.unit_price_gross_amount * 2amount += fulfilled_order.shipping_price_gross_amount- mocked_refund.assert_called_with(payment_dummy, amount)+ mocked_refund.assert_called_with(payment_dummy, ANY, amount)@patch("saleor.order.actions.gateway.refund")@@ -378,7 +380,7 @@ def test_fulfillment_refund_products_order_lines_include_shipping_costs(assert refund_fulfillment["lines"][0]["quantity"] == 2amount = line_to_refund.unit_price_gross_amount * 2amount += order_with_lines.shipping_price_gross_amount- mocked_refund.assert_called_with(payment_dummy, amount)+ mocked_refund.assert_called_with(payment_dummy, ANY, amount)@patch("saleor.order.actions.gateway.refund")@@ -424,7 +426,7 @@ def test_fulfillment_refund_products_fulfillment_lines_custom_amount(assert len(refund_fulfillment["lines"]) == 1assert refund_fulfillment["lines"][0]["orderLine"]["id"] == order_line_idassert refund_fulfillment["lines"][0]["quantity"] == 2- mocked_refund.assert_called_with(payment_dummy, amount_to_refund)+ mocked_refund.assert_called_with(payment_dummy, ANY, amount_to_refund)@patch("saleor.order.actions.gateway.refund")@@ -462,7 +464,7 @@ def test_fulfillment_refund_products_order_lines_custom_amount(assert len(refund_fulfillment["lines"]) == 1assert refund_fulfillment["lines"][0]["orderLine"]["id"] == line_idassert refund_fulfillment["lines"][0]["quantity"] == 2- mocked_refund.assert_called_with(payment_dummy, amount_to_refund)+ mocked_refund.assert_called_with(payment_dummy, ANY, amount_to_refund)@patch("saleor.order.actions.gateway.refund")@@ -549,4 +551,4 @@ def test_fulfillment_refund_products_fulfillment_lines_and_order_lines(amount = fulfillment_line_to_refund.order_line.unit_price_gross_amount * 2amount += order_line.unit_price_gross_amount * 2amount = quantize_price(amount, fulfilled_order.currency)- mocked_refund.assert_called_with(payment_dummy, amount)+ mocked_refund.assert_called_with(payment_dummy, ANY, amount)diff --git a/saleor/graphql/order/tests/test_fulfillment_return_products.py b/saleor/graphql/order/tests/test_fulfillment_return_products.pyindex 43ce074f71..784c6e4c0a 100644--- a/saleor/graphql/order/tests/test_fulfillment_return_products.py+++ b/saleor/graphql/order/tests/test_fulfillment_return_products.py@@ -1,5 +1,5 @@from decimal import Decimal-from unittest.mock import patch+from unittest.mock import ANY, patchimport graphenefrom prices import Money, TaxedMoney@@ -108,7 +108,7 @@ def test_fulfillment_return_products_amount_and_shipping_costs(staff_api_client.post_graphql(ORDER_FULFILL_RETURN_MUTATION, variables)mocked_refund.assert_called_with(- payment_dummy, quantize_price(amount_to_refund, fulfilled_order.currency)+ payment_dummy, ANY, quantize_price(amount_to_refund, fulfilled_order.currency))@@ -215,7 +215,7 @@ def test_fulfillment_return_products_order_lines(amount = line_to_return.unit_price_gross_amount * line_quantity_to_returnamount += order_with_lines.shipping_price_gross_amount- mocked_refund.assert_called_with(payment_dummy, amount)+ mocked_refund.assert_called_with(payment_dummy, ANY, amount)def test_fulfillment_return_products_order_lines_quantity_bigger_than_total(@@ -317,7 +317,7 @@ def test_fulfillment_return_products_order_lines_custom_amount(assert len(return_fulfillment["lines"]) == 1assert return_fulfillment["lines"][0]["orderLine"]["id"] == line_idassert return_fulfillment["lines"][0]["quantity"] == 2- mocked_refund.assert_called_with(payment_dummy, amount_to_refund)+ mocked_refund.assert_called_with(payment_dummy, ANY, amount_to_refund)@patch("saleor.order.actions.gateway.refund")@@ -434,7 +434,7 @@ def test_fulfillment_return_products_fulfillment_lines(* quantity_to_return)amount += fulfilled_order.shipping_price_gross_amount- mocked_refund.assert_called_with(payment_dummy, amount)+ mocked_refund.assert_called_with(payment_dummy, ANY, amount)def test_fulfillment_return_products_fulfillment_lines_quantity_bigger_than_total(@@ -594,7 +594,7 @@ def test_fulfillment_return_products_fulfillment_lines_include_shipping_costs(assert return_fulfillment["lines"][0]["quantity"] == 2amount = fulfillment_line_to_return.order_line.unit_price_gross_amount * 2amount += fulfilled_order.shipping_price_gross_amount- mocked_refund.assert_called_with(payment_dummy, amount)+ mocked_refund.assert_called_with(payment_dummy, ANY, amount)@patch("saleor.order.actions.gateway.refund")@@ -695,4 +695,4 @@ def test_fulfillment_return_products_fulfillment_lines_and_order_lines(amount = order_line.unit_price_gross_amount * 2amount = quantize_price(amount, fulfilled_order.currency)- mocked_refund.assert_called_with(payment_dummy, amount)+ mocked_refund.assert_called_with(payment_dummy, ANY, amount)diff --git a/saleor/graphql/order/tests/test_order.py b/saleor/graphql/order/tests/test_order.pyindex 9917b7178a..1c60071932 100644--- a/saleor/graphql/order/tests/test_order.py+++ b/saleor/graphql/order/tests/test_order.py@@ -817,7 +817,7 @@ def test_order_confirm(type=order_events.OrderEvents.PAYMENT_CAPTURED,parameters__amount=payment_txn_preauth.get_total().amount,).exists()- capture_mock.assert_called_once_with(payment_txn_preauth)+ capture_mock.assert_called_once_with(payment_txn_preauth, ANY)def test_order_confirm_unfulfilled(staff_api_client, order, permission_manage_orders):diff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.pyindex 48ee01dfe8..7c78adce20 100644--- a/saleor/graphql/payment/mutations.py+++ b/saleor/graphql/payment/mutations.py@@ -187,7 +187,7 @@ class PaymentCapture(BaseMutation):info, payment_id, field="payment_id", only_type=Payment)try:- gateway.capture(payment, amount)+ gateway.capture(payment, info.context.plugins, amount)payment.refresh_from_db()except PaymentError as e:raise ValidationError(str(e), code=PaymentErrorCode.PAYMENT_ERROR)@@ -207,7 +207,7 @@ class PaymentRefund(PaymentCapture):info, payment_id, field="payment_id", only_type=Payment)try:- gateway.refund(payment, amount=amount)+ gateway.refund(payment, info.context.plugins, amount=amount)payment.refresh_from_db()except PaymentError as e:raise ValidationError(str(e), code=PaymentErrorCode.PAYMENT_ERROR)@@ -232,7 +232,7 @@ class PaymentVoid(BaseMutation):info, payment_id, field="payment_id", only_type=Payment)try:- gateway.void(payment)+ gateway.void(payment, info.context.plugins)payment.refresh_from_db()except PaymentError as e:raise ValidationError(str(e), code=PaymentErrorCode.PAYMENT_ERROR)diff --git a/saleor/graphql/payment/resolvers.py b/saleor/graphql/payment/resolvers.pyindex 4f435abb9d..55897bb4c8 100644--- a/saleor/graphql/payment/resolvers.py+++ b/saleor/graphql/payment/resolvers.py@@ -1,16 +1,9 @@-from ...payment import gateway as payment_gatewayfrom ...payment import models-from ...payment.utils import fetch_customer_idfrom ..utils.filters import filter_by_query_paramPAYMENT_SEARCH_FIELDS = ["id"]-def resolve_client_token(user, gateway: str):- customer_id = fetch_customer_id(user, gateway)- return payment_gateway.get_client_token(gateway, customer_id)--def resolve_payments(info, query):queryset = models.Payment.objects.all().distinct()return filter_by_query_param(queryset, query, PAYMENT_SEARCH_FIELDS)diff --git a/saleor/graphql/payment/tests/test_payment.py b/saleor/graphql/payment/tests/test_payment.pyindex 837633c675..ebe5018156 100644--- a/saleor/graphql/payment/tests/test_payment.py+++ b/saleor/graphql/payment/tests/test_payment.py@@ -1,6 +1,6 @@import jsonfrom decimal import Decimal-from unittest.mock import patch+from unittest.mock import ANY, patchimport grapheneimport pytest@@ -832,7 +832,7 @@ def test_list_payment_sources()response = user_api_client.post_graphql(query)- mock_get_source_list.assert_called_once_with(gateway, dummy_customer_id)+ mock_get_source_list.assert_called_once_with(gateway, dummy_customer_id, ANY)content = get_graphql_content(response)["data"]["me"]["storedPaymentSources"]assert content is not None and len(content) == 1assert content[0] == {"gateway": gateway, "creditCardInfo": {"lastDigits": "5678"}}diff --git a/saleor/order/actions.py b/saleor/order/actions.pyindex b892bf2075..f42c81955f 100644--- a/saleor/order/actions.py+++ b/saleor/order/actions.py@@ -1126,7 +1126,7 @@ def _process_refund(amount += order.shipping_price_gross_amountif amount:amount = min(payment.captured_amount, amount)- gateway.refund(payment, amount)+ gateway.refund(payment, manager, amount)order_refunded(order, requester, amount, payment, manager=manager)fulfillment_refunded_event(diff --git a/saleor/order/tests/test_order_actions_create_fulfillments_for_returned_products.py b/saleor/order/tests/test_order_actions_create_fulfillments_for_returned_products.pyindex 13f5ab8336..29327cf608 100644--- a/saleor/order/tests/test_order_actions_create_fulfillments_for_returned_products.py+++ b/saleor/order/tests/test_order_actions_create_fulfillments_for_returned_products.py@@ -1,5 +1,5 @@from decimal import Decimal-from unittest.mock import patch+from unittest.mock import ANY, patchfrom prices import Money, TaxedMoney@@ -128,7 +128,7 @@ def test_create_return_fulfillment_only_order_lines_with_refund()amount = sum([line.unit_price_gross_amount * 2 for line in order_lines_to_return])- mocked_refund.assert_called_once_with(payment_dummy_fully_charged, amount)+ mocked_refund.assert_called_once_with(payment_dummy_fully_charged, ANY, amount)assert not replace_order@@ -185,7 +185,7 @@ def test_create_return_fulfillment_only_order_lines_included_shipping_costs(amount = sum([line.unit_price_gross_amount * 2 for line in order_lines_to_return])amount += order_with_lines.shipping_price_gross_amount- mocked_refund.assert_called_once_with(payment_dummy_fully_charged, amount)+ mocked_refund.assert_called_once_with(payment_dummy_fully_charged, ANY, amount)assert not replace_order@@ -339,7 +339,7 @@ def test_create_return_fulfillment_multiple_order_line_returns(for line in order_lines_to_return:assert line.quantity_unfulfilled == original_quantity.get(line.pk) - 2- assert mocked_refund.call_count == 2+ assert mocked_refund.call_count == ANY, 2@patch("saleor.order.actions.gateway.refund")@@ -516,7 +516,7 @@ def test_create_return_fulfillment_multiple_fulfillment_lines_returns(for line in fulfillment_lines:assert line.quantity == original_quantity.get(line.pk) - 2- assert mocked_refund.call_count == 2+ assert mocked_refund.call_count == ANY, 2@patch("saleor.order.actions.gateway.refund")@@ -589,7 +589,7 @@ def test_create_return_fulfillment_multiple_lines_returns(for line in fulfillment_lines:assert line.quantity == original_quantity.get(line.pk) - 2- assert mocked_refund.call_count == 2+ assert mocked_refund.call_count == ANY, 2@patch("saleor.order.actions.gateway.refund")@@ -767,4 +767,4 @@ def test_create_return_fulfillment_with_lines_already_refunded(for line in fulfillment_lines_to_return])- mocked_refund.assert_called_once_with(payment_dummy_fully_charged, amount)+ mocked_refund.assert_called_once_with(payment_dummy_fully_charged, ANY, amount)diff --git a/saleor/order/tests/test_order_actions_refund_products.py b/saleor/order/tests/test_order_actions_refund_products.pyindex 5533526a77..27cc7e3e4b 100644--- a/saleor/order/tests/test_order_actions_refund_products.py+++ b/saleor/order/tests/test_order_actions_refund_products.py@@ -1,5 +1,5 @@from decimal import Decimal-from unittest.mock import patch+from unittest.mock import ANY, patchfrom prices import Money, TaxedMoney@@ -61,7 +61,7 @@ def test_create_refund_fulfillment_only_order_lines(== current_allocation.quantity_allocated)amount = sum([line.unit_price_gross_amount * 2 for line in order_lines_to_refund])- mocked_refund.assert_called_once_with(payment_dummy, amount)+ mocked_refund.assert_called_once_with(payment_dummy, ANY, amount)@patch("saleor.order.actions.gateway.refund")@@ -105,7 +105,7 @@ def test_create_refund_fulfillment_multiple_order_line_refunds(for line in order_lines_to_refund:assert line.quantity_unfulfilled == original_quantity.get(line.pk) - 2- assert mocked_refund.call_count == 2+ assert mocked_refund.call_count == ANY, 2@patch("saleor.order.actions.gateway.refund")@@ -145,7 +145,7 @@ def test_create_refund_fulfillment_included_shipping_costs(assert line.quantity_unfulfilled == original_quantity.get(line.pk) - 2amount = sum([line.unit_price_gross_amount * 2 for line in order_lines_to_refund])amount += order_with_lines.shipping_price_gross_amount- mocked_refund.assert_called_once_with(payment_dummy, amount)+ mocked_refund.assert_called_once_with(payment_dummy, ANY, amount)@patch("saleor.order.actions.gateway.refund")@@ -185,7 +185,7 @@ def test_create_refund_fulfillment_only_fulfillment_lines(amount = sum([line.order_line.unit_price_gross_amount * 2 for line in fulfillment_lines])- mocked_refund.assert_called_once_with(payment_dummy, amount)+ mocked_refund.assert_called_once_with(payment_dummy, ANY, amount)@patch("saleor.order.actions.gateway.refund")@@ -228,7 +228,7 @@ def test_create_refund_fulfillment_multiple_fulfillment_lines_refunds(for line in fulfillment_lines:assert line.quantity == original_quantity.get(line.pk) - 2- assert mocked_refund.call_count == 2+ assert mocked_refund.call_count == ANY, 2@patch("saleor.order.actions.gateway.refund")@@ -268,7 +268,7 @@ def test_create_refund_fulfillment_custom_amount(for line in fulfillment_lines:assert line.quantity == original_quantity.get(line.pk) - 2- mocked_refund.assert_called_once_with(payment_dummy, amount)+ mocked_refund.assert_called_once_with(payment_dummy, ANY, amount)@patch("saleor.order.actions.gateway.refund")@@ -343,4 +343,4 @@ def test_create_refund_fulfillment_multiple_refunds(order_line.refresh_from_db()assert order_line.quantity_fulfilled == 4assert order_line.quantity_unfulfilled == 1- assert mocked_refund.call_count == 2+ assert mocked_refund.call_count == ANY, 2diff --git a/saleor/payment/gateway.py b/saleor/payment/gateway.pyindex 340e234c8c..e03cdaab7d 100644--- a/saleor/payment/gateway.py+++ b/saleor/payment/gateway.py@@ -4,8 +4,6 @@ from typing import TYPE_CHECKING, Callable, List, Optionalfrom django.db import transaction-from ..payment.interface import TokenConfig-from ..plugins.manager import get_plugins_managerfrom . import GatewayError, PaymentError, TransactionKindfrom .models import Payment, Transactionfrom .utils import (@@ -76,12 +74,10 @@ def with_locked_payment(fn: Callable) -> Callable:def process_payment(payment: Payment,token: str,+ plugin_manager: "PluginsManager",store_source: bool = False,additional_data: Optional[dict] = None,- plugin_manager: Optional["PluginsManager"] = None,) -> Transaction:- if not plugin_manager:- plugin_manager = get_plugins_manager()payment_data = create_payment_information(payment=payment,payment_token=token,@@ -109,8 +105,12 @@ def process_payment(@require_active_payment@with_locked_payment@payment_postprocess-def authorize(payment: Payment, token: str, store_source: bool = False) -> Transaction:- plugin_manager = get_plugins_manager()+def authorize(+ payment: Payment,+ token: str,+ plugin_manager: "PluginsManager",+ store_source: bool = False,+) -> Transaction:clean_authorize(payment)payment_data = create_payment_information(payment=payment, payment_token=token, store_source=store_source@@ -135,9 +135,11 @@ def authorize(payment: Payment, token: str, store_source: bool = False) -> Trans@with_locked_payment@payment_postprocessdef capture(- payment: Payment, amount: Decimal = None, store_source: bool = False+ payment: Payment,+ plugin_manager: "PluginsManager",+ amount: Decimal = None,+ store_source: bool = False,) -> Transaction:- plugin_manager = get_plugins_manager()if amount is None:amount = payment.get_charge_amount()clean_capture(payment, Decimal(amount))@@ -163,8 +165,9 @@ def capture(@require_active_payment@with_locked_payment@payment_postprocess-def refund(payment: Payment, amount: Decimal = None) -> Transaction:- plugin_manager = get_plugins_manager()+def refund(+ payment: Payment, plugin_manager: "PluginsManager", amount: Decimal = None+) -> Transaction:if amount is None:amount = payment.captured_amount_validate_refund_amount(payment, amount)@@ -202,8 +205,7 @@ def refund(payment: Payment, amount: Decimal = None) -> Transaction:@require_active_payment@with_locked_payment@payment_postprocess-def void(payment: Payment) -> Transaction:- plugin_manager = get_plugins_manager()+def void(payment: Payment, plugin_manager: "PluginsManager") -> Transaction:token = _get_past_transaction_token(payment, TransactionKind.AUTH)payment_data = create_payment_information(payment=payment, payment_token=token)response, error = _fetch_gateway_response(@@ -222,8 +224,11 @@ def void(payment: Payment) -> Transaction:@require_active_payment@with_locked_payment@payment_postprocess-def confirm(payment: Payment, additional_data: Optional[dict] = None) -> Transaction:- plugin_manager = get_plugins_manager()+def confirm(+ payment: Payment,+ plugin_manager: "PluginsManager",+ additional_data: Optional[dict] = None,+) -> Transaction:txn = payment.transactions.filter(kind=TransactionKind.ACTION_TO_CONFIRM, is_success=True).last()@@ -247,19 +252,14 @@ def confirm(payment: Payment, additional_data: Optional[dict] = None) -> Transac)-def list_payment_sources(gateway: str, customer_id: str) -> List["CustomerSource"]:- plugin_manager = get_plugins_manager()+def list_payment_sources(+ gateway: str, customer_id: str, plugin_manager: "PluginsManager"+) -> List["CustomerSource"]:return plugin_manager.list_payment_sources(gateway, customer_id)-def get_client_token(gateway: str, customer_id: str = None) -> str:- plugin_manager = get_plugins_manager()- token_config = TokenConfig(customer_id=customer_id)- return plugin_manager.get_client_token(gateway, token_config)---def list_gateways() -> List["PaymentGateway"]:- return get_plugins_manager().list_payment_gateways()+def list_gateways(plugin_manager: "PluginsManager") -> List["PaymentGateway"]:+ return plugin_manager.list_payment_gateways()def _fetch_gateway_response(fn, *args, **kwargs):@@ -294,10 +294,12 @@ def _validate_refund_amount(payment: Payment, amount: Decimal):raise PaymentError("Cannot refund more than captured.")-def payment_refund_or_void(payment: Optional[Payment]):+def payment_refund_or_void(+ payment: Optional[Payment], plugin_manager: "PluginsManager"+):if payment is None:returnif payment.can_refund():- refund(payment)+ refund(payment, plugin_manager)elif payment.can_void():- void(payment)+ void(payment, plugin_manager)diff --git a/saleor/payment/gateways/adyen/webhooks.py b/saleor/payment/gateways/adyen/webhooks.pyindex 1e9f4d2a31..128dfe0dbf 100644--- a/saleor/payment/gateways/adyen/webhooks.py+++ b/saleor/payment/gateways/adyen/webhooks.py@@ -169,7 +169,7 @@ def create_order(payment, checkout, manager):user=checkout.user or AnonymousUser(),)except ValidationError:- payment_refund_or_void(payment)+ payment_refund_or_void(payment, manager)return None# Refresh the payment to assign the newly created orderpayment.refresh_from_db()diff --git a/saleor/payment/gateways/dummy/tests/test_dummy.py b/saleor/payment/gateways/dummy/tests/test_dummy.pyindex 9882d255c5..cf53d185c7 100644--- a/saleor/payment/gateways/dummy/tests/test_dummy.py+++ b/saleor/payment/gateways/dummy/tests/test_dummy.py@@ -2,6 +2,7 @@ from decimal import Decimalimport pytest+from .....plugins.manager import get_plugins_managerfrom .... import ChargeStatus, PaymentError, TransactionKind, gateway@@ -12,7 +13,9 @@ def setup_dummy_gateway(settings):def test_authorize_success(payment_dummy):- txn = gateway.authorize(payment=payment_dummy, token="Fake")+ txn = gateway.authorize(+ payment=payment_dummy, token="Fake", plugin_manager=get_plugins_manager()+ )assert txn.is_successassert txn.kind == TransactionKind.AUTHassert txn.payment == payment_dummy@@ -40,14 +43,18 @@ def test_authorize_failed(is_active, charge_status, payment_dummy):payment.charge_status = charge_statuspayment.save()with pytest.raises(PaymentError):- txn = gateway.authorize(payment=payment, token="Fake")+ txn = gateway.authorize(+ payment=payment, token="Fake", plugin_manager=get_plugins_manager()+ )assert txn is Nonedef test_authorize_gateway_error(payment_dummy, monkeypatch):monkeypatch.setattr("saleor.payment.gateways.dummy.dummy_success", lambda: False)with pytest.raises(PaymentError):- txn = gateway.authorize(payment=payment_dummy, token="Fake")+ txn = gateway.authorize(+ payment=payment_dummy, token="Fake", plugin_manager=get_plugins_manager()+ )assert txn.kind == TransactionKind.AUTHassert not txn.is_successassert txn.payment == payment_dummy@@ -56,7 +63,9 @@ def test_authorize_gateway_error(payment_dummy, monkeypatch):def test_void_success(payment_txn_preauth):assert payment_txn_preauth.is_activeassert payment_txn_preauth.charge_status == ChargeStatus.NOT_CHARGED- txn = gateway.void(payment=payment_txn_preauth)+ txn = gateway.void(+ payment=payment_txn_preauth, plugin_manager=get_plugins_manager()+ )assert txn.is_successassert txn.kind == TransactionKind.VOIDassert txn.payment == payment_txn_preauth@@ -85,14 +94,16 @@ def test_void_failed(is_active, charge_status, payment_dummy):payment.charge_status = charge_statuspayment.save()with pytest.raises(PaymentError):- txn = gateway.void(payment=payment)+ txn = gateway.void(payment=payment, plugin_manager=get_plugins_manager())assert txn is Nonedef test_void_gateway_error(payment_txn_preauth, monkeypatch):monkeypatch.setattr("saleor.payment.gateways.dummy.dummy_success", lambda: False)with pytest.raises(PaymentError):- txn = gateway.void(payment=payment_txn_preauth)+ txn = gateway.void(+ payment=payment_txn_preauth, plugin_manager=get_plugins_manager()+ )assert txn.kind == TransactionKind.VOIDassert not txn.is_successassert txn.payment == payment_txn_preauth@@ -103,7 +114,11 @@ def test_void_gateway_error(payment_txn_preauth, monkeypatch):[("98.40", ChargeStatus.FULLY_CHARGED), (70, ChargeStatus.PARTIALLY_CHARGED)],)def test_capture_success(amount, charge_status, payment_txn_preauth):- txn = gateway.capture(payment=payment_txn_preauth, amount=Decimal(amount))+ txn = gateway.capture(+ payment=payment_txn_preauth,+ plugin_manager=get_plugins_manager(),+ amount=Decimal(amount),+ )assert txn.is_successassert txn.payment == payment_txn_preauthpayment_txn_preauth.refresh_from_db()@@ -130,14 +145,18 @@ def test_capture_failed(payment.charge_status = charge_statuspayment.save()with pytest.raises(PaymentError):- txn = gateway.capture(payment=payment, amount=amount)+ txn = gateway.capture(+ payment=payment, plugin_manager=get_plugins_manager(), amount=amount+ )assert txn is Nonedef test_capture_gateway_error(payment_txn_preauth, monkeypatch):monkeypatch.setattr("saleor.payment.gateways.dummy.dummy_success", lambda: False)with pytest.raises(PaymentError):- txn = gateway.capture(payment=payment_txn_preauth, amount=80)+ txn = gateway.capture(+ payment=payment_txn_preauth, plugin_manager=get_plugins_manager(), amount=80+ )assert txn.kind == TransactionKind.CAPTUREassert not txn.is_successassert txn.payment == payment_txn_preauth@@ -165,7 +184,11 @@ def test_refund_success(payment.charge_status = ChargeStatus.FULLY_CHARGEDpayment.captured_amount = initial_captured_amountpayment.save()- txn = gateway.refund(payment=payment, amount=Decimal(refund_amount))+ txn = gateway.refund(+ payment=payment,+ plugin_manager=get_plugins_manager(),+ amount=Decimal(refund_amount),+ )payment.refresh_from_db()assert txn.kind == TransactionKind.REFUND@@ -194,7 +217,11 @@ def test_refund_failed(payment.captured_amount = Decimal(initial_captured_amount)payment.save()with pytest.raises(PaymentError):- txn = gateway.refund(payment=payment, amount=Decimal(refund_amount))+ txn = gateway.refund(+ payment=payment,+ plugin_manager=get_plugins_manager(),+ amount=Decimal(refund_amount),+ )assert txn is None@@ -205,7 +232,11 @@ def test_refund_gateway_error(payment_txn_captured, monkeypatch):payment.captured_amount = Decimal("80.00")payment.save()with pytest.raises(PaymentError):- gateway.refund(payment=payment, amount=Decimal("80.00"))+ gateway.refund(+ payment=payment,+ plugin_manager=get_plugins_manager(),+ amount=Decimal("80.00"),+ )payment.refresh_from_db()txn = payment.transactions.last()diff --git a/saleor/payment/gateways/dummy_credit_card/tests/test_dummy_credit_card.py b/saleor/payment/gateways/dummy_credit_card/tests/test_dummy_credit_card.pyindex e3f32954f1..9f79a0e4e6 100644--- a/saleor/payment/gateways/dummy_credit_card/tests/test_dummy_credit_card.py+++ b/saleor/payment/gateways/dummy_credit_card/tests/test_dummy_credit_card.py@@ -2,6 +2,7 @@ from decimal import Decimalimport pytest+from .....plugins.manager import get_plugins_managerfrom .... import ChargeStatus, PaymentError, TransactionKind, gatewayfrom .. import (PREAUTHORIZED_TOKENS,@@ -34,7 +35,11 @@ def setup_dummy_credit_card_gateway(settings):def test_authorize_success(payment_dummy_credit_card):- txn = gateway.authorize(payment=payment_dummy_credit_card, token="Fake")+ txn = gateway.authorize(+ payment=payment_dummy_credit_card,+ token="Fake",+ plugin_manager=get_plugins_manager(),+ )assert txn.is_successassert txn.kind == TransactionKind.AUTHassert txn.payment == payment_dummy_credit_card@@ -62,7 +67,9 @@ def test_authorize_failed(is_active, charge_status, error, payment_dummy_credit_payment.charge_status = charge_statuspayment.save()with pytest.raises(PaymentError) as e:- gateway.authorize(payment=payment, token="Fake")+ gateway.authorize(+ payment=payment, token="Fake", plugin_manager=get_plugins_manager()+ )assert e._excinfo[1].message == error@@ -72,7 +79,11 @@ def test_authorize_gateway_error(payment_dummy_credit_card, monkeypatch):"saleor.payment.gateways.dummy_credit_card.dummy_success", lambda: False)with pytest.raises(PaymentError) as e:- gateway.authorize(payment=payment_dummy_credit_card, token="Fake")+ gateway.authorize(+ payment=payment_dummy_credit_card,+ token="Fake",+ plugin_manager=get_plugins_manager(),+ )assert e._excinfo[1].message == "Unable to authorize transaction"@@ -98,7 +109,9 @@ def test_void_success(payment_txn_preauth):assert payment_txn_preauth.is_activeassert payment_txn_preauth.charge_status == ChargeStatus.NOT_CHARGED- txn = gateway.void(payment=payment_txn_preauth)+ txn = gateway.void(+ payment=payment_txn_preauth, plugin_manager=get_plugins_manager()+ )assert txn.is_successassert txn.kind == TransactionKind.VOIDassert txn.payment == payment_txn_preauth@@ -127,7 +140,7 @@ def test_void_failed(is_active, charge_status, error, payment_dummy_credit_card)payment.charge_status = charge_statuspayment.save()with pytest.raises(PaymentError) as e:- gateway.void(payment=payment)+ gateway.void(payment=payment, plugin_manager=get_plugins_manager())assert e._excinfo[1].message == error@@ -140,7 +153,7 @@ def test_void_gateway_error(payment_txn_preauth, monkeypatch):"saleor.payment.gateways.dummy_credit_card.dummy_success", lambda: False)with pytest.raises(PaymentError) as e:- gateway.void(payment=payment_txn_preauth)+ gateway.void(payment=payment_txn_preauth, plugin_manager=get_plugins_manager())assert e._excinfo[1].message == "Unable to void the transaction."@@ -175,7 +188,11 @@ def test_capture_success(amount, charge_status, token, payment_txn_preauth):transaction.token = tokentransaction.save()- txn = gateway.capture(payment=payment_txn_preauth, amount=Decimal(amount))+ txn = gateway.capture(+ payment=payment_txn_preauth,+ plugin_manager=get_plugins_manager(),+ amount=Decimal(amount),+ )assert txn.is_successassert txn.payment == payment_txn_preauthassert not txn.error@@ -203,7 +220,9 @@ def test_capture_failed(payment.charge_status = charge_statuspayment.save()with pytest.raises(PaymentError) as e:- gateway.capture(payment=payment, amount=amount)+ gateway.capture(+ payment=payment, plugin_manager=get_plugins_manager(), amount=amount+ )assert e._excinfo[1].message == error@@ -220,7 +239,9 @@ def test_capture_error_in_response(token, error, payment_txn_preauth):# whenwith pytest.raises(PaymentError) as e:- gateway.capture(payment=payment_txn_preauth)+ gateway.capture(+ payment=payment_txn_preauth, plugin_manager=get_plugins_manager()+ )assert e._excinfo[1].message == error@@ -264,7 +285,11 @@ def test_refund_success(payment.charge_status = ChargeStatus.FULLY_CHARGEDpayment.captured_amount = initial_captured_amountpayment.save()- txn = gateway.refund(payment=payment, amount=Decimal(refund_amount))+ txn = gateway.refund(+ payment=payment,+ plugin_manager=get_plugins_manager(),+ amount=Decimal(refund_amount),+ )payment.refresh_from_db()assert txn.kind == TransactionKind.REFUND@@ -297,7 +322,11 @@ def test_refund_failed(payment.captured_amount = Decimal(initial_captured_amount)payment.save()with pytest.raises(PaymentError) as e:- gateway.refund(payment=payment, amount=Decimal(refund_amount))+ gateway.refund(+ payment=payment,+ plugin_manager=get_plugins_manager(),+ amount=Decimal(refund_amount),+ )assert e._excinfo[1].message == error@@ -312,7 +341,11 @@ def test_refund_gateway_error(payment_txn_captured, monkeypatch):payment.captured_amount = Decimal("80.00")payment.save()with pytest.raises(PaymentError):- gateway.refund(payment=payment, amount=Decimal("80.00"))+ gateway.refund(+ payment=payment,+ plugin_manager=get_plugins_manager(),+ amount=Decimal("80.00"),+ )payment.refresh_from_db()txn = payment.transactions.last()@@ -326,7 +359,11 @@ def test_refund_gateway_error(payment_txn_captured, monkeypatch):@pytest.mark.parametrize("token", ["111", PREAUTHORIZED_TOKENS[1]])def test_process_payment_success(token, payment_dummy_credit_card):# when- txn = gateway.process_payment(payment=payment_dummy_credit_card, token=token)+ txn = gateway.process_payment(+ payment=payment_dummy_credit_card,+ token=token,+ plugin_manager=get_plugins_manager(),+ )# thenassert txn.is_success@@ -341,7 +378,11 @@ def test_process_payment_success(token, payment_dummy_credit_card):def test_process_payment_failed(token, error, payment_dummy_credit_card):# whenwith pytest.raises(PaymentError) as e:- gateway.process_payment(payment=payment_dummy_credit_card, token=token)+ gateway.process_payment(+ payment=payment_dummy_credit_card,+ token=token,+ plugin_manager=get_plugins_manager(),+ )assert e._excinfo[1].message == error@@ -374,7 +415,11 @@ def test_process_payment_pre_authorized()# when- txn = gateway.process_payment(payment=payment_dummy_credit_card, token=token)+ txn = gateway.process_payment(+ payment=payment_dummy_credit_card,+ token=token,+ plugin_manager=get_plugins_manager(),+ )# thenassert txn.is_success@@ -398,7 +443,11 @@ def test_process_payment_pre_authorized_and_capture()# when- txn = gateway.process_payment(payment=payment_dummy_credit_card, token=token)+ txn = gateway.process_payment(+ payment=payment_dummy_credit_card,+ token=token,+ plugin_manager=get_plugins_manager(),+ )# thenassert txn.is_success@@ -423,7 +472,11 @@ def test_process_payment_pre_authorized_and_capture_error(# whenwith pytest.raises(PaymentError) as e:- gateway.process_payment(payment=payment_dummy_credit_card, token=token)+ gateway.process_payment(+ payment=payment_dummy_credit_card,+ token=token,+ plugin_manager=get_plugins_manager(),+ )assert e._excinfo[1].message == TOKEN_VALIDATION_MAPPING[token]diff --git a/saleor/payment/tests/test_gateway.py b/saleor/payment/tests/test_gateway.pyindex ee8cf3ad99..7012ff6844 100644--- a/saleor/payment/tests/test_gateway.py+++ b/saleor/payment/tests/test_gateway.py@@ -1,10 +1,7 @@from decimal import Decimal-import pytest--import saleor.payment.gateway as gateway--from .. import ChargeStatus, CustomPaymentChoices, TransactionKind+from ...plugins.manager import get_plugins_manager+from .. import ChargeStatus, CustomPaymentChoices, TransactionKind, gatewayfrom ..interface import GatewayResponsefrom ..utils import create_payment_information@@ -83,26 +80,17 @@ TOKEN = "token"USED_GATEWAY = "mirumee.payments.dummy"-def mock_payment_interface(mocker, fake_payment_interface):- mgr = mocker.patch(- "saleor.payment.gateway.get_plugins_manager",- autospec=True,- return_value=fake_payment_interface,- )- yield fake_payment_interface- mgr.assert_called_once()---def test_process_payment(mock_payment_interface, payment_txn_preauth):+def test_process_payment(fake_payment_interface, payment_txn_preauth):PAYMENT_DATA = create_payment_information(payment=payment_txn_preauth, payment_token=TOKEN)- mock_payment_interface.process_payment.return_value = PROCESS_PAYMENT_RESPONSE+ fake_payment_interface.process_payment.return_value = PROCESS_PAYMENT_RESPONSE- transaction = gateway.process_payment(payment=payment_txn_preauth, token=TOKEN)+ transaction = gateway.process_payment(+ payment=payment_txn_preauth, token=TOKEN, plugin_manager=fake_payment_interface+ )- mock_payment_interface.process_payment.assert_called_once_with(+ fake_payment_interface.process_payment.assert_called_once_with(USED_GATEWAY, PAYMENT_DATA)assert transaction.amount == PROCESS_PAYMENT_RESPONSE.amount@@ -112,32 +100,37 @@ def test_process_payment(mock_payment_interface, payment_txn_preauth):def test_store_source_when_processing_payment(- mock_payment_interface, payment_txn_preauth+ fake_payment_interface, payment_txn_preauth):PAYMENT_DATA = create_payment_information(payment=payment_txn_preauth, payment_token=TOKEN, store_source=True)- mock_payment_interface.process_payment.return_value = PROCESS_PAYMENT_RESPONSE+ fake_payment_interface.process_payment.return_value = PROCESS_PAYMENT_RESPONSEtransaction = gateway.process_payment(- payment=payment_txn_preauth, token=TOKEN, store_source=True+ payment=payment_txn_preauth,+ token=TOKEN,+ plugin_manager=fake_payment_interface,+ store_source=True,)- mock_payment_interface.process_payment.assert_called_once_with(+ fake_payment_interface.process_payment.assert_called_once_with(USED_GATEWAY, PAYMENT_DATA)assert transaction.customer_id == PROCESS_PAYMENT_RESPONSE.customer_id-def test_authorize_payment(mock_payment_interface, payment_dummy):+def test_authorize_payment(fake_payment_interface, payment_dummy):PAYMENT_DATA = create_payment_information(payment=payment_dummy, payment_token=TOKEN)- mock_payment_interface.authorize_payment.return_value = AUTHORIZE_RESPONSE+ fake_payment_interface.authorize_payment.return_value = AUTHORIZE_RESPONSE- transaction = gateway.authorize(payment=payment_dummy, token=TOKEN)+ transaction = gateway.authorize(+ payment=payment_dummy, token=TOKEN, plugin_manager=fake_payment_interface+ )- mock_payment_interface.authorize_payment.assert_called_once_with(+ fake_payment_interface.authorize_payment.assert_called_once_with(USED_GATEWAY, PAYMENT_DATA)assert transaction.amount == AUTHORIZE_RESPONSE.amount@@ -146,16 +139,18 @@ def test_authorize_payment(mock_payment_interface, payment_dummy):assert transaction.gateway_response == RAW_RESPONSE-def test_capture_payment(mock_payment_interface, payment_txn_preauth):+def test_capture_payment(fake_payment_interface, payment_txn_preauth):auth_transaction = payment_txn_preauth.transactions.get()PAYMENT_DATA = create_payment_information(payment=payment_txn_preauth, payment_token=auth_transaction.token)- mock_payment_interface.capture_payment.return_value = PROCESS_PAYMENT_RESPONSE+ fake_payment_interface.capture_payment.return_value = PROCESS_PAYMENT_RESPONSE- transaction = gateway.capture(payment=payment_txn_preauth)+ transaction = gateway.capture(+ payment=payment_txn_preauth, plugin_manager=fake_payment_interface+ )- mock_payment_interface.capture_payment.assert_called_once_with(+ fake_payment_interface.capture_payment.assert_called_once_with(USED_GATEWAY, PAYMENT_DATA)assert transaction.amount == PROCESS_PAYMENT_RESPONSE.amount@@ -167,7 +162,9 @@ def test_capture_payment(mock_payment_interface, payment_txn_preauth):def test_refund_for_manual_payment(payment_txn_captured):payment_txn_captured.gateway = CustomPaymentChoices.MANUALtransaction = gateway.refund(- payment=payment_txn_captured, amount=PARTIAL_REFUND_AMOUNT+ payment=payment_txn_captured,+ plugin_manager=get_plugins_manager(),+ amount=PARTIAL_REFUND_AMOUNT,)payment_txn_captured.refresh_from_db()assert payment_txn_captured.charge_status == ChargeStatus.PARTIALLY_REFUNDED@@ -176,18 +173,20 @@ def test_refund_for_manual_payment(payment_txn_captured):assert transaction.currency == "USD"-def test_partial_refund_payment(mock_payment_interface, payment_txn_captured):+def test_partial_refund_payment(fake_payment_interface, payment_txn_captured):capture_transaction = payment_txn_captured.transactions.get()PAYMENT_DATA = create_payment_information(payment=payment_txn_captured,amount=PARTIAL_REFUND_AMOUNT,payment_token=capture_transaction.token,)- mock_payment_interface.refund_payment.return_value = PARTIAL_REFUND_RESPONSE+ fake_payment_interface.refund_payment.return_value = PARTIAL_REFUND_RESPONSEtransaction = gateway.refund(- payment=payment_txn_captured, amount=PARTIAL_REFUND_AMOUNT+ payment=payment_txn_captured,+ plugin_manager=fake_payment_interface,+ amount=PARTIAL_REFUND_AMOUNT,)- mock_payment_interface.refund_payment.assert_called_once_with(+ fake_payment_interface.refund_payment.assert_called_once_with(USED_GATEWAY, PAYMENT_DATA)@@ -199,16 +198,18 @@ def test_partial_refund_payment(mock_payment_interface, payment_txn_captured):assert transaction.gateway_response == RAW_RESPONSE-def test_full_refund_payment(mock_payment_interface, payment_txn_captured):+def test_full_refund_payment(fake_payment_interface, payment_txn_captured):capture_transaction = payment_txn_captured.transactions.get()PAYMENT_DATA = create_payment_information(payment=payment_txn_captured,amount=FULL_REFUND_AMOUNT,payment_token=capture_transaction.token,)- mock_payment_interface.refund_payment.return_value = FULL_REFUND_RESPONSE- transaction = gateway.refund(payment=payment_txn_captured)- mock_payment_interface.refund_payment.assert_called_once_with(+ fake_payment_interface.refund_payment.return_value = FULL_REFUND_RESPONSE+ transaction = gateway.refund(+ payment=payment_txn_captured, plugin_manager=fake_payment_interface+ )+ fake_payment_interface.refund_payment.assert_called_once_with(USED_GATEWAY, PAYMENT_DATA)@@ -220,18 +221,20 @@ def test_full_refund_payment(mock_payment_interface, payment_txn_captured):assert transaction.gateway_response == RAW_RESPONSE-def test_void_payment(mock_payment_interface, payment_txn_preauth):+def test_void_payment(fake_payment_interface, payment_txn_preauth):auth_transaction = payment_txn_preauth.transactions.get()PAYMENT_DATA = create_payment_information(payment=payment_txn_preauth,payment_token=auth_transaction.token,amount=VOID_AMOUNT,)- mock_payment_interface.void_payment.return_value = VOID_RESPONSE+ fake_payment_interface.void_payment.return_value = VOID_RESPONSE- transaction = gateway.void(payment=payment_txn_preauth)+ transaction = gateway.void(+ payment=payment_txn_preauth, plugin_manager=fake_payment_interface+ )- mock_payment_interface.void_payment.assert_called_once_with(+ fake_payment_interface.void_payment.assert_called_once_with(USED_GATEWAY, PAYMENT_DATA)payment_txn_preauth.refresh_from_db()@@ -242,18 +245,20 @@ def test_void_payment(mock_payment_interface, payment_txn_preauth):assert transaction.gateway_response == RAW_RESPONSE-def test_confirm_payment(mock_payment_interface, payment_txn_to_confirm):+def test_confirm_payment(fake_payment_interface, payment_txn_to_confirm):auth_transaction = payment_txn_to_confirm.transactions.get()PAYMENT_DATA = create_payment_information(payment=payment_txn_to_confirm,payment_token=auth_transaction.token,amount=CONFIRM_AMOUNT,)- mock_payment_interface.confirm_payment.return_value = CONFIRM_RESPONSE+ fake_payment_interface.confirm_payment.return_value = CONFIRM_RESPONSE- transaction = gateway.confirm(payment=payment_txn_to_confirm)+ transaction = gateway.confirm(+ payment=payment_txn_to_confirm, plugin_manager=fake_payment_interface+ )- mock_payment_interface.confirm_payment.assert_called_once_with(+ fake_payment_interface.confirm_payment.assert_called_once_with(USED_GATEWAY, PAYMENT_DATA)assert transaction.amount == CONFIRM_RESPONSE.amount@@ -262,9 +267,9 @@ def test_confirm_payment(mock_payment_interface, payment_txn_to_confirm):assert transaction.gateway_response == RAW_RESPONSE-def test_list_gateways(mock_payment_interface):+def test_list_gateways(fake_payment_interface):gateways = [{"name": "Stripe"}, {"name": "Braintree"}]- mock_payment_interface.list_payment_gateways.return_value = gateways- lst = gateway.list_gateways()- mock_payment_interface.list_payment_gateways.assert_called_once()+ fake_payment_interface.list_payment_gateways.return_value = gateways+ lst = gateway.list_gateways(fake_payment_interface)+ fake_payment_interface.list_payment_gateways.assert_called_once()assert lst == gatewaysdiff --git a/saleor/payment/tests/test_payment.py b/saleor/payment/tests/test_payment.pyindex fc0476ca3e..9af9904e72 100644--- a/saleor/payment/tests/test_payment.py+++ b/saleor/payment/tests/test_payment.py@@ -270,7 +270,7 @@ def test_gateway_charge_failed(dummy_response.kind = TransactionKind.CAPTUREmock_capture_payment.return_value = dummy_responsewith pytest.raises(PaymentError):- gateway.capture(payment, amount)+ gateway.capture(payment, get_plugins_manager(), amount)mock_capture_payment.assert_called_once()payment.refresh_from_db()assert payment.charge_status == ChargeStatus.NOT_CHARGED@@ -280,38 +280,38 @@ def test_gateway_charge_failed(def test_gateway_charge_errors(payment_dummy, transaction_token, settings):payment = payment_dummy- gateway.authorize(payment, transaction_token)+ gateway.authorize(payment, transaction_token, get_plugins_manager())with pytest.raises(PaymentError) as exc:- gateway.capture(payment, Decimal("0"))+ gateway.capture(payment, get_plugins_manager(), Decimal("0"))assert exc.value.message == "Amount should be a positive number."payment.charge_status = ChargeStatus.FULLY_REFUNDEDpayment.save()with pytest.raises(PaymentError) as exc:- gateway.capture(payment, Decimal("10"))+ gateway.capture(payment, get_plugins_manager(), Decimal("10"))assert exc.value.message == "This payment cannot be captured."payment.charge_status = ChargeStatus.NOT_CHARGEDpayment.save()with pytest.raises(PaymentError) as exc:- gateway.capture(payment, Decimal("1000000"))+ gateway.capture(payment, get_plugins_manager(), Decimal("1000000"))assert exc.value.message == ("Unable to charge more than un-captured amount.")def test_gateway_refund_errors(payment_txn_captured):payment = payment_txn_capturedwith pytest.raises(PaymentError) as exc:- gateway.refund(payment, Decimal("1000000"))+ gateway.refund(payment, get_plugins_manager(), Decimal("1000000"))assert exc.value.message == "Cannot refund more than captured."with pytest.raises(PaymentError) as exc:- gateway.refund(payment, Decimal("0"))+ gateway.refund(payment, get_plugins_manager(), Decimal("0"))assert exc.value.message == "Amount should be a positive number."payment.charge_status = ChargeStatus.NOT_CHARGEDpayment.save()with pytest.raises(PaymentError) as exc:- gateway.refund(payment, Decimal("1"))+ gateway.refund(payment, get_plugins_manager(), Decimal("1"))assert exc.value.message == "This payment cannot be refunded."