Shopify/active_merchant

View on GitHub
lib/active_merchant/billing/gateways/checkout_v2.rb

Summary

Maintainability
F
6 days
Test Coverage

File checkout_v2.rb has 554 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module ActiveMerchant #:nodoc:
  module Billing #:nodoc:
    class CheckoutV2Gateway < Gateway
      self.display_name = 'Checkout.com Unified Payments'
      self.homepage_url = 'https://www.checkout.com/'
Severity: Major
Found in lib/active_merchant/billing/gateways/checkout_v2.rb - About 1 day to fix

    Class CheckoutV2Gateway has 52 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class CheckoutV2Gateway < Gateway
          self.display_name = 'Checkout.com Unified Payments'
          self.homepage_url = 'https://www.checkout.com/'
          self.live_url = 'https://api.checkout.com'
          self.test_url = 'https://api.sandbox.checkout.com'
    Severity: Major
    Found in lib/active_merchant/billing/gateways/checkout_v2.rb - About 7 hrs to fix

      Method add_payment_method has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
      Open

            def add_payment_method(post, payment_method, options, key = :source)
              # the key = :destination when this method is called in def credit
              post[key] = {}
              case payment_method
              when NetworkTokenizationCreditCard
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/checkout_v2.rb - About 6 hrs to fix

      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_payout_destination_data has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

            def add_payout_destination_data(post, options)
              return unless options[:payout] == true
      
              post[:destination] ||= {}
              post[:destination][:account_holder] ||= {}
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/checkout_v2.rb - About 4 hrs to fix

      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_customer_data has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

            def add_customer_data(post, options)
              post[:customer] = {}
              post[:customer][:email] = options[:email] || nil
              post[:payment_ip] = options[:ip] if options[:ip]
              address = options[:billing_address]
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/checkout_v2.rb - About 3 hrs to fix

      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_recipient_data has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

            def add_recipient_data(post, options)
              return unless options[:recipient].is_a?(Hash)
      
              recipient = options[:recipient]
      
      
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/checkout_v2.rb - About 2 hrs to fix

      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_3ds has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

            def add_3ds(post, options)
              if options[:three_d_secure] || options[:execute_threed]
                post[:'3ds'] = {}
                post[:'3ds'][:enabled] = true
                post[:success_url] = options[:callback_url] if options[:callback_url]
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/checkout_v2.rb - About 2 hrs to fix

      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_shipping_address has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

            def add_shipping_address(post, options)
              if address = options[:shipping_address]
                post[:shipping] = {}
                post[:shipping][:address] = {}
                post[:shipping][:address][:address_line1] = address[:address1] unless address[:address1].blank?
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/checkout_v2.rb - About 2 hrs to fix

      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 has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def add_payment_method(post, payment_method, options, key = :source)
              # the key = :destination when this method is called in def credit
              post[key] = {}
              case payment_method
              when NetworkTokenizationCreditCard
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/checkout_v2.rb - About 1 hr to fix

        Method store has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

              def store(payment_method, options = {})
                post = {}
                MultiResponse.run do |r|
                  if payment_method.is_a?(NetworkTokenizationCreditCard)
                    r.process { verify(payment_method, options) }
        Severity: Minor
        Found in lib/active_merchant/billing/gateways/checkout_v2.rb - About 1 hr to fix

        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_payout_sender_data has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def add_payout_sender_data(post, options)
                return unless options[:payout] == true
        
                post[:sender] = {
                  # options for type are individual, corporate, or government
        Severity: Minor
        Found in lib/active_merchant/billing/gateways/checkout_v2.rb - About 1 hr to fix

          Method success_from has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

                def success_from(action, response)
                  return response['status'] == 'Pending' if action == :credit
                  return true if action == :unstore && response == 204
          
                  store_response = response['token'] || response['id']
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/checkout_v2.rb - About 1 hr to fix

          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 commit has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

                def commit(action, post, options, authorization = nil, method = :post)
                  begin
                    raw_response = ssl_request(method, url(action, authorization), post.nil? || post.empty? ? nil : post.to_json, headers(action, options))
                    response = parse(raw_response)
                    response['id'] = response['_links']['payment']['href'].split('/')[-1] if action == :capture && response.key?('_links')
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/checkout_v2.rb - About 1 hr to fix

          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 error_code_from has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

                def error_code_from(succeeded, response, options)
                  return if succeeded
          
                  if response['error_type'] && response['error_codes']
                    "#{response['error_type']}: #{response['error_codes'].join(', ')}"
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/checkout_v2.rb - About 55 mins to fix

          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 response has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

                def response(action, succeeded, response, options = {}, source_id = nil)
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/checkout_v2.rb - About 35 mins to fix

            Method commit has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                  def commit(action, post, options, authorization = nil, method = :post)
            Severity: Minor
            Found in lib/active_merchant/billing/gateways/checkout_v2.rb - About 35 mins to fix

              Method message_from has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                    def message_from(succeeded, response, options)
                      if succeeded
                        'Succeeded'
                      elsif response['error_type']
                        response['error_type'] + ': ' + response['error_codes'].first
              Severity: Minor
              Found in lib/active_merchant/billing/gateways/checkout_v2.rb - About 35 mins to fix

              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_invoice has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                    def add_invoice(post, money, options)
                      post[:amount] = localized_amount(money, options[:currency])
                      post[:reference] = options[:order_id]
                      post[:currency] = options[:currency] || currency(money)
                      if options[:descriptor_name] || options[:descriptor_city]
              Severity: Minor
              Found in lib/active_merchant/billing/gateways/checkout_v2.rb - About 25 mins to fix

              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

              Similar blocks of code found in 3 locations. Consider refactoring.
              Open

                      if options[:descriptor_name] || options[:descriptor_city]
                        post[:billing_descriptor] = {}
                        post[:billing_descriptor][:name] = options[:descriptor_name] if options[:descriptor_name]
                        post[:billing_descriptor][:city] = options[:descriptor_city] if options[:descriptor_city]
                      end
              Severity: Minor
              Found in lib/active_merchant/billing/gateways/checkout_v2.rb and 2 other locations - About 40 mins to fix
              lib/active_merchant/billing/gateways/commerce_hub.rb on lines 283..287
              lib/active_merchant/billing/gateways/wepay.rb on lines 160..164

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 37.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              There are no issues that match your filters.

              Category
              Status