From 89848efd238126d7b2c2b38fe43a4e095e64b7af Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 20 Feb 2024 13:20:47 +0000 Subject: [PATCH] Replaces stubs for VCR calls Remove calling StripeStubs helper --- ...rd_id_from_the_correct_response_fields.yml | 367 ++++++++++++ .../when_request_fails/raises_an_error.yml | 562 ++++++++++++++++++ spec/lib/stripe/profile_storer_spec.rb | 78 ++- 3 files changed, 978 insertions(+), 29 deletions(-) create mode 100644 spec/fixtures/vcr_cassettes/Stripe-v10.9.0/Stripe_ProfileStorer/create_customer_from_token/when_called_from_Stripe_SCA/fetches_the_customer_id_and_the_card_id_from_the_correct_response_fields.yml create mode 100644 spec/fixtures/vcr_cassettes/Stripe-v10.9.0/Stripe_ProfileStorer/create_customer_from_token/when_request_fails/raises_an_error.yml diff --git a/spec/fixtures/vcr_cassettes/Stripe-v10.9.0/Stripe_ProfileStorer/create_customer_from_token/when_called_from_Stripe_SCA/fetches_the_customer_id_and_the_card_id_from_the_correct_response_fields.yml b/spec/fixtures/vcr_cassettes/Stripe-v10.9.0/Stripe_ProfileStorer/create_customer_from_token/when_called_from_Stripe_SCA/fetches_the_customer_id_and_the_card_id_from_the_correct_response_fields.yml new file mode 100644 index 0000000000..2beb3b0c5f --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Stripe-v10.9.0/Stripe_ProfileStorer/create_customer_from_token/when_called_from_Stripe_SCA/fetches_the_customer_id_and_the_card_id_from_the_correct_response_fields.yml @@ -0,0 +1,367 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.stripe.com/v1/payment_methods + body: + encoding: UTF-8 + string: type=card&card[number]=4242424242424242&card[exp_month]=12&card[exp_year]=2025&card[cvc]=314 + headers: + User-Agent: + - Stripe/v1 RubyBindings/10.9.0 + Authorization: + - Bearer + Content-Type: + - application/x-www-form-urlencoded + Stripe-Version: + - '2023-10-16' + X-Stripe-Client-User-Agent: + - '{"bindings_version":"10.9.0","lang":"ruby","lang_version":"3.1.4 p223 (2023-03-30)","platform":"x86_64-linux","engine":"ruby","publisher":"stripe","uname":"Linux + version 6.5.0-18-generic (buildd@lcy02-amd64-070) (x86_64-linux-gnu-gcc-12 + (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0, GNU ld (GNU Binutils for Ubuntu) 2.38) + #18~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 7 11:40:03 UTC 2","hostname":"ff-LAT"}' + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Tue, 20 Feb 2024 13:19:07 GMT + Content-Type: + - application/json + Content-Length: + - '960' + Connection: + - keep-alive + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET,HEAD,PUT,PATCH,POST,DELETE + Access-Control-Allow-Origin: + - "*" + Access-Control-Expose-Headers: + - Request-Id, Stripe-Manage-Version, Stripe-Should-Retry, X-Stripe-External-Auth-Required, + X-Stripe-Privileged-Session-Required + Access-Control-Max-Age: + - '300' + Cache-Control: + - no-cache, no-store + Content-Security-Policy: + - report-uri https://q.stripe.com/csp-report?p=v1%2Fpayment_methods; block-all-mixed-content; + default-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'; + img-src 'self'; script-src 'self' 'report-sample'; style-src 'self' + Idempotency-Key: + - 609226cc-ab51-4a57-93c8-0d8238e474aa + Original-Request: + - req_gYIg4EBjN8fjjX + Request-Id: + - req_gYIg4EBjN8fjjX + Stripe-Should-Retry: + - 'false' + Stripe-Version: + - '2023-10-16' + Vary: + - Origin + X-Stripe-Routing-Context-Priority-Tier: + - api-testmode + Strict-Transport-Security: + - max-age=63072000; includeSubDomains; preload + body: + encoding: UTF-8 + string: |- + { + "id": "pm_1OltDyKuuB1fWySnXkwDkokz", + "object": "payment_method", + "billing_details": { + "address": { + "city": null, + "country": null, + "line1": null, + "line2": null, + "postal_code": null, + "state": null + }, + "email": null, + "name": null, + "phone": null + }, + "card": { + "brand": "visa", + "checks": { + "address_line1_check": null, + "address_postal_code_check": null, + "cvc_check": "unchecked" + }, + "country": "US", + "display_brand": "visa", + "exp_month": 12, + "exp_year": 2025, + "fingerprint": "6E6tgVjx6U65iHFV", + "funding": "credit", + "generated_from": null, + "last4": "4242", + "networks": { + "available": [ + "visa" + ], + "preferred": null + }, + "three_d_secure_usage": { + "supported": true + }, + "wallet": null + }, + "created": 1708435147, + "customer": null, + "livemode": false, + "metadata": {}, + "type": "card" + } + recorded_at: Tue, 20 Feb 2024 13:19:07 GMT +- request: + method: post + uri: https://api.stripe.com/v1/customers + body: + encoding: UTF-8 + string: expand[0]=sources&email=shenita_ankunding%40hoeger.name + headers: + Content-Type: + - application/x-www-form-urlencoded + Authorization: + - Basic c2tfdGVzdF94RmdKUU9sWHBNQUZzb3p0endGQlRGaFAwMEhHN0J1Q0ptOg== + User-Agent: + - Stripe/v1 ActiveMerchantBindings/1.133.0 + Stripe-Version: + - '2020-08-27' + X-Stripe-Client-User-Agent: + - '{"bindings_version":"1.133.0","lang":"ruby","lang_version":"3.1.4 p223 (2023-03-30)","platform":"x86_64-linux","publisher":"active_merchant"}' + X-Stripe-Client-User-Metadata: + - '{"ip":null}' + Connection: + - close + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Tue, 20 Feb 2024 13:19:08 GMT + Content-Type: + - application/json + Content-Length: + - '826' + Connection: + - close + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET,HEAD,PUT,PATCH,POST,DELETE + Access-Control-Allow-Origin: + - "*" + Access-Control-Expose-Headers: + - Request-Id, Stripe-Manage-Version, Stripe-Should-Retry, X-Stripe-External-Auth-Required, + X-Stripe-Privileged-Session-Required + Access-Control-Max-Age: + - '300' + Cache-Control: + - no-cache, no-store + Content-Security-Policy: + - report-uri https://q.stripe.com/csp-report?p=v1%2Fcustomers; block-all-mixed-content; + default-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'; + img-src 'self'; script-src 'self' 'report-sample'; style-src 'self' + Idempotency-Key: + - 162e60f8-d4fe-4133-b9cb-ae9d15ddf042 + Original-Request: + - req_D38PUkZrwSbLfI + Request-Id: + - req_D38PUkZrwSbLfI + Stripe-Should-Retry: + - 'false' + Stripe-Version: + - '2020-08-27' + Vary: + - Origin + X-Stripe-Routing-Context-Priority-Tier: + - api-testmode + Strict-Transport-Security: + - max-age=63072000; includeSubDomains; preload + body: + encoding: UTF-8 + string: |- + { + "id": "cus_Pb5OEVptBjuN70", + "object": "customer", + "address": null, + "balance": 0, + "created": 1708435148, + "currency": null, + "default_currency": null, + "default_source": null, + "delinquent": false, + "description": null, + "discount": null, + "email": "shenita_ankunding@hoeger.name", + "invoice_prefix": "64D9B722", + "invoice_settings": { + "custom_fields": null, + "default_payment_method": null, + "footer": null, + "rendering_options": null + }, + "livemode": false, + "metadata": {}, + "name": null, + "next_invoice_sequence": 1, + "phone": null, + "preferred_locales": [], + "shipping": null, + "sources": { + "object": "list", + "data": [], + "has_more": false, + "total_count": 0, + "url": "/v1/customers/cus_Pb5OEVptBjuN70/sources" + }, + "tax_exempt": "none", + "test_clock": null + } + recorded_at: Tue, 20 Feb 2024 13:19:08 GMT +- request: + method: post + uri: https://api.stripe.com/v1/payment_methods/pm_1OltDyKuuB1fWySnXkwDkokz/attach + body: + encoding: UTF-8 + string: customer=cus_Pb5OEVptBjuN70 + headers: + Content-Type: + - application/x-www-form-urlencoded + Authorization: + - Basic c2tfdGVzdF94RmdKUU9sWHBNQUZzb3p0endGQlRGaFAwMEhHN0J1Q0ptOg== + User-Agent: + - Stripe/v1 ActiveMerchantBindings/1.133.0 + Stripe-Version: + - '2020-08-27' + X-Stripe-Client-User-Agent: + - '{"bindings_version":"1.133.0","lang":"ruby","lang_version":"3.1.4 p223 (2023-03-30)","platform":"x86_64-linux","publisher":"active_merchant"}' + X-Stripe-Client-User-Metadata: + - '{"ip":null}' + Connection: + - close + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Tue, 20 Feb 2024 13:19:09 GMT + Content-Type: + - application/json + Content-Length: + - '971' + Connection: + - close + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET,HEAD,PUT,PATCH,POST,DELETE + Access-Control-Allow-Origin: + - "*" + Access-Control-Expose-Headers: + - Request-Id, Stripe-Manage-Version, Stripe-Should-Retry, X-Stripe-External-Auth-Required, + X-Stripe-Privileged-Session-Required + Access-Control-Max-Age: + - '300' + Cache-Control: + - no-cache, no-store + Content-Security-Policy: + - report-uri https://q.stripe.com/csp-report?p=v1%2Fpayment_methods%2F%3Apayment_method%2Fattach; + block-all-mixed-content; default-src 'none'; base-uri 'none'; form-action + 'none'; frame-ancestors 'none'; img-src 'self'; script-src 'self' 'report-sample'; + style-src 'self' + Idempotency-Key: + - c0e57cd9-fbff-440b-ad66-2815a866b1cf + Original-Request: + - req_j271qCEUB7YGUK + Request-Id: + - req_j271qCEUB7YGUK + Stripe-Should-Retry: + - 'false' + Stripe-Version: + - '2020-08-27' + Vary: + - Origin + X-Stripe-Routing-Context-Priority-Tier: + - api-testmode + Strict-Transport-Security: + - max-age=63072000; includeSubDomains; preload + body: + encoding: UTF-8 + string: |- + { + "id": "pm_1OltDyKuuB1fWySnXkwDkokz", + "object": "payment_method", + "billing_details": { + "address": { + "city": null, + "country": null, + "line1": null, + "line2": null, + "postal_code": null, + "state": null + }, + "email": null, + "name": null, + "phone": null + }, + "card": { + "brand": "visa", + "checks": { + "address_line1_check": null, + "address_postal_code_check": null, + "cvc_check": "pass" + }, + "country": "US", + "display_brand": "visa", + "exp_month": 12, + "exp_year": 2025, + "fingerprint": "6E6tgVjx6U65iHFV", + "funding": "credit", + "generated_from": null, + "last4": "4242", + "networks": { + "available": [ + "visa" + ], + "preferred": null + }, + "three_d_secure_usage": { + "supported": true + }, + "wallet": null + }, + "created": 1708435147, + "customer": "cus_Pb5OEVptBjuN70", + "livemode": false, + "metadata": {}, + "type": "card" + } + recorded_at: Tue, 20 Feb 2024 13:19:09 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/fixtures/vcr_cassettes/Stripe-v10.9.0/Stripe_ProfileStorer/create_customer_from_token/when_request_fails/raises_an_error.yml b/spec/fixtures/vcr_cassettes/Stripe-v10.9.0/Stripe_ProfileStorer/create_customer_from_token/when_request_fails/raises_an_error.yml new file mode 100644 index 0000000000..59a91fbd6d --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Stripe-v10.9.0/Stripe_ProfileStorer/create_customer_from_token/when_request_fails/raises_an_error.yml @@ -0,0 +1,562 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.stripe.com/v1/payment_methods + body: + encoding: UTF-8 + string: type=card&card[number]=4242424242424242&card[exp_month]=12&card[exp_year]=2025&card[cvc]=314 + headers: + User-Agent: + - Stripe/v1 RubyBindings/10.9.0 + Authorization: + - Bearer + Content-Type: + - application/x-www-form-urlencoded + X-Stripe-Client-Telemetry: + - '{"last_request_metrics":{"request_id":"req_gYIg4EBjN8fjjX","request_duration_ms":942}}' + Stripe-Version: + - '2023-10-16' + X-Stripe-Client-User-Agent: + - '{"bindings_version":"10.9.0","lang":"ruby","lang_version":"3.1.4 p223 (2023-03-30)","platform":"x86_64-linux","engine":"ruby","publisher":"stripe","uname":"Linux + version 6.5.0-18-generic (buildd@lcy02-amd64-070) (x86_64-linux-gnu-gcc-12 + (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0, GNU ld (GNU Binutils for Ubuntu) 2.38) + #18~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 7 11:40:03 UTC 2","hostname":"ff-LAT"}' + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Tue, 20 Feb 2024 13:19:10 GMT + Content-Type: + - application/json + Content-Length: + - '960' + Connection: + - keep-alive + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET,HEAD,PUT,PATCH,POST,DELETE + Access-Control-Allow-Origin: + - "*" + Access-Control-Expose-Headers: + - Request-Id, Stripe-Manage-Version, Stripe-Should-Retry, X-Stripe-External-Auth-Required, + X-Stripe-Privileged-Session-Required + Access-Control-Max-Age: + - '300' + Cache-Control: + - no-cache, no-store + Content-Security-Policy: + - report-uri https://q.stripe.com/csp-report?p=v1%2Fpayment_methods; block-all-mixed-content; + default-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'; + img-src 'self'; script-src 'self' 'report-sample'; style-src 'self' + Idempotency-Key: + - bfe2eea2-8a4c-407a-8b9c-25ec4b9ccd58 + Original-Request: + - req_kWgtjRuDhw7tal + Request-Id: + - req_kWgtjRuDhw7tal + Stripe-Should-Retry: + - 'false' + Stripe-Version: + - '2023-10-16' + Vary: + - Origin + X-Stripe-Routing-Context-Priority-Tier: + - api-testmode + Strict-Transport-Security: + - max-age=63072000; includeSubDomains; preload + body: + encoding: UTF-8 + string: |- + { + "id": "pm_1OltE2KuuB1fWySnYZ7LlubV", + "object": "payment_method", + "billing_details": { + "address": { + "city": null, + "country": null, + "line1": null, + "line2": null, + "postal_code": null, + "state": null + }, + "email": null, + "name": null, + "phone": null + }, + "card": { + "brand": "visa", + "checks": { + "address_line1_check": null, + "address_postal_code_check": null, + "cvc_check": "unchecked" + }, + "country": "US", + "display_brand": "visa", + "exp_month": 12, + "exp_year": 2025, + "fingerprint": "6E6tgVjx6U65iHFV", + "funding": "credit", + "generated_from": null, + "last4": "4242", + "networks": { + "available": [ + "visa" + ], + "preferred": null + }, + "three_d_secure_usage": { + "supported": true + }, + "wallet": null + }, + "created": 1708435150, + "customer": null, + "livemode": false, + "metadata": {}, + "type": "card" + } + recorded_at: Tue, 20 Feb 2024 13:19:10 GMT +- request: + method: post + uri: https://api.stripe.com/v1/customers + body: + encoding: UTF-8 + string: name=Apple+Customer&email=applecustomer%40example.com + headers: + User-Agent: + - Stripe/v1 RubyBindings/10.9.0 + Authorization: + - Bearer + Content-Type: + - application/x-www-form-urlencoded + X-Stripe-Client-Telemetry: + - '{"last_request_metrics":{"request_id":"req_kWgtjRuDhw7tal","request_duration_ms":687}}' + Stripe-Version: + - '2023-10-16' + X-Stripe-Client-User-Agent: + - '{"bindings_version":"10.9.0","lang":"ruby","lang_version":"3.1.4 p223 (2023-03-30)","platform":"x86_64-linux","engine":"ruby","publisher":"stripe","uname":"Linux + version 6.5.0-18-generic (buildd@lcy02-amd64-070) (x86_64-linux-gnu-gcc-12 + (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0, GNU ld (GNU Binutils for Ubuntu) 2.38) + #18~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 7 11:40:03 UTC 2","hostname":"ff-LAT"}' + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Tue, 20 Feb 2024 13:19:10 GMT + Content-Type: + - application/json + Content-Length: + - '649' + Connection: + - keep-alive + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET,HEAD,PUT,PATCH,POST,DELETE + Access-Control-Allow-Origin: + - "*" + Access-Control-Expose-Headers: + - Request-Id, Stripe-Manage-Version, Stripe-Should-Retry, X-Stripe-External-Auth-Required, + X-Stripe-Privileged-Session-Required + Access-Control-Max-Age: + - '300' + Cache-Control: + - no-cache, no-store + Content-Security-Policy: + - report-uri https://q.stripe.com/csp-report?p=v1%2Fcustomers; block-all-mixed-content; + default-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'; + img-src 'self'; script-src 'self' 'report-sample'; style-src 'self' + Idempotency-Key: + - 0e26d5cd-a915-48c3-8155-cd7e3ac0e29e + Original-Request: + - req_epsMK51JqaJtHw + Request-Id: + - req_epsMK51JqaJtHw + Stripe-Should-Retry: + - 'false' + Stripe-Version: + - '2023-10-16' + Vary: + - Origin + X-Stripe-Routing-Context-Priority-Tier: + - api-testmode + Strict-Transport-Security: + - max-age=63072000; includeSubDomains; preload + body: + encoding: UTF-8 + string: |- + { + "id": "cus_Pb5OE0HGl0Oqd1", + "object": "customer", + "address": null, + "balance": 0, + "created": 1708435150, + "currency": null, + "default_source": null, + "delinquent": false, + "description": null, + "discount": null, + "email": "applecustomer@example.com", + "invoice_prefix": "39F9B056", + "invoice_settings": { + "custom_fields": null, + "default_payment_method": null, + "footer": null, + "rendering_options": null + }, + "livemode": false, + "metadata": {}, + "name": "Apple Customer", + "next_invoice_sequence": 1, + "phone": null, + "preferred_locales": [], + "shipping": null, + "tax_exempt": "none", + "test_clock": null + } + recorded_at: Tue, 20 Feb 2024 13:19:11 GMT +- request: + method: post + uri: https://api.stripe.com/v1/payment_methods/pm_1OltE2KuuB1fWySnYZ7LlubV/attach + body: + encoding: UTF-8 + string: customer=cus_Pb5OE0HGl0Oqd1 + headers: + User-Agent: + - Stripe/v1 RubyBindings/10.9.0 + Authorization: + - Bearer + Content-Type: + - application/x-www-form-urlencoded + X-Stripe-Client-Telemetry: + - '{"last_request_metrics":{"request_id":"req_epsMK51JqaJtHw","request_duration_ms":415}}' + Stripe-Version: + - '2023-10-16' + X-Stripe-Client-User-Agent: + - '{"bindings_version":"10.9.0","lang":"ruby","lang_version":"3.1.4 p223 (2023-03-30)","platform":"x86_64-linux","engine":"ruby","publisher":"stripe","uname":"Linux + version 6.5.0-18-generic (buildd@lcy02-amd64-070) (x86_64-linux-gnu-gcc-12 + (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0, GNU ld (GNU Binutils for Ubuntu) 2.38) + #18~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 7 11:40:03 UTC 2","hostname":"ff-LAT"}' + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Tue, 20 Feb 2024 13:19:11 GMT + Content-Type: + - application/json + Content-Length: + - '971' + Connection: + - keep-alive + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET,HEAD,PUT,PATCH,POST,DELETE + Access-Control-Allow-Origin: + - "*" + Access-Control-Expose-Headers: + - Request-Id, Stripe-Manage-Version, Stripe-Should-Retry, X-Stripe-External-Auth-Required, + X-Stripe-Privileged-Session-Required + Access-Control-Max-Age: + - '300' + Cache-Control: + - no-cache, no-store + Content-Security-Policy: + - report-uri https://q.stripe.com/csp-report?p=v1%2Fpayment_methods%2F%3Apayment_method%2Fattach; + block-all-mixed-content; default-src 'none'; base-uri 'none'; form-action + 'none'; frame-ancestors 'none'; img-src 'self'; script-src 'self' 'report-sample'; + style-src 'self' + Idempotency-Key: + - bb5b354e-8665-4ab0-a64e-088ff0a14aa8 + Original-Request: + - req_K6makRFpikabOo + Request-Id: + - req_K6makRFpikabOo + Stripe-Should-Retry: + - 'false' + Stripe-Version: + - '2023-10-16' + Vary: + - Origin + X-Stripe-Routing-Context-Priority-Tier: + - api-testmode + Strict-Transport-Security: + - max-age=63072000; includeSubDomains; preload + body: + encoding: UTF-8 + string: |- + { + "id": "pm_1OltE2KuuB1fWySnYZ7LlubV", + "object": "payment_method", + "billing_details": { + "address": { + "city": null, + "country": null, + "line1": null, + "line2": null, + "postal_code": null, + "state": null + }, + "email": null, + "name": null, + "phone": null + }, + "card": { + "brand": "visa", + "checks": { + "address_line1_check": null, + "address_postal_code_check": null, + "cvc_check": "pass" + }, + "country": "US", + "display_brand": "visa", + "exp_month": 12, + "exp_year": 2025, + "fingerprint": "6E6tgVjx6U65iHFV", + "funding": "credit", + "generated_from": null, + "last4": "4242", + "networks": { + "available": [ + "visa" + ], + "preferred": null + }, + "three_d_secure_usage": { + "supported": true + }, + "wallet": null + }, + "created": 1708435150, + "customer": "cus_Pb5OE0HGl0Oqd1", + "livemode": false, + "metadata": {}, + "type": "card" + } + recorded_at: Tue, 20 Feb 2024 13:19:11 GMT +- request: + method: post + uri: https://api.stripe.com/v1/customers + body: + encoding: UTF-8 + string: expand[0]=sources&email=katelynn%40marquardt.info + headers: + Content-Type: + - application/x-www-form-urlencoded + Authorization: + - Basic c2tfdGVzdF94RmdKUU9sWHBNQUZzb3p0endGQlRGaFAwMEhHN0J1Q0ptOg== + User-Agent: + - Stripe/v1 ActiveMerchantBindings/1.133.0 + Stripe-Version: + - '2020-08-27' + X-Stripe-Client-User-Agent: + - '{"bindings_version":"1.133.0","lang":"ruby","lang_version":"3.1.4 p223 (2023-03-30)","platform":"x86_64-linux","publisher":"active_merchant"}' + X-Stripe-Client-User-Metadata: + - '{"ip":null}' + Connection: + - close + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Tue, 20 Feb 2024 13:19:13 GMT + Content-Type: + - application/json + Content-Length: + - '820' + Connection: + - close + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET,HEAD,PUT,PATCH,POST,DELETE + Access-Control-Allow-Origin: + - "*" + Access-Control-Expose-Headers: + - Request-Id, Stripe-Manage-Version, Stripe-Should-Retry, X-Stripe-External-Auth-Required, + X-Stripe-Privileged-Session-Required + Access-Control-Max-Age: + - '300' + Cache-Control: + - no-cache, no-store + Content-Security-Policy: + - report-uri https://q.stripe.com/csp-report?p=v1%2Fcustomers; block-all-mixed-content; + default-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'; + img-src 'self'; script-src 'self' 'report-sample'; style-src 'self' + Idempotency-Key: + - 8278861b-de51-4322-9cdd-821d5ec7b3b0 + Original-Request: + - req_ukBOelKBiIPZrt + Request-Id: + - req_ukBOelKBiIPZrt + Stripe-Should-Retry: + - 'false' + Stripe-Version: + - '2020-08-27' + Vary: + - Origin + X-Stripe-Routing-Context-Priority-Tier: + - api-testmode + Strict-Transport-Security: + - max-age=63072000; includeSubDomains; preload + body: + encoding: UTF-8 + string: |- + { + "id": "cus_Pb5OZZ6PPoT3Nf", + "object": "customer", + "address": null, + "balance": 0, + "created": 1708435152, + "currency": null, + "default_currency": null, + "default_source": null, + "delinquent": false, + "description": null, + "discount": null, + "email": "katelynn@marquardt.info", + "invoice_prefix": "E4CDF0B3", + "invoice_settings": { + "custom_fields": null, + "default_payment_method": null, + "footer": null, + "rendering_options": null + }, + "livemode": false, + "metadata": {}, + "name": null, + "next_invoice_sequence": 1, + "phone": null, + "preferred_locales": [], + "shipping": null, + "sources": { + "object": "list", + "data": [], + "has_more": false, + "total_count": 0, + "url": "/v1/customers/cus_Pb5OZZ6PPoT3Nf/sources" + }, + "tax_exempt": "none", + "test_clock": null + } + recorded_at: Tue, 20 Feb 2024 13:19:13 GMT +- request: + method: post + uri: https://api.stripe.com/v1/payment_methods/pm_1OltE2KuuB1fWySnYZ7LlubV/attach + body: + encoding: UTF-8 + string: customer=cus_Pb5OZZ6PPoT3Nf + headers: + Content-Type: + - application/x-www-form-urlencoded + Authorization: + - Basic c2tfdGVzdF94RmdKUU9sWHBNQUZzb3p0endGQlRGaFAwMEhHN0J1Q0ptOg== + User-Agent: + - Stripe/v1 ActiveMerchantBindings/1.133.0 + Stripe-Version: + - '2020-08-27' + X-Stripe-Client-User-Agent: + - '{"bindings_version":"1.133.0","lang":"ruby","lang_version":"3.1.4 p223 (2023-03-30)","platform":"x86_64-linux","publisher":"active_merchant"}' + X-Stripe-Client-User-Metadata: + - '{"ip":null}' + Connection: + - close + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 400 + message: Bad Request + headers: + Server: + - nginx + Date: + - Tue, 20 Feb 2024 13:19:13 GMT + Content-Type: + - application/json + Content-Length: + - '245' + Connection: + - close + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET,HEAD,PUT,PATCH,POST,DELETE + Access-Control-Allow-Origin: + - "*" + Access-Control-Expose-Headers: + - Request-Id, Stripe-Manage-Version, Stripe-Should-Retry, X-Stripe-External-Auth-Required, + X-Stripe-Privileged-Session-Required + Access-Control-Max-Age: + - '300' + Cache-Control: + - no-cache, no-store + Content-Security-Policy: + - report-uri https://q.stripe.com/csp-report?p=v1%2Fpayment_methods%2F%3Apayment_method%2Fattach; + block-all-mixed-content; default-src 'none'; base-uri 'none'; form-action + 'none'; frame-ancestors 'none'; img-src 'self'; script-src 'self' 'report-sample'; + style-src 'self' + Idempotency-Key: + - ae083153-7766-4b05-b54a-5b211474f5ae + Original-Request: + - req_nICjjhtxAsqGFU + Request-Id: + - req_nICjjhtxAsqGFU + Stripe-Should-Retry: + - 'false' + Stripe-Version: + - '2020-08-27' + Vary: + - Origin + X-Stripe-Routing-Context-Priority-Tier: + - api-testmode + Strict-Transport-Security: + - max-age=63072000; includeSubDomains; preload + body: + encoding: UTF-8 + string: | + { + "error": { + "message": "The payment method you provided has already been attached to a customer.", + "request_log_url": "https://dashboard.stripe.com/test/logs/req_nICjjhtxAsqGFU?t=1708435153", + "type": "invalid_request_error" + } + } + recorded_at: Tue, 20 Feb 2024 13:19:13 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/lib/stripe/profile_storer_spec.rb b/spec/lib/stripe/profile_storer_spec.rb index 0553fe5fc4..663db16165 100644 --- a/spec/lib/stripe/profile_storer_spec.rb +++ b/spec/lib/stripe/profile_storer_spec.rb @@ -5,47 +5,67 @@ require 'spec_helper' module Stripe describe ProfileStorer do include StripeStubs - include StripeHelper - describe "create_customer_from_token" do - let(:stripe_payment_method) { create(:stripe_sca_payment_method) } - let(:card) { create(:credit_card, gateway_payment_profile_id: card_id) } - let(:payment) { create(:payment, source: card, payment_method: stripe_payment_method) } - let(:profile_storer) { Stripe::ProfileStorer.new(payment, stripe_payment_method.provider) } + describe "create_customer_from_token", :vcr, :stripe_version do + let(:pm_card) do + Stripe::PaymentMethod.create({ + type: 'card', + card: { + number: '4242424242424242', + exp_month: 12, + exp_year: Time.zone.now.year.next, + cvc: '314', + }, + }) + end - let(:customer_id) { "cus_A123" } - let(:card_id) { "card_2342" } - let(:customer_response_mock) { - { status: 200, body: JSON.generate(id: customer_id, sources: { data: [{ id: "1" }] }) } + let(:credit_card) { create(:credit_card, gateway_payment_profile_id: pm_card.id) } + + let(:stripe_payment_method) { + create(:stripe_sca_payment_method, distributor_ids: [create(:distributor_enterprise).id], + preferred_enterprise_id: create(:enterprise).id) } - around do |example| - with_stripe_setup { example.run } - end + let(:payment) { + create( + :payment, + payment_method: stripe_payment_method, + source: credit_card, + ) + } - before do - stub_customers_post_request(email: payment.order.email, response: customer_response_mock) - stub_payment_method_attach_request(payment_method: card_id, customer: customer_id) - end + let(:profile_storer) { Stripe::ProfileStorer.new(payment, stripe_payment_method.provider) } context "when called from Stripe SCA" do it "fetches the customer id and the card id from the correct response fields" do profile_storer.create_customer_from_token - expect(payment.source.gateway_customer_profile_id).to eq customer_id - expect(payment.source.gateway_payment_profile_id).to eq card_id + expect(payment.source.gateway_customer_profile_id).to match(/cus_/) + expect(payment.source.gateway_payment_profile_id).to eq pm_card.id + end + end + context "when request fails" do + let(:message) { + 'The payment method you provided has already been attached to a customer.' + } + + let(:customer) do + Stripe::Customer.create({ + name: 'Apple Customer', + email: 'applecustomer@example.com', + }) end - context "when request fails" do - it "raises an error" do - expect(stripe_payment_method.provider).to receive(:store).and_return( - ActiveMerchant::Billing::Response.new(false, "some error") - ) - - expect { profile_storer.create_customer_from_token }.to raise_error( - Spree::Core::GatewayError - ) - end + before do + Stripe::PaymentMethod.attach( + pm_card.id, + { customer: customer.id }, + ) + end + it "raises an error" do + expect { profile_storer.create_customer_from_token }.to raise_error( + Spree::Core::GatewayError, message + ) end end end