Shopify/active_merchant

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

Summary

Maintainability
F
1 wk
Test Coverage

File worldpay.rb has 868 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'nokogiri'

module ActiveMerchant #:nodoc:
  module Billing #:nodoc:
    class WorldpayGateway < Gateway
Severity: Major
Found in lib/active_merchant/billing/gateways/worldpay.rb - About 2 days to fix

    Class WorldpayGateway has 100 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class WorldpayGateway < Gateway
          self.test_url = 'https://secure-test.worldpay.com/jsp/merchant/xml/paymentService.jsp'
          self.live_url = 'https://secure.worldpay.com/jsp/merchant/xml/paymentService.jsp'
    
          self.default_currency = 'GBP'
    Severity: Major
    Found in lib/active_merchant/billing/gateways/worldpay.rb - About 1 day to fix

      Method build_authorization_request has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
      Open

            def build_authorization_request(money, payment_method, options)
              build_request do |xml|
                xml.submit do
                  xml.order order_tag_attributes(options) do
                    xml.description(options[:description].blank? ? 'Purchase' : options[:description])
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/worldpay.rb - About 5 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_sub_merchant_data has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

            def add_sub_merchant_data(xml, options)
              xml.subMerchantData do
                xml.pfId options[:pf_id] if options[:pf_id]
                xml.subName options[:sub_name] if options[:sub_name]
                xml.subId options[:sub_id] if options[:sub_id]
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/worldpay.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_network_tokenization_card has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

            def add_network_tokenization_card(xml, payment_method, options)
              source = payment_method.respond_to?(:source) ? payment_method.source : options[:wallet_type]
              token_type = NETWORK_TOKEN_TYPE.fetch(source, 'NETWORKTOKEN')
      
              xml.paymentDetails do
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/worldpay.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_address has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

            def add_address(xml, address, options)
              return unless address
      
              address = address_with_defaults(address)
      
      
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/worldpay.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_level_two_and_three_data has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

            def add_level_two_and_three_data(xml, amount, data)
              xml.invoiceReferenceNumber data[:invoice_reference_number] if data.include?(:invoice_reference_number)
              xml.customerReference data[:customer_reference] if data.include?(:customer_reference)
              xml.cardAcceptorTaxId data[:card_acceptor_tax_id] if data.include?(:card_acceptor_tax_id)
      
      
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/worldpay.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_items_into_level_three_data has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

            def add_items_into_level_three_data(xml, item)
              xml.item do
                xml.description item[:description] if item[:description]
                xml.productCode item[:product_code] if item[:product_code]
                xml.commodityCode item[:commodity_code] if item[:commodity_code]
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/worldpay.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_level_two_and_three_data has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def add_level_two_and_three_data(xml, amount, data)
              xml.invoiceReferenceNumber data[:invoice_reference_number] if data.include?(:invoice_reference_number)
              xml.customerReference data[:customer_reference] if data.include?(:customer_reference)
              xml.cardAcceptorTaxId data[:card_acceptor_tax_id] if data.include?(:card_acceptor_tax_id)
      
      
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/worldpay.rb - About 1 hr to fix

        Method commit has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def commit(action, request, *success_criteria, options)
                xml = ssl_post(url, request, headers(options))
                raw = parse(action, xml)
        
                if options[:execute_threed]
        Severity: Minor
        Found in lib/active_merchant/billing/gateways/worldpay.rb - About 1 hr to fix

          Method parse_elements has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

                def parse_elements(node, response)
                  node_name = node.name.underscore
                  node.attributes.each do |k, v|
                    response["#{node_name}_#{k.underscore}".to_sym] = v.value
                  end
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/worldpay.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 commit has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

                def commit(action, request, *success_criteria, options)
                  xml = ssl_post(url, request, headers(options))
                  raw = parse(action, xml)
          
                  if options[:execute_threed]
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/worldpay.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 capture has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

                def capture(money, authorization, options = {})
                  authorization = order_id_from_authorization(authorization.to_s)
                  MultiResponse.run do |r|
                    r.process { inquire_request(authorization, options, 'AUTHORISED', 'CAPTURED') } unless options[:authorization_validated]
                    if r.params
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/worldpay.rb - About 45 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 refund has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def refund(money, authorization, options = {})
                  authorization = order_id_from_authorization(authorization.to_s)
                  success_criteria = %w(CAPTURED SETTLED SETTLED_BY_MERCHANT SENT_FOR_REFUND)
                  success_criteria.push('AUTHORIZED') if options[:cancel_or_refund]
                  response = MultiResponse.run do |r|
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/worldpay.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_shopper_id has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def add_shopper_id(xml, options)
                  if options[:ip] && options[:session_id]
                    xml.session 'shopperIPAddress' => options[:ip], 'id' => options[:session_id]
                  else
                    xml.session 'shopperIPAddress' => options[:ip] if options[:ip]
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/worldpay.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_three_d_secure has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

                def add_three_d_secure(xml, options)
                  return unless three_d_secure = options[:three_d_secure]
          
                  xml.info3DSecure do
                    xml.threeDSVersion three_d_secure[:version]
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/worldpay.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

          Method generate_stored_credential_params has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

                def generate_stored_credential_params(is_initial_transaction, reason = nil)
                  customer_or_merchant = reason == 'RECURRING' && is_initial_transaction ? 'customerInitiatedReason' : 'merchantInitiatedReason'
          
                  stored_credential_params = {}
                  stored_credential_params['usage'] = is_initial_transaction ? 'FIRST' : 'USED'
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/worldpay.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 2 locations. Consider refactoring.
          Open

                    add_date_element(xml, 'shopperAccountCreationDate', shopper_account_risk_data[:shopper_account_creation_date])
                    add_date_element(xml, 'shopperAccountModificationDate', shopper_account_risk_data[:shopper_account_modification_date])
                    add_date_element(xml, 'shopperAccountPasswordChangeDate', shopper_account_risk_data[:shopper_account_password_change_date])
                    add_date_element(xml, 'shopperAccountShippingAddressFirstUseDate', shopper_account_risk_data[:shopper_account_shipping_address_first_use_date])
                    add_date_element(xml, 'shopperAccountPaymentAccountFirstUseDate', shopper_account_risk_data[:shopper_account_payment_account_first_use_date])
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/worldpay.rb and 1 other location - About 25 mins to fix
          lib/active_merchant/billing/gateways/ogone.rb on lines 316..320

          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 31.

          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

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

                        'dayOfMonth' => timestamp[:day_of_month],
                        'month' => timestamp[:month],
                        'year' => timestamp[:year],
                        'hour' => timestamp[:hour],
                        'minute' => timestamp[:minute],
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/worldpay.rb and 1 other location - About 15 mins to fix
          lib/active_merchant/billing/gateways/worldpay.rb on lines 526..532

          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 25.

          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

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

                  data = {
                    'shippingMethod' => transaction_risk_data[:shipping_method],
                    'deliveryTimeframe' => transaction_risk_data[:delivery_timeframe],
                    'deliveryEmailAddress' => transaction_risk_data[:delivery_email_address],
                    'reorderingPreviousPurchases' => transaction_risk_data[:reordering_previous_purchases],
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/worldpay.rb and 1 other location - About 15 mins to fix
          lib/active_merchant/billing/gateways/worldpay.rb on lines 472..477

          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 25.

          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