Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add option to store customer source in process_payment
Jakub Draganek3c76952718f7
diff --git a/saleor/payment/gateway.py b/saleor/payment/gateway.pyindex 838065f90c..86ae902fac 100644--- a/saleor/payment/gateway.py+++ b/saleor/payment/gateway.py@@ -1,4 +1,4 @@-from ..core.payments import PaymentInterface, Gateway+from ..core.payments import Gateway, PaymentInterfacefrom ..extensions.manager import get_extensions_managerfrom .models import Payment, Transactionfrom .utils import create_payment_information, create_transaction@@ -9,9 +9,11 @@ class PaymentGateway:self.plugin_manager: PaymentInterface = get_extensions_manager()def process_payment(- self, gateway: Gateway, payment: Payment, token: str+ self, gateway: Gateway, payment: Payment, token: str, store_source: bool = False) -> Transaction:- payment_data = create_payment_information(payment=payment, payment_token=token)+ payment_data = create_payment_information(+ payment=payment, payment_token=token, store_source=store_source+ )response = self.plugin_manager.process_payment(gateway, payment_data, token)return create_transaction(payment,diff --git a/saleor/payment/gateways/braintree/plugin.py b/saleor/payment/gateways/braintree/plugin.pyindex 1fef6eb342..ca22f0a3e1 100644--- a/saleor/payment/gateways/braintree/plugin.py+++ b/saleor/payment/gateways/braintree/plugin.py@@ -58,7 +58,8 @@ class BraintreeGatewayPlugin(BasePlugin):"type": ConfigurationTypeField.BOOLEAN,"help_text": pgettext_lazy("Plugin help text",- "Determines if Saleor should store cards on payments in Braintree customer.",+ "Determines if Saleor should store cards on payments"+ " in Braintree customer.",),"label": pgettext_lazy("Plugin label", "Store customers card"),},diff --git a/saleor/payment/gateways/stripe/plugin.py b/saleor/payment/gateways/stripe/plugin.pyindex 3c0c9625ab..efdbbe02d7 100644--- a/saleor/payment/gateways/stripe/plugin.py+++ b/saleor/payment/gateways/stripe/plugin.py@@ -43,7 +43,8 @@ class StripeGatewayPlugin(BasePlugin):"type": ConfigurationTypeField.BOOLEAN,"help_text": pgettext_lazy("Plugin help text",- "Determines if Saleor should store cards on payments in Stripe customer.",+ "Determines if Saleor should store cards on payments"+ "in Stripe customer.",),"label": pgettext_lazy("Plugin label", "Store customers card"),},diff --git a/tests/gateway/test_gateway.py b/tests/gateway/test_gateway.pyindex 43b6b993ca..b5e0365139 100644--- a/tests/gateway/test_gateway.py+++ b/tests/gateway/test_gateway.py@@ -11,6 +11,7 @@ from saleor.payment.utils import create_payment_informationRAW_RESPONSE = {"test": "abcdefgheijklmn"}PROCESS_PAYMENT_RESPONSE = GatewayResponse(is_success=True,+ customer_id="test_customer",action_required=False,kind=TransactionKind.AUTH,amount=Decimal(10.0),@@ -57,3 +58,25 @@ def test_process_payment(payment_txn_preauth):assert transaction.kind == TransactionKind.AUTHassert transaction.currency == "usd"assert transaction.gateway_response == RAW_RESPONSE+++def test_store_source_when_processing_payment(payment_txn_preauth):+ TOKEN = "token"+ USED_GATEWAY = Gateway.STRIPE+ gateway = PaymentGateway()+ PAYMENT_DATA = create_payment_information(+ payment=payment_txn_preauth, payment_token=TOKEN, store_source=True+ )+ gateway.plugin_manager.process_payment.return_value = PROCESS_PAYMENT_RESPONSE++ transaction = gateway.process_payment(+ payment=payment_txn_preauth,+ gateway=USED_GATEWAY,+ token=TOKEN,+ store_source=True,+ )++ gateway.plugin_manager.process_payment.assert_called_once_with(+ USED_GATEWAY, PAYMENT_DATA, TOKEN+ )+ assert transaction.customer_id == PROCESS_PAYMENT_RESPONSE.customer_id