File stripe_payment_intents.rb
has 580 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'active_support/core_ext/hash/slice'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
# This gateway uses the current Stripe {Payment Intents API}[https://stripe.com/docs/api/payment_intents].
Class StripePaymentIntentsGateway
has 64 methods (exceeds 20 allowed). Consider refactoring. Open
class StripePaymentIntentsGateway < StripeGateway
ALLOWED_METHOD_STATES = %w[automatic manual].freeze
ALLOWED_CANCELLATION_REASONS = %w[duplicate fraudulent requested_by_customer abandoned].freeze
CREATE_INTENT_ATTRIBUTES = %i[description statement_descriptor_suffix statement_descriptor receipt_email save_payment_method]
CONFIRM_INTENT_ATTRIBUTES = %i[receipt_email return_url save_payment_method setup_future_usage off_session]
Method create_setup_intent
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def create_setup_intent(payment_method, options = {})
MultiResponse.run do |r|
r.process do
post = {}
add_customer(post, options)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method create_intent
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def create_intent(money, payment_method, options = {})
MultiResponse.run do |r|
if payment_method.is_a?(NetworkTokenizationCreditCard) && digital_wallet_payment_method?(payment_method) && options[:new_ap_gp_route] != true
r.process { tokenize_apple_google(payment_method, options) }
payment_method = (r.params['token']['id']) if r.success?
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method create_intent
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create_intent(money, payment_method, options = {})
MultiResponse.run do |r|
if payment_method.is_a?(NetworkTokenizationCreditCard) && digital_wallet_payment_method?(payment_method) && options[:new_ap_gp_route] != true
r.process { tokenize_apple_google(payment_method, options) }
payment_method = (r.params['token']['id']) if r.success?
Method store
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def store(payment_method, options = {})
params = {}
# If customer option is provided, create a payment method and attach to customer id
# Otherwise, create a customer, then attach
if new_apple_google_pay_flow(payment_method, options)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method add_stored_credential_transaction_type
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def add_stored_credential_transaction_type(post, options = {})
return unless options[:stored_credential_transaction_type]
stored_credential = options[:stored_credential]
# Do not add anything unless these are present.
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method refund
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def refund(money, intent_id, options = {})
if intent_id.include?('pi_')
intent = api_request(:get, "payment_intents/#{intent_id}", nil, options)
return Response.new(false, intent['error']['message'], intent) if intent['error']
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method add_external_three_d_secure_auth_data
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def add_external_three_d_secure_auth_data(post, options = {})
return unless options[:three_d_secure]&.is_a?(Hash)
three_d_secure = options[:three_d_secure]
post[:payment_method_options] ||= {}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method add_level_three
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def add_level_three(post, options = {})
level_three = {}
level_three[:merchant_reference] = options[:merchant_reference] if options[:merchant_reference]
level_three[:customer_reference] = options[:customer_reference] if options[:customer_reference]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method add_stored_credentials
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def add_stored_credentials(post, options = {})
stored_credential = options[:stored_credential]
return unless stored_credential && !stored_credential.values.all?(&:nil?)
post[:payment_method_options] ||= {}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method tokenize_apple_google
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def tokenize_apple_google(payment, options = {})
tokenization_method = payment.source == :google_pay ? :android_pay : payment.source
post = {
card: {
number: payment.number,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method add_cryptogram_and_eci
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def add_cryptogram_and_eci(post, payment_method, options)
post[:payment_method_options] ||= {}
post[:payment_method_options][:card] ||= {}
post[:payment_method_options][:card][:network_token] ||= {}
post[:payment_method_options][:card][:network_token] = {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method add_network_token_cryptogram_and_eci
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def add_network_token_cryptogram_and_eci(post, payment_method)
return unless adding_network_token_card_data?(payment_method)
post[:payment_method_options] ||= {}
post[:payment_method_options][:card] ||= {}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method add_payment_method_data
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def add_payment_method_data(payment_method, options = {})
post = {
type: 'card',
card: {
exp_month: payment_method.month,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method add_billing_address
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def add_billing_address(post, payment_method, options = {})
return if payment_method.nil? || payment_method.is_a?(StripePaymentToken) || payment_method.is_a?(String)
post[:payment_method_data] ||= {}
if billing = options[:billing_address] || options[:address]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method add_billing_address_for_card_tokenization
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def add_billing_address_for_card_tokenization(post, options = {})
return unless (billing = options[:billing_address] || options[:address])
billing = add_address(billing, options)
billing[:address].transform_keys! { |k| k == :postal_code ? :address_zip : k.to_s.prepend('address_').to_sym }
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method add_claim_without_transaction_id
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def add_claim_without_transaction_id(post, options = {})
return if options[:stored_credential] || options[:network_transaction_id] || options[:ds_transaction_id]
return unless options[:claim_without_transaction_id]
post[:payment_method_options] ||= {}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"