Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add capture payment method
Jakub Draganek1045ca221c13
diff --git a/saleor/payment/gateways/stripe_new/__init__.py b/saleor/payment/gateways/stripe_new/__init__.pyindex 9ae63d5189..444264f4a8 100644--- a/saleor/payment/gateways/stripe_new/__init__.py+++ b/saleor/payment/gateways/stripe_new/__init__.py@@ -25,7 +25,6 @@ def get_client_token(**_):def authorize(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:- error, intent = None, Nonekind = TransactionKind.CAPTURE if config.auto_capture else TransactionKind.AUTHclient = _get_client(**config.connection_params)currency = get_currency_for_stripe(payment_information.currency)@@ -63,7 +62,30 @@ def authorize(def capture(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:- pass+ client = _get_client(**config.connection_params)+ try:+ intent = client.PaymentIntent.retrieve(id=payment_information.token)+ capture = intent.capture()+ response = GatewayResponse(+ is_success=capture.status == "succeeded",+ transaction_id=intent.id,+ amount=get_amount_from_stripe(intent.amount, intent.currency),+ currency=get_currency_from_stripe(intent.currency),+ error=None,+ kind=TransactionKind.CAPTURE,+ raw_response=capture,+ )+ except stripe.error.StripeError as exc:+ response = GatewayResponse(+ is_success=False,+ transaction_id=payment_information.token,+ amount=payment_information.amount,+ currency=payment_information.currency,+ error=exc.user_message,+ kind=TransactionKind.CAPTURE,+ raw_response=exc.json_body or {},+ )+ return responsedef refund(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:diff --git a/tests/gateway/stripe/__init__.py b/tests/gateway/stripe/__init__.pynew file mode 100644index 0000000000..e69de29bb2diff --git a/tests/gateway/cassettes/test_authorize.yaml b/tests/gateway/stripe/cassettes/test_authorize.yamlsimilarity index 100%rename from tests/gateway/cassettes/test_authorize.yamlrename to tests/gateway/stripe/cassettes/test_authorize.yamldiff --git a/tests/gateway/stripe/cassettes/test_authorize_error_response.yaml b/tests/gateway/stripe/cassettes/test_authorize_error_response.yamlnew file mode 100644index 0000000000..ec4a4f3c92--- /dev/null+++ b/tests/gateway/stripe/cassettes/test_authorize_error_response.yaml@@ -0,0 +1,71 @@+interactions:+- request:+ body: payment_method=abcdefghijklmnoprstquwz&amount=4242¤cy=usd&confirmation_method=manual&confirm=True&capture_method=automatic+ headers:+ Accept:+ - '*/*'+ Accept-Encoding:+ - gzip, deflate+ Connection:+ - keep-alive+ Content-Length:+ - '128'+ Content-Type:+ - application/x-www-form-urlencoded+ Idempotency-Key:+ - ceca05d8-534b-4de0-a1ed-51fcff242024+ User-Agent:+ - Stripe/v1 PythonBindings/2.33.0+ X-Stripe-Client-Telemetry:+ - '{"last_request_metrics": {"request_id": "req_8S93V2YnPF1OyS", "request_duration_ms":+ 73}}'+ 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 \"error\": {\n \"code\": \"resource_missing\",\n \"doc_url\"\+ : \"https://stripe.com/docs/error-codes/resource-missing\",\n \"message\"\+ : \"No such payment_method: abcdefghijklmnoprstquwz\",\n \"param\": \"\+ payment_method\",\n \"type\": \"invalid_request_error\"\n }\n}\n"+ headers:+ Connection:+ - keep-alive+ Content-Length:+ - '257'+ Content-Type:+ - application/json+ Date:+ - Thu, 08 Aug 2019 14:57:07 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:+ - ceca05d8-534b-4de0-a1ed-51fcff242024+ original-request:+ - req_NpPPwz4gRweJlh+ request-id:+ - req_NpPPwz4gRweJlh+ stripe-version:+ - '2019-05-16'+ status:+ code: 400+ message: Bad Request+version: 1diff --git a/tests/gateway/cassettes/test_authorize_without_capture.yaml b/tests/gateway/stripe/cassettes/test_authorize_without_capture.yamlsimilarity index 100%rename from tests/gateway/cassettes/test_authorize_without_capture.yamlrename to tests/gateway/stripe/cassettes/test_authorize_without_capture.yamldiff --git a/tests/gateway/stripe/cassettes/test_capture.yaml b/tests/gateway/stripe/cassettes/test_capture.yamlnew file mode 100644index 0000000000..0333fc7e93--- /dev/null+++ b/tests/gateway/stripe/cassettes/test_capture.yaml@@ -0,0 +1,236 @@+interactions:+- request:+ body: null+ headers:+ Accept:+ - '*/*'+ Accept-Encoding:+ - gzip, deflate+ Connection:+ - keep-alive+ User-Agent:+ - Stripe/v1 PythonBindings/2.33.0+ X-Stripe-Client-Telemetry:+ - '{"last_request_metrics": {"request_id": "req_z1CtFdtgNMk5eX", "request_duration_ms":+ 4}}'+ 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: GET+ uri: https://api.stripe.com/v1/payment_intents/pi_1F5BsRIUmJaD6Oqvz2XMKZCD+ response:+ body:+ string: "{\n \"id\": \"pi_1F5BsRIUmJaD6Oqvz2XMKZCD\",\n \"object\": \"payment_intent\"\+ ,\n \"amount\": 4242,\n \"amount_capturable\": 4242,\n \"amount_received\"\+ : 0,\n \"application\": null,\n \"application_fee_amount\": null,\n \"\+ canceled_at\": null,\n \"cancellation_reason\": null,\n \"capture_method\"\+ : \"manual\",\n \"charges\": {\n \"object\": \"list\",\n \"data\":\+ \ [\n {\n \"id\": \"ch_1F5BsRIUmJaD6Oqvl2WF1xdU\",\n \"\+ object\": \"charge\",\n \"amount\": 4242,\n \"amount_refunded\"\+ : 0,\n \"application\": null,\n \"application_fee\": null,\n\+ \ \"application_fee_amount\": null,\n \"balance_transaction\"\+ : null,\n \"billing_details\": {\n \"address\": {\n \+ \ \"city\": null,\n \"country\": null,\n \"line1\"\+ : null,\n \"line2\": null,\n \"postal_code\": null,\n\+ \ \"state\": null\n },\n \"email\": null,\n \+ \ \"name\": null,\n \"phone\": null\n },\n \+ \ \"captured\": false,\n \"created\": 1565271719,\n \"currency\"\+ : \"usd\",\n \"customer\": null,\n \"description\": null,\n\+ \ \"destination\": null,\n \"dispute\": null,\n \"failure_code\"\+ : null,\n \"failure_message\": null,\n \"fraud_details\": {\n\+ \ },\n \"invoice\": null,\n \"livemode\": false,\n \+ \ \"metadata\": {\n },\n \"on_behalf_of\": null,\n \+ \ \"order\": null,\n \"outcome\": {\n \"network_status\"\+ : \"approved_by_network\",\n \"reason\": null,\n \"risk_level\"\+ : \"normal\",\n \"risk_score\": 10,\n \"seller_message\"\+ : \"Payment complete.\",\n \"type\": \"authorized\"\n },\n\+ \ \"paid\": true,\n \"payment_intent\": \"pi_1F5BsRIUmJaD6Oqvz2XMKZCD\"\+ ,\n \"payment_method\": \"pm_1F5BsQIUmJaD6OqvbB4aOcJX\",\n \"\+ payment_method_details\": {\n \"card\": {\n \"brand\"\+ : \"visa\",\n \"checks\": {\n \"address_line1_check\"\+ : null,\n \"address_postal_code_check\": null,\n \+ \ \"cvc_check\": null\n },\n \"country\": \"PL\",\n\+ \ \"exp_month\": 8,\n \"exp_year\": 2020,\n \+ \ \"fingerprint\": \"aleqpF0PMAATcfmb\",\n \"funding\": \"credit\"\+ ,\n \"last4\": \"0005\",\n \"three_d_secure\": null,\n\+ \ \"wallet\": null\n },\n \"type\": \"card\"\n\+ \ },\n \"receipt_email\": null,\n \"receipt_number\"\+ : null,\n \"receipt_url\": \"https://pay.stripe.com/receipts/acct_1EzlmjIUmJaD6Oqv/ch_1F5BsRIUmJaD6Oqvl2WF1xdU/rcpt_FaMbtUmGgcY6xnKYCxzQgjVlAwLno4y\"\+ ,\n \"refunded\": false,\n \"refunds\": {\n \"object\"\+ : \"list\",\n \"data\": [\n\n ],\n \"has_more\"\+ : false,\n \"total_count\": 0,\n \"url\": \"/v1/charges/ch_1F5BsRIUmJaD6Oqvl2WF1xdU/refunds\"\+ \n },\n \"review\": null,\n \"shipping\": null,\n \+ \ \"source\": null,\n \"source_transfer\": null,\n \"statement_descriptor\"\+ : null,\n \"statement_descriptor_suffix\": null,\n \"status\"\+ : \"succeeded\",\n \"transfer_data\": null,\n \"transfer_group\"\+ : null\n }\n ],\n \"has_more\": false,\n \"total_count\": 1,\n\+ \ \"url\": \"/v1/charges?payment_intent=pi_1F5BsRIUmJaD6Oqvz2XMKZCD\"\n\+ \ },\n \"client_secret\": \"pi_1F5BsRIUmJaD6Oqvz2XMKZCD_secret_FnZ8ApzrD4JVONWgCbLGbKAdI\"\+ ,\n \"confirmation_method\": \"manual\",\n \"created\": 1565271719,\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\": null,\n \"on_behalf_of\": null,\n\+ \ \"payment_method\": \"pm_1F5BsQIUmJaD6OqvbB4aOcJX\",\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_capture\",\n \"transfer_data\": null,\n\+ \ \"transfer_group\": null\n}\n"+ headers:+ Connection:+ - keep-alive+ Content-Length:+ - '3975'+ Content-Type:+ - application/json+ Date:+ - Thu, 08 Aug 2019 14:57:08 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+ request-id:+ - req_WNAnG8hOrgPLhg+ stripe-version:+ - '2019-05-16'+ status:+ code: 200+ message: OK+- request:+ body: null+ headers:+ Accept:+ - '*/*'+ Accept-Encoding:+ - gzip, deflate+ Connection:+ - keep-alive+ Content-Length:+ - '0'+ Content-Type:+ - application/x-www-form-urlencoded+ Idempotency-Key:+ - 0ae9d626-e952-4e89-821f-fda00f6b7f41+ User-Agent:+ - Stripe/v1 PythonBindings/2.33.0+ X-Stripe-Client-Telemetry:+ - '{"last_request_metrics": {"request_id": "req_WNAnG8hOrgPLhg", "request_duration_ms":+ 534}}'+ 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/pi_1F5BsRIUmJaD6Oqvz2XMKZCD/capture+ response:+ body:+ string: "{\n \"id\": \"pi_1F5BsRIUmJaD6Oqvz2XMKZCD\",\n \"object\": \"payment_intent\"\+ ,\n \"amount\": 4242,\n \"amount_capturable\": 0,\n \"amount_received\"\+ : 4242,\n \"application\": null,\n \"application_fee_amount\": null,\n \+ \ \"canceled_at\": null,\n \"cancellation_reason\": null,\n \"capture_method\"\+ : \"manual\",\n \"charges\": {\n \"object\": \"list\",\n \"data\":\+ \ [\n {\n \"id\": \"ch_1F5BsRIUmJaD6Oqvl2WF1xdU\",\n \"\+ object\": \"charge\",\n \"amount\": 4242,\n \"amount_refunded\"\+ : 0,\n \"application\": null,\n \"application_fee\": null,\n\+ \ \"application_fee_amount\": null,\n \"balance_transaction\"\+ : \"txn_1F5D3BIUmJaD6OqvpbNul1gK\",\n \"billing_details\": {\n \+ \ \"address\": {\n \"city\": null,\n \"country\"\+ : null,\n \"line1\": null,\n \"line2\": null,\n \+ \ \"postal_code\": null,\n \"state\": null\n },\n\+ \ \"email\": null,\n \"name\": null,\n \"phone\"\+ : null\n },\n \"captured\": true,\n \"created\": 1565271719,\n\+ \ \"currency\": \"usd\",\n \"customer\": null,\n \"description\"\+ : null,\n \"destination\": null,\n \"dispute\": null,\n \+ \ \"failure_code\": null,\n \"failure_message\": null,\n \+ \ \"fraud_details\": {\n },\n \"invoice\": null,\n \"\+ livemode\": false,\n \"metadata\": {\n },\n \"on_behalf_of\"\+ : null,\n \"order\": null,\n \"outcome\": {\n \"network_status\"\+ : \"approved_by_network\",\n \"reason\": null,\n \"risk_level\"\+ : \"normal\",\n \"risk_score\": 10,\n \"seller_message\"\+ : \"Payment complete.\",\n \"type\": \"authorized\"\n },\n\+ \ \"paid\": true,\n \"payment_intent\": \"pi_1F5BsRIUmJaD6Oqvz2XMKZCD\"\+ ,\n \"payment_method\": \"pm_1F5BsQIUmJaD6OqvbB4aOcJX\",\n \"\+ payment_method_details\": {\n \"card\": {\n \"brand\"\+ : \"visa\",\n \"checks\": {\n \"address_line1_check\"\+ : null,\n \"address_postal_code_check\": null,\n \+ \ \"cvc_check\": null\n },\n \"country\": \"PL\",\n\+ \ \"exp_month\": 8,\n \"exp_year\": 2020,\n \+ \ \"fingerprint\": \"aleqpF0PMAATcfmb\",\n \"funding\": \"credit\"\+ ,\n \"last4\": \"0005\",\n \"three_d_secure\": null,\n\+ \ \"wallet\": null\n },\n \"type\": \"card\"\n\+ \ },\n \"receipt_email\": null,\n \"receipt_number\"\+ : null,\n \"receipt_url\": \"https://pay.stripe.com/receipts/acct_1EzlmjIUmJaD6Oqv/ch_1F5BsRIUmJaD6Oqvl2WF1xdU/rcpt_FaMbtUmGgcY6xnKYCxzQgjVlAwLno4y\"\+ ,\n \"refunded\": false,\n \"refunds\": {\n \"object\"\+ : \"list\",\n \"data\": [\n\n ],\n \"has_more\"\+ : false,\n \"total_count\": 0,\n \"url\": \"/v1/charges/ch_1F5BsRIUmJaD6Oqvl2WF1xdU/refunds\"\+ \n },\n \"review\": null,\n \"shipping\": null,\n \+ \ \"source\": null,\n \"source_transfer\": null,\n \"statement_descriptor\"\+ : null,\n \"statement_descriptor_suffix\": null,\n \"status\"\+ : \"succeeded\",\n \"transfer_data\": null,\n \"transfer_group\"\+ : null\n }\n ],\n \"has_more\": false,\n \"total_count\": 1,\n\+ \ \"url\": \"/v1/charges?payment_intent=pi_1F5BsRIUmJaD6Oqvz2XMKZCD\"\n\+ \ },\n \"client_secret\": \"pi_1F5BsRIUmJaD6Oqvz2XMKZCD_secret_FnZ8ApzrD4JVONWgCbLGbKAdI\"\+ ,\n \"confirmation_method\": \"manual\",\n \"created\": 1565271719,\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\": null,\n \"on_behalf_of\": null,\n\+ \ \"payment_method\": \"pm_1F5BsQIUmJaD6OqvbB4aOcJX\",\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\": \"succeeded\",\n \"transfer_data\": null,\n \"transfer_group\"\+ : null\n}\n"+ headers:+ Connection:+ - keep-alive+ Content-Length:+ - '3993'+ Content-Type:+ - application/json+ Date:+ - Thu, 08 Aug 2019 14:57:09 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:+ - 0ae9d626-e952-4e89-821f-fda00f6b7f41+ original-request:+ - req_SlIBaeBHbOzc6l+ request-id:+ - req_SlIBaeBHbOzc6l+ stripe-version:+ - '2019-05-16'+ status:+ code: 200+ message: OK+version: 1diff --git a/tests/gateway/stripe/cassettes/test_capture_error_response.yaml b/tests/gateway/stripe/cassettes/test_capture_error_response.yamlnew file mode 100644index 0000000000..829442554d--- /dev/null+++ b/tests/gateway/stripe/cassettes/test_capture_error_response.yaml@@ -0,0 +1,61 @@+interactions:+- request:+ body: null+ headers:+ Accept:+ - '*/*'+ Accept-Encoding:+ - gzip, deflate+ Connection:+ - keep-alive+ User-Agent:+ - Stripe/v1 PythonBindings/2.33.0+ X-Stripe-Client-Telemetry:+ - '{"last_request_metrics": {"request_id": "req_SlIBaeBHbOzc6l", "request_duration_ms":+ 9}}'+ 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: GET+ uri: https://api.stripe.com/v1/payment_intents/THIS_INTENT_DOES_NOT_EXISTS+ response:+ body:+ string: "{\n \"error\": {\n \"code\": \"resource_missing\",\n \"doc_url\"\+ : \"https://stripe.com/docs/error-codes/resource-missing\",\n \"message\"\+ : \"No such payment_intent: THIS_INTENT_DOES_NOT_EXISTS\",\n \"param\"\+ : \"intent\",\n \"type\": \"invalid_request_error\"\n }\n}\n"+ headers:+ Connection:+ - keep-alive+ Content-Length:+ - '253'+ Content-Type:+ - application/json+ Date:+ - Thu, 08 Aug 2019 15:05:56 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+ request-id:+ - req_J74zANRVs5Kp3I+ stripe-version:+ - '2019-05-16'+ status:+ code: 404+ message: Not Found+version: 1diff --git a/tests/gateway/test_stripe_new.py b/tests/gateway/stripe/test_stripe.pysimilarity index 69%rename from tests/gateway/test_stripe_new.pyrename to tests/gateway/stripe/test_stripe.pyindex d221960413..97798a8e5c 100644--- a/tests/gateway/test_stripe_new.py+++ b/tests/gateway/stripe/test_stripe.py@@ -100,31 +100,41 @@ def test_authorize_without_capture(stripe_payment, sandbox_gateway_config):assert response.is_success is True-# @pytest.fixture()-# def stripe_authorized_payment(stripe_payment):-# stripe_payment.charge_status = ChargeStatus.NOT_CHARGED-# stripe_payment.save(update_fields=["charge_status"])-#-# return stripe_payment-#-#-# @pytest.mark.integration-# @pytest.mark.vcr(filter_headers=["authorization"])-# def test_capture(-# stripe_authorized_payment,-# gateway_config,-# stripe_charge_success_response,-# ):-# payment = stripe_authorized_payment-# payment_info = create_payment_information(payment, amount=TRANSACTION_AMOUNT)-# response = stripe_charge_success_response-#-# response = capture(payment_info, gateway_config)-#-# assert not response.error-# assert response.transaction_id == PAYMENT_METHOD_CARD_SIMPLE-# assert response.kind == TransactionKind.CAPTURE-# assert response.is_success-# assert isclose(response.amount, TRANSACTION_AMOUNT)-# assert response.currency == TRANSACTION_CURRENCY-# assert response.raw_response == stripe_charge_success_response+def stripe_authorized_payment(stripe_payment):+ stripe_payment.charge_status = ChargeStatus.NOT_CHARGED+ stripe_payment.save(update_fields=["charge_status"])++ return stripe_payment++[email protected](filter_headers=["authorization"])+def test_capture(stripe_authorized_payment, sandbox_gateway_config):+ INTENT_ID = "pi_1F5BsRIUmJaD6Oqvz2XMKZCD"+ payment_info = create_payment_information(+ stripe_authorized_payment, payment_token=INTENT_ID+ )+ response = capture(payment_info, sandbox_gateway_config)++ assert not response.error+ assert response.transaction_id == INTENT_ID+ assert response.kind == TransactionKind.CAPTURE+ assert response.is_success+ assert isclose(response.amount, TRANSACTION_AMOUNT)+ assert response.currency == TRANSACTION_CURRENCY++[email protected](filter_headers=["authorization"])+def test_capture_error_response(stripe_payment, sandbox_gateway_config):+ INVALID_INTENT = "THIS_INTENT_DOES_NOT_EXISTS"+ payment_info = create_payment_information(stripe_payment, INVALID_INTENT)+ response = capture(payment_info, sandbox_gateway_config)++ assert response.error == "No such payment_intent: " + INVALID_INTENT+ assert response.transaction_id == INVALID_INTENT+ assert response.kind == TransactionKind.CAPTURE+ assert not response.is_success+ assert response.amount == stripe_payment.total+ assert response.currency == stripe_payment.currency