Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add action_required flag to GatewayResponse
Jakub Draganek1838f813c10c
diff --git a/saleor/payment/gateways/braintree/__init__.py b/saleor/payment/gateways/braintree/__init__.pyindex 68059c8746..17e1ade754 100644--- a/saleor/payment/gateways/braintree/__init__.py+++ b/saleor/payment/gateways/braintree/__init__.py@@ -147,6 +147,7 @@ def authorize(kind = TransactionKind.CAPTURE if config.auto_capture else TransactionKind.AUTHreturn GatewayResponse(is_success=result.is_success,+ action_required=False,kind=kind,amount=gateway_response.get("amount", payment_information.amount),currency=gateway_response.get("currency", payment_information.currency),@@ -207,6 +208,7 @@ def capture(payment_information: PaymentData, config: GatewayConfig) -> GatewayRreturn GatewayResponse(is_success=result.is_success,+ action_required=False,kind=TransactionKind.CAPTURE,amount=gateway_response.get("amount", payment_information.amount),currency=gateway_response.get("currency", payment_information.currency),@@ -231,6 +233,7 @@ def void(payment_information: PaymentData, config: GatewayConfig) -> GatewayRespreturn GatewayResponse(is_success=result.is_success,+ action_required=False,kind=TransactionKind.VOID,amount=gateway_response.get("amount", payment_information.amount),currency=gateway_response.get("currency", payment_information.currency),@@ -258,6 +261,7 @@ def refund(payment_information: PaymentData, config: GatewayConfig) -> GatewayRereturn GatewayResponse(is_success=result.is_success,+ action_required=False,kind=TransactionKind.REFUND,amount=gateway_response.get("amount", payment_information.amount),currency=gateway_response.get("currency", payment_information.currency),diff --git a/saleor/payment/gateways/dummy/__init__.py b/saleor/payment/gateways/dummy/__init__.pyindex d3ba929785..d0292115d9 100644--- a/saleor/payment/gateways/dummy/__init__.py+++ b/saleor/payment/gateways/dummy/__init__.py@@ -26,6 +26,7 @@ def authorize(error = "Unable to authorize transaction"return GatewayResponse(is_success=success,+ action_required=False,kind=TransactionKind.AUTH,amount=payment_information.amount,currency=payment_information.currency,@@ -41,6 +42,7 @@ def void(payment_information: PaymentData, config: GatewayConfig) -> GatewayResperror = "Unable to void the transaction."return GatewayResponse(is_success=success,+ action_required=False,kind=TransactionKind.VOID,amount=payment_information.amount,currency=payment_information.currency,@@ -58,6 +60,7 @@ def capture(payment_information: PaymentData, config: GatewayConfig) -> GatewayRreturn GatewayResponse(is_success=success,+ action_required=False,kind=TransactionKind.CAPTURE,amount=payment_information.amount,currency=payment_information.currency,@@ -73,6 +76,7 @@ def refund(payment_information: PaymentData, config: GatewayConfig) -> GatewayReerror = "Unable to process refund"return GatewayResponse(is_success=success,+ action_required=False,kind=TransactionKind.REFUND,amount=payment_information.amount,currency=payment_information.currency,diff --git a/saleor/payment/gateways/razorpay/__init__.py b/saleor/payment/gateways/razorpay/__init__.pyindex b2ee531ee4..7f49fe9c02 100644--- a/saleor/payment/gateways/razorpay/__init__.py+++ b/saleor/payment/gateways/razorpay/__init__.py@@ -34,6 +34,7 @@ def _generate_response("""Generate Saleor transaction information from the payload or from passed data."""return GatewayResponse(transaction_id=data.get("id", payment_information.token),+ action_required=False,kind=kind,amount=data.get("amount", payment_information.amount),currency=data.get("currency", payment_information.currency),diff --git a/saleor/payment/gateways/stripe/__init__.py b/saleor/payment/gateways/stripe/__init__.pyindex a9260d7072..c8950ea3da 100644--- a/saleor/payment/gateways/stripe/__init__.py+++ b/saleor/payment/gateways/stripe/__init__.py@@ -206,6 +206,7 @@ def _create_response(is_success = response.get("status") == "succeeded"return GatewayResponse(is_success=is_success,+ action_required=False,transaction_id=token,kind=kind,amount=amount,diff --git a/saleor/payment/gateways/stripe_new/__init__.py b/saleor/payment/gateways/stripe_new/__init__.pyindex 6e1a63e0bf..7dd82c820a 100644--- a/saleor/payment/gateways/stripe_new/__init__.py+++ b/saleor/payment/gateways/stripe_new/__init__.py@@ -38,7 +38,9 @@ def authorize(capture_method="automatic" if config.auto_capture else "manual",)response = GatewayResponse(- is_success=intent.status in ("succeeded", "requires_capture"),+ is_success=intent.status+ in ("succeeded", "requires_capture", "requires_action"),+ action_required=intent.status == "requires_action",transaction_id=intent.id,amount=get_amount_from_stripe(intent.amount, currency),currency=get_currency_from_stripe(intent.currency),@@ -49,6 +51,7 @@ def authorize(except stripe.error.StripeError as exc:response = GatewayResponse(is_success=False,+ action_required=False,transaction_id=payment_information.token,amount=payment_information.amount,currency=payment_information.currency,@@ -66,6 +69,7 @@ def capture(payment_information: PaymentData, config: GatewayConfig) -> GatewayRcapture = intent.capture()response = GatewayResponse(is_success=capture.status == "succeeded",+ action_required=False,transaction_id=intent.id,amount=get_amount_from_stripe(intent.amount, intent.currency),currency=get_currency_from_stripe(intent.currency),@@ -76,6 +80,7 @@ def capture(payment_information: PaymentData, config: GatewayConfig) -> GatewayRexcept stripe.error.StripeError as exc:response = GatewayResponse(is_success=False,+ action_required=False,transaction_id=payment_information.token,amount=payment_information.amount,currency=payment_information.currency,@@ -95,6 +100,7 @@ def refund(payment_information: PaymentData, config: GatewayConfig) -> GatewayRerefund = intent["charges"]["data"][0].refund(amount=stripe_amount)response = GatewayResponse(is_success=refund.status == "succeeded",+ action_required=False,transaction_id=intent.id,amount=payment_information.amount,currency=get_currency_from_stripe(refund.currency),@@ -105,6 +111,7 @@ def refund(payment_information: PaymentData, config: GatewayConfig) -> GatewayReexcept stripe.error.StripeError as exc:response = GatewayResponse(is_success=False,+ action_required=False,transaction_id=payment_information.token,amount=payment_information.amount,currency=payment_information.currency,@@ -122,6 +129,7 @@ def void(payment_information: PaymentData, config: GatewayConfig) -> GatewayResprefund = intent["charges"]["data"][0].refund()response = GatewayResponse(is_success=refund.status == "succeeded",+ action_required=False,transaction_id=intent.id,amount=get_amount_from_stripe(intent.amount, intent.currency),currency=get_currency_from_stripe(refund.currency),@@ -132,6 +140,7 @@ def void(payment_information: PaymentData, config: GatewayConfig) -> GatewayRespexcept stripe.error.StripeError as exc:response = GatewayResponse(is_success=False,+ action_required=False,transaction_id=payment_information.token,amount=payment_information.amount,currency=payment_information.currency,diff --git a/saleor/payment/interface.py b/saleor/payment/interface.pyindex 642d0e902e..de4d487683 100644--- a/saleor/payment/interface.py+++ b/saleor/payment/interface.py@@ -12,6 +12,7 @@ class GatewayResponse:"""is_success: bool+ action_required: boolkind: stramount: Decimalcurrency: strdiff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex 4d3d5227cf..164db8d0d2 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -219,6 +219,7 @@ def create_transaction(if not gateway_response:gateway_response = GatewayResponse(kind=kind,+ action_required=False,transaction_id=payment_information.token,is_success=False,amount=payment_information.amount,diff --git a/tests/gateway/stripe/cassettes/test_authorize_3d_secure.yaml b/tests/gateway/stripe/cassettes/test_authorize_3d_secure.yamlnew file mode 100644index 0000000000..4e9b9beb6f--- /dev/null+++ b/tests/gateway/stripe/cassettes/test_authorize_3d_secure.yaml@@ -0,0 +1,121 @@+interactions:+- request:+ body: payment_method=pm_card_threeDSecure2Required&amount=4242¤cy=usd&confirmation_method=manual&confirm=True&capture_method=automatic+ headers:+ Accept:+ - '*/*'+ Accept-Encoding:+ - gzip, deflate+ Connection:+ - keep-alive+ Content-Length:+ - '134'+ Content-Type:+ - application/x-www-form-urlencoded+ Idempotency-Key:+ - af317a86-f82f-45e2-b036-de792905a3cc+ User-Agent:+ - Stripe/v1 PythonBindings/2.33.0+ X-Stripe-Client-Telemetry:+ - '{"last_request_metrics": {"request_id": "req_NpPPwz4gRweJlh", "request_duration_ms":+ 5}}'+ X-Stripe-Client-User-Agent:+ - '{"bindings_version": "2.33.0", "lang": "python", "publisher": "stripe", "httplib":+ "requests", "lang_version": "3.7.4", "platform": "Darwin-18.7.0-x86_64-i386-64bit",+ "uname": "Darwin mbp-jakub.lan 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun+ 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64 i386"}'+ method: POST+ uri: https://api.stripe.com/v1/payment_intents+ response:+ body:+ string: "{\n \"id\": \"pi_1F5UpbIUmJaD6Oqv71dfNXKr\",\n \"object\": \"payment_intent\"\+ ,\n \"amount\": 4242,\n \"amount_capturable\": 0,\n \"amount_received\"\+ : 0,\n \"application\": null,\n \"application_fee_amount\": null,\n \"\+ canceled_at\": null,\n \"cancellation_reason\": null,\n \"capture_method\"\+ : \"automatic\",\n \"charges\": {\n \"object\": \"list\",\n \"data\"\+ : [\n\n ],\n \"has_more\": false,\n \"total_count\": 0,\n \"url\"\+ : \"/v1/charges?payment_intent=pi_1F5UpbIUmJaD6Oqv71dfNXKr\"\n },\n \"client_secret\"\+ : \"pi_1F5UpbIUmJaD6Oqv71dfNXKr_secret_YpKk3AC4bBa21fKw05Utm4dNZ\",\n \"\+ confirmation_method\": \"manual\",\n \"created\": 1565344579,\n \"currency\"\+ : \"usd\",\n \"customer\": null,\n \"description\": null,\n \"invoice\"\+ : null,\n \"last_payment_error\": null,\n \"livemode\": false,\n \"metadata\"\+ : {\n },\n \"next_action\": {\n \"type\": \"use_stripe_sdk\",\n \"\+ use_stripe_sdk\": {\n \"type\": \"stripe_3ds2_fingerprint\",\n \"\+ three_d_secure_2_source\": \"src_1F5UpbIUmJaD6OqvjlXgR2e8\",\n \"directory_server_name\"\+ : \"visa\",\n \"server_transaction_id\": \"1300b770-7015-461e-95e6-f5d10b04db5f\"\+ ,\n \"three_ds_method_url\": \"\",\n \"three_ds_optimizations\"\+ : \"\",\n \"directory_server_encryption\": {\n \"directory_server_id\"\+ : \"A000000003\",\n \"algorithm\": \"RSA\",\n \"certificate\"\+ : \"-----BEGIN CERTIFICATE-----\\nMIIFrjCCBJagAwIBAgIQB2rJmsHVwbONd36WP9QPrTANBgkqhkiG9w0BAQsFADBx\\\+ nMQswCQYDVQQGEwJVUzENMAsGA1UEChMEVklTQTEvMC0GA1UECxMmVmlzYSBJbnRl\\ncm5hdGlvbmFsIFNlcnZpY2UgQXNzb2NpYXRpb24xIjAgBgNVBAMTGVZpc2EgZUNv\\\+ nbW1lcmNlIElzc3VpbmcgQ0EwHhcNMTcxMTAyMjIyMzEwW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x6yLt\\\+ n398znM/jra6O1I7mT1GvFpLgXPYHDw==\\n-----END CERTIFICATE-----\\n\"\n \+ \ ]\n }\n }\n },\n \"on_behalf_of\": null,\n \"payment_method\"\+ : \"pm_1F5UpbIUmJaD6Oqv3hvrQbjd\",\n \"payment_method_options\": {\n \"\+ card\": {\n \"request_three_d_secure\": \"automatic\"\n }\n },\n\+ \ \"payment_method_types\": [\n \"card\"\n ],\n \"receipt_email\": null,\n\+ \ \"review\": null,\n \"setup_future_usage\": null,\n \"shipping\": null,\n\+ \ \"source\": null,\n \"statement_descriptor\": null,\n \"statement_descriptor_suffix\"\+ : null,\n \"status\": \"requires_action\",\n \"transfer_data\": null,\n\+ \ \"transfer_group\": null\n}\n"+ headers:+ Connection:+ - keep-alive+ Content-Length:+ - '5228'+ Content-Type:+ - application/json+ Date:+ - Fri, 09 Aug 2019 09:56:19 GMT+ Server:+ - nginx+ Strict-Transport-Security:+ - max-age=31556926; includeSubDomains; preload+ access-control-allow-credentials:+ - 'true'+ access-control-allow-methods:+ - GET, POST, HEAD, OPTIONS, DELETE+ access-control-allow-origin:+ - '*'+ access-control-expose-headers:+ - Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required+ access-control-max-age:+ - '300'+ cache-control:+ - no-cache, no-store+ idempotency-key:+ - af317a86-f82f-45e2-b036-de792905a3cc+ original-request:+ - req_rJ8KoAjQPpmxDW+ request-id:+ - req_rJ8KoAjQPpmxDW+ stripe-version:+ - '2019-05-16'+ status:+ code: 200+ message: OK+version: 1diff --git a/tests/gateway/stripe/test_stripe.py b/tests/gateway/stripe/test_stripe.pyindex 5047531390..f3a9eab057 100644--- a/tests/gateway/stripe/test_stripe.py+++ b/tests/gateway/stripe/test_stripe.py@@ -19,6 +19,7 @@ TRANSACTION_AMOUNT = Decimal(42.42)TRANSACTION_REFUND_AMOUNT = Decimal(24.24)TRANSACTION_CURRENCY = "USD"PAYMENT_METHOD_CARD_SIMPLE = "pm_card_pl"+PAYMENT_METHOD_CARD_3D_SECURE = "pm_card_threeDSecure2Required"# Set to True if recording new cassette with sandbox using credentials in envRECORD = False@@ -74,6 +75,7 @@ def test_authorize(sandbox_gateway_config, stripe_payment):assert isclose(response.amount, TRANSACTION_AMOUNT)assert response.currency == TRANSACTION_CURRENCYassert response.is_success is True+ assert not response.action_required@pytest.mark.integration@@ -89,6 +91,22 @@ def test_authorize_error_response(stripe_payment, sandbox_gateway_config):assert not response.is_successassert response.amount == stripe_payment.totalassert response.currency == stripe_payment.currency+ assert not response.action_required++[email protected](filter_headers=["authorization"])+def test_authorize_3d_secure(stripe_payment, sandbox_gateway_config):+ payment_info = create_payment_information(+ stripe_payment, PAYMENT_METHOD_CARD_3D_SECURE+ )+ response = authorize(payment_info, sandbox_gateway_config)+ assert not response.error+ assert response.kind == TransactionKind.CAPTURE+ assert isclose(response.amount, TRANSACTION_AMOUNT)+ assert response.currency == TRANSACTION_CURRENCY+ assert response.is_success is True+ assert response.action_required@pytest.mark.integrationdiff --git a/tests/test_payment.py b/tests/test_payment.pyindex 197eb5075d..d5ccedfdba 100644--- a/tests/test_payment.py+++ b/tests/test_payment.py@@ -44,6 +44,7 @@ EXAMPLE_ERROR = "Example dummy error"def gateway_response(settings):return GatewayResponse(is_success=True,+ action_required=False,transaction_id="transaction-token",amount=Decimal(14.50),currency=settings.DEFAULT_CURRENCY,@@ -87,6 +88,7 @@ def transaction_token():def dummy_response(payment_dummy, transaction_data, transaction_token):return GatewayResponse(is_success=True,+ action_required=False,transaction_id=transaction_token,error=EXAMPLE_ERROR,amount=payment_dummy.total,