Shopify/active_merchant

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

Summary

Maintainability
F
5 days
Test Coverage

File usa_epay_advanced.rb has 842 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'securerandom'
require 'digest'

module ActiveMerchant #:nodoc:
  module Billing #:nodoc:
Severity: Major
Found in lib/active_merchant/billing/gateways/usa_epay_advanced.rb - About 2 days to fix

    Class UsaEpayAdvancedGateway has 90 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class UsaEpayAdvancedGateway < Gateway
          API_VERSION = '1.4'
    
          TEST_URL_BASE = 'https://sandbox.usaepay.com/soap/gate/' #:nodoc:
          LIVE_URL_BASE = 'https://www.usaepay.com/soap/gate/' #:nodoc:
    Severity: Major
    Found in lib/active_merchant/billing/gateways/usa_epay_advanced.rb - About 1 day to fix

      Method parse has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

            def parse(action, soap)
              xml = REXML::Document.new(soap)
              root = REXML::XPath.first(xml, '//SOAP-ENV:Body')
              response = root ? parse_element(root[0]) : { response: soap }
      
      
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/usa_epay_advanced.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 parse_element has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

            def parse_element(node)
              if node.has_elements?
                response = {}
                node.elements.each do |e|
                  key = e.name.underscore
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/usa_epay_advanced.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 parse has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def parse(action, soap)
              xml = REXML::Document.new(soap)
              root = REXML::XPath.first(xml, '//SOAP-ENV:Body')
              response = root ? parse_element(root[0]) : { response: soap }
      
      
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/usa_epay_advanced.rb - About 1 hr to fix

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

              def build_field_value_array(soap, tag_name, type, custom_data, fields)
        Severity: Minor
        Found in lib/active_merchant/billing/gateways/usa_epay_advanced.rb - About 35 mins to fix

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

                def build_recurring_billing(soap, options)
                  if options[:recurring]
                    soap.RecurringBilling 'xsi:type' => 'ns1:RecurringBilling' do
                      build_tag soap, :double, 'Amount', amount(options[:recurring][:amount])
                      build_tag soap, :string, 'Next', options[:recurring][:next].strftime('%Y-%m-%d') if options[:recurring][:next]
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/usa_epay_advanced.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 build_credit_card_or_check has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

                def build_credit_card_or_check(soap, payment_method)
                  case
                  when payment_method[:method].kind_of?(ActiveMerchant::Billing::CreditCard)
                    build_tag soap, :string, 'CardNumber', payment_method[:method].number
                    build_tag soap, :string, 'CardExpiration', "#{'%02d' % payment_method[:method].month}#{payment_method[:method].year.to_s[-2..-1]}"
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/usa_epay_advanced.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

                def build_billing_address(soap, options)
                  if options[:billing_address]
                    options[:billing_address][:first_name], options[:billing_address][:last_name] = split_names(options[:billing_address][:name]) if options[:billing_address][:name]
                    soap.BillingAddress 'xsi:type' => 'ns1:Address' do
                      ADDRESS_OPTIONS.each do |k, v|
          Severity: Major
          Found in lib/active_merchant/billing/gateways/usa_epay_advanced.rb and 1 other location - About 1 hr to fix
          lib/active_merchant/billing/gateways/usa_epay_advanced.rb on lines 1485..1490

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

          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

                def build_shipping_address(soap, options)
                  if options[:shipping_address]
                    options[:shipping_address][:first_name], options[:shipping_address][:last_name] = split_names(options[:shipping_address][:name]) if options[:shipping_address][:name]
                    soap.ShippingAddress 'xsi:type' => 'ns1:Address' do
                      ADDRESS_OPTIONS.each do |k, v|
          Severity: Major
          Found in lib/active_merchant/billing/gateways/usa_epay_advanced.rb and 1 other location - About 1 hr to fix
          lib/active_merchant/billing/gateways/usa_epay_advanced.rb on lines 1474..1479

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

          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

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

                def parse_element(node)
                  if node.has_elements?
                    response = {}
                    node.elements.each do |e|
                      key = e.name.underscore
          Severity: Major
          Found in lib/active_merchant/billing/gateways/usa_epay_advanced.rb and 1 other location - About 1 hr to fix
          lib/active_merchant/billing/gateways/authorize_net_cim.rb on lines 947..967

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

          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 4 locations. Consider refactoring.
          Open

                CUSTOMER_RECURRING_BILLING_OPTIONS = {
                  enabled: [:boolean, 'Enabled'],
                  schedule: [:string, 'Schedule'],
                  number_left: [:integer, 'NumLeft'],
                  currency: [:string, 'Currency'],
          Severity: Major
          Found in lib/active_merchant/billing/gateways/usa_epay_advanced.rb and 3 other locations - About 50 mins to fix
          lib/active_merchant/billing/gateways/usa_epay_advanced.rb on lines 112..123
          lib/active_merchant/billing/gateways/usa_epay_advanced.rb on lines 166..177
          lib/active_merchant/billing/gateways/usa_epay_advanced.rb on lines 203..214

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

          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 4 locations. Consider refactoring.
          Open

                COMMON_ADDRESS_OPTIONS = {
                  first_name: [:string, 'FirstName'],
                  last_name: [:string, 'LastName'],
                  city: [:string, 'City'],
                  state: [:string, 'State'],
          Severity: Major
          Found in lib/active_merchant/billing/gateways/usa_epay_advanced.rb and 3 other locations - About 50 mins to fix
          lib/active_merchant/billing/gateways/usa_epay_advanced.rb on lines 87..98
          lib/active_merchant/billing/gateways/usa_epay_advanced.rb on lines 166..177
          lib/active_merchant/billing/gateways/usa_epay_advanced.rb on lines 203..214

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

          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 4 locations. Consider refactoring.
          Open

                TRANSACTION_REQUEST_OBJECT_OPTIONS = {
                  command: [:string, 'Command'],
                  ignore_duplicate: [:boolean, 'IgnoreDuplicate'],
                  authorization_code: [:string, 'AuthCode'],
                  reference_number: [:string, 'RefNum'],
          Severity: Major
          Found in lib/active_merchant/billing/gateways/usa_epay_advanced.rb and 3 other locations - About 50 mins to fix
          lib/active_merchant/billing/gateways/usa_epay_advanced.rb on lines 87..98
          lib/active_merchant/billing/gateways/usa_epay_advanced.rb on lines 112..123
          lib/active_merchant/billing/gateways/usa_epay_advanced.rb on lines 203..214

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

          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 4 locations. Consider refactoring.
          Open

                CREDIT_CARD_DATA_OPTIONS = {
                  magnetic_stripe: [:string, 'MagStripe'],
                  dukpt: [:string, 'DUKPT'],
                  signature: [:string, 'Signature'],
                  terminal_type: [:string, 'TermType'],
          Severity: Major
          Found in lib/active_merchant/billing/gateways/usa_epay_advanced.rb and 3 other locations - About 50 mins to fix
          lib/active_merchant/billing/gateways/usa_epay_advanced.rb on lines 87..98
          lib/active_merchant/billing/gateways/usa_epay_advanced.rb on lines 112..123
          lib/active_merchant/billing/gateways/usa_epay_advanced.rb on lines 166..177

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

          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

                CHECK_DATA_OPTIONS = {
                  drivers_license: [:string, 'DriversLicense'],
                  drivers_license_state: [:string, 'DriversLicenseState'],
                  record_type: [:string, 'RecordType'],
                  aux_on_us: [:string, 'AuxOnUS'],
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/usa_epay_advanced.rb and 1 other location - About 25 mins to fix
          lib/active_merchant/billing/gateways/usa_epay_advanced.rb on lines 193..201

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

          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

                TRANSACTION_DETAIL_MONEY_OPTIONS = {
                  amount: [:double, 'Amount'],
                  tax: [:double, 'Tax'],
                  tip: [:double, 'Tip'],
                  non_tax: [:boolean, 'NonTax'],
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/usa_epay_advanced.rb and 1 other location - About 25 mins to fix
          lib/active_merchant/billing/gateways/usa_epay_advanced.rb on lines 216..224

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

          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

                def build_capture_transaction(soap, options)
                  soap.tag! 'ns1:captureTransaction' do
                    build_token soap, options
                    build_tag soap, :integer, 'RefNum', options[:reference_number]
                    build_tag soap, :double, 'Amount', amount(options[:amount])
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/usa_epay_advanced.rb and 1 other location - About 15 mins to fix
          lib/active_merchant/billing/gateways/usa_epay_advanced.rb on lines 1274..1278

          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

                def build_refund_transaction(soap, options)
                  soap.tag! 'ns1:refundTransaction' do
                    build_token soap, options
                    build_tag soap, :integer, 'RefNum', options[:reference_number]
                    build_tag soap, :integer, 'Amount', amount(options[:amount])
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/usa_epay_advanced.rb and 1 other location - About 15 mins to fix
          lib/active_merchant/billing/gateways/usa_epay_advanced.rb on lines 1259..1263

          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