Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix missing update of payment methods when using stored payment method (#9158)
Maciej Korycinskiee4bf520baca
diff --git a/saleor/payment/gateways/stripe/plugin.py b/saleor/payment/gateways/stripe/plugin.pyindex afde210cef..d822606d4e 100644--- a/saleor/payment/gateways/stripe/plugin.py+++ b/saleor/payment/gateways/stripe/plugin.py@@ -244,10 +244,13 @@ class StripeGatewayPlugin(BasePlugin):intent_id = Nonekind = TransactionKind.ACTION_TO_CONFIRMaction_required = True+ payment_method_info = Noneif intent:kind, action_required = self._get_transaction_details_for_stripe_status(intent.status)+ if kind in (TransactionKind.AUTH, TransactionKind.CAPTURE):+ payment_method_info = get_payment_method_details(intent)client_secret = intent.client_secretlast_response = intent.last_responseraw_response = last_response.data if last_response else None@@ -265,6 +268,7 @@ class StripeGatewayPlugin(BasePlugin):action_required_data={"client_secret": client_secret, "id": intent_id},customer_id=customer.id if customer else None,psp_reference=intent.id if intent else None,+ payment_method_info=payment_method_info,)@require_active_plugindiff --git a/saleor/payment/gateways/stripe/tests/test_plugin.py b/saleor/payment/gateways/stripe/tests/test_plugin.pyindex 0e1026920a..fc55139ae4 100644--- a/saleor/payment/gateways/stripe/tests/test_plugin.py+++ b/saleor/payment/gateways/stripe/tests/test_plugin.py@@ -8,7 +8,7 @@ from stripe.stripe_object import StripeObjectfrom .....plugins.models import PluginConfigurationfrom .... import TransactionKind-from ....interface import GatewayResponse, StorePaymentMethodEnum+from ....interface import GatewayResponse, PaymentMethodInfo, StorePaymentMethodEnumfrom ....utils import (create_payment_information,create_transaction,@@ -314,11 +314,31 @@ def test_process_payment_with_customer_and_future_usage(dummy_response = {"id": "evt_1Ip9ANH1Vac4G4dbE9ch7zGS",}++ dummy_charges = {+ "charges": {+ "data": [+ {+ "payment_method_details": {+ "type": "card",+ "card": {+ "last4": "1234",+ "exp_year": "2222",+ "exp_month": "12",+ "brand": "visa",+ },+ }+ }+ ]+ }+ }+payment_intent_id = "payment-intent-id"payment_intent.id = payment_intent_idpayment_intent.client_secret = client_secretpayment_intent.last_response.data = dummy_response- payment_intent.status = SUCCESS_STATUS+ payment_intent.status = "requires_payment_method"+ payment_intent.get.side_effect = dummy_charges.getplugin = stripe_plugin(auto_capture=True)@@ -334,8 +354,8 @@ def test_process_payment_with_customer_and_future_usage(response = plugin.process_payment(payment_info, None)assert response.is_success is True- assert response.action_required is False- assert response.kind == TransactionKind.CAPTURE+ assert response.action_required is True+ assert response.kind == TransactionKind.ACTION_TO_CONFIRMassert response.amount == payment_info.amountassert response.currency == payment_info.currencyassert response.transaction_id == payment_intent_id@@ -389,11 +409,15 @@ def test_process_payment_with_customer_and_future_usage_no_store(dummy_response = {"id": "evt_1Ip9ANH1Vac4G4dbE9ch7zGS",}++ dummy_charges = {}+payment_intent_id = "payment-intent-id"payment_intent.id = payment_intent_idpayment_intent.client_secret = client_secretpayment_intent.last_response.data = dummy_responsepayment_intent.status = SUCCESS_STATUS+ payment_intent.get.side_effect = dummy_charges.getplugin = stripe_plugin(auto_capture=True)@@ -420,6 +444,7 @@ def test_process_payment_with_customer_and_future_usage_no_store("client_secret": client_secret,"id": payment_intent_id,}+ assert response.payment_method_info is Noneapi_key = plugin.config.connection_params["secret_api_key"]mocked_payment_intent.assert_called_once_with(@@ -463,11 +488,31 @@ def test_process_payment_with_customer_and_payment_method(dummy_response = {"id": "evt_1Ip9ANH1Vac4G4dbE9ch7zGS",}++ dummy_charges = {+ "charges": {+ "data": [+ {+ "payment_method_details": {+ "type": "card",+ "card": {+ "last4": "1234",+ "exp_year": "2222",+ "exp_month": "12",+ "brand": "visa",+ },+ }+ }+ ]+ }+ }+payment_intent_id = "payment-intent-id"payment_intent.id = payment_intent_idpayment_intent.client_secret = client_secretpayment_intent.last_response.data = dummy_responsepayment_intent.status = SUCCESS_STATUS+ payment_intent.get.side_effect = dummy_charges.getplugin = stripe_plugin(auto_capture=True)@@ -494,6 +539,9 @@ def test_process_payment_with_customer_and_payment_method("client_secret": client_secret,"id": payment_intent_id,}+ assert response.payment_method_info == PaymentMethodInfo(+ last_4="1234", exp_month=12, exp_year=2222, brand="visa", type="card"+ )api_key = plugin.config.connection_params["secret_api_key"]mocked_payment_intent.assert_called_once_with(@@ -539,11 +587,31 @@ def test_process_payment_with_payment_method_types(dummy_response = {"id": "evt_1Ip9ANH1Vac4G4dbE9ch7zGS",}++ dummy_charges = {+ "charges": {+ "data": [+ {+ "payment_method_details": {+ "type": "card",+ "card": {+ "last4": "1234",+ "exp_year": "2222",+ "exp_month": "12",+ "brand": "visa",+ },+ }+ }+ ]+ }+ }+payment_intent_id = "payment-intent-id"payment_intent.id = payment_intent_idpayment_intent.client_secret = client_secretpayment_intent.last_response.data = dummy_responsepayment_intent.status = SUCCESS_STATUS+ payment_intent.get.side_effect = dummy_charges.getplugin = stripe_plugin(auto_capture=True)@@ -571,6 +639,9 @@ def test_process_payment_with_payment_method_types("client_secret": client_secret,"id": payment_intent_id,}+ assert response.payment_method_info == PaymentMethodInfo(+ last_4="1234", exp_month=12, exp_year=2222, brand="visa", type="card"+ )api_key = plugin.config.connection_params["secret_api_key"]mocked_payment_intent.assert_called_once_with(@@ -615,11 +686,31 @@ def test_process_payment_offline(dummy_response = {"id": "evt_1Ip9ANH1Vac4G4dbE9ch7zGS",}++ dummy_charges = {+ "charges": {+ "data": [+ {+ "payment_method_details": {+ "type": "card",+ "card": {+ "last4": "1234",+ "exp_year": "2222",+ "exp_month": "12",+ "brand": "visa",+ },+ }+ }+ ]+ }+ }+payment_intent_id = "payment-intent-id"payment_intent.id = payment_intent_idpayment_intent.client_secret = client_secretpayment_intent.last_response.data = dummy_responsepayment_intent.status = SUCCESS_STATUS+ payment_intent.get.side_effect = dummy_charges.getplugin = stripe_plugin(auto_capture=True)@@ -646,6 +737,9 @@ def test_process_payment_offline("client_secret": client_secret,"id": payment_intent_id,}+ assert response.payment_method_info == PaymentMethodInfo(+ last_4="1234", exp_month=12, exp_year=2222, brand="visa", type="card"+ )api_key = plugin.config.connection_params["secret_api_key"]mocked_payment_intent.assert_called_once_with(@@ -696,11 +790,31 @@ def test_process_payment_with_customer_and_payment_method_raises_authentication_dummy_response = {"id": "evt_1Ip9ANH1Vac4G4dbE9ch7zGS",}++ dummy_charges = {+ "charges": {+ "data": [+ {+ "payment_method_details": {+ "type": "card",+ "card": {+ "last4": "1234",+ "exp_year": "2222",+ "exp_month": "12",+ "brand": "visa",+ },+ }+ }+ ]+ }+ }+payment_intent_id = "payment-intent-id"payment_intent.id = payment_intent_idpayment_intent.client_secret = client_secretpayment_intent.last_response.data = dummy_responsepayment_intent.status = SUCCESS_STATUS+ payment_intent.get.side_effect = dummy_charges.getplugin = stripe_plugin(auto_capture=True)@@ -728,6 +842,9 @@ def test_process_payment_with_customer_and_payment_method_raises_authentication_"client_secret": client_secret,"id": payment_intent_id,}+ assert response.payment_method_info == PaymentMethodInfo(+ last_4="1234", exp_month=12, exp_year=2222, brand="visa", type="card"+ )api_key = plugin.config.connection_params["secret_api_key"]mocked_payment_intent.assert_called_once_with(@@ -901,10 +1018,28 @@ def test_process_payment_with_manual_capture(dummy_response = {"id": "evt_1Ip9ANH1Vac4G4dbE9ch7zGS",}+ dummy_charges = {+ "charges": {+ "data": [+ {+ "payment_method_details": {+ "type": "card",+ "card": {+ "last4": "1234",+ "exp_year": "2222",+ "exp_month": "12",+ "brand": "visa",+ },+ }+ }+ ]+ }+ }payment_intent_id = "payment-intent-id"payment_intent.id = payment_intent_idpayment_intent.client_secret = client_secretpayment_intent.last_response.data = dummy_response+ payment_intent.get.side_effect = dummy_charges.getplugin = stripe_plugin(auto_capture=False)diff --git a/saleor/payment/gateways/stripe/tests/test_plugin_deprecated.py b/saleor/payment/gateways/stripe/tests/test_plugin_deprecated.pyindex 6e6e59a491..1d0903e94d 100644--- a/saleor/payment/gateways/stripe/tests/test_plugin_deprecated.py+++ b/saleor/payment/gateways/stripe/tests/test_plugin_deprecated.py@@ -25,11 +25,13 @@ def test_process_payment_with_customer_and_future_usage(dummy_response = {"id": "evt_1Ip9ANH1Vac4G4dbE9ch7zGS",}+ dummy_charges = {}payment_intent_id = "payment-intent-id"payment_intent.id = payment_intent_idpayment_intent.client_secret = client_secretpayment_intent.last_response.data = dummy_responsepayment_intent.status = SUCCESS_STATUS+ payment_intent.get.side_effect = dummy_charges.getplugin = stripe_plugin(auto_capture=True)