<commit_before>module Spree
  class Gateway::GlobalCollectHml < Gateway
    include GlobalCollect::Constants

    preference :merchant_id, :string
    preference :test_mode, :boolean, default: false
    preference :payment_products, :hash, default: PAYMENT_PRODUCTS
    preference :payment_product_restrictions, :hash,
               default: PAYMENT_PRODUCTS_RESTRICTIONS

    has_many :global_collect_checkouts,
             class_name: 'Spree::GlobalCollectCheckout',
             foreign_key: 'payment_method_id'

    def method_type
      'global_collect_hml'
    end

    def provider_class
      provider.class
    end

    def provider
      self
    end

    def auto_capture?
      false
    end

    def payment_profiles_supported?
      true
    end

    def payment_source_class
      Spree::GlobalCollectCheckout
    end

    def reusable_sources(order)
      if order.completed?
        sources_by_order order
      else
        if order.user_id
          global_collect_checkouts
            .where(user_id: order.user_id).with_payment_profile
        else
          []
        end
      end
    end

    def authorize(amount, source, gateway_options={})
      response = provider.get_orderstatus(source.order_number)
      source.update_attributes(
        payment_product_id:   response[:paymentproductid],
        effort_id:            response[:effortid],
        attempt_id:           response[:attemptid],
        gc_payment_method_id: response[:paymentmethodid],
        payment_reference:    response[:paymentreference]
      )

      if response.success?
        # Settare per usare AVS e CVV
        source.payment.update_attributes(
          response_code: response[:merchantreference]
        )

        ActiveMerchant::Billing::Response.new(
          true, Spree.t('global_collect.payment_authorized'),
          gc_response: response.to_s)
      else
        ActiveMerchant::Billing::Response.new(
          false, response.error || Spree.t('global_collect.payment_error'),
          gc_response: response.to_s)
      end
    end
<commit_msg>uses authorization for ActiveMerchant success<commit_after>module Spree
  class Gateway::GlobalCollectHml < Gateway
    include GlobalCollect::Constants

    preference :merchant_id, :string
    preference :test_mode, :boolean, default: false
    preference :payment_products, :hash, default: PAYMENT_PRODUCTS
    preference :payment_product_restrictions, :hash,
               default: PAYMENT_PRODUCTS_RESTRICTIONS

    has_many :global_collect_checkouts,
             class_name: 'Spree::GlobalCollectCheckout',
             foreign_key: 'payment_method_id'

    def method_type
      'global_collect_hml'
    end

    def provider_class
      provider.class
    end

    def provider
      self
    end

    def auto_capture?
      false
    end

    def payment_profiles_supported?
      true
    end

    def payment_source_class
      Spree::GlobalCollectCheckout
    end

    def reusable_sources(order)
      if order.completed?
        sources_by_order order
      else
        if order.user_id
          global_collect_checkouts
            .where(user_id: order.user_id).with_payment_profile
        else
          []
        end
      end
    end

    def authorize(amount, source, gateway_options={})
      response = provider.get_orderstatus(source.order_number)
      source.update_attributes(
        payment_product_id:   response[:paymentproductid],
        effort_id:            response[:effortid],
        attempt_id:           response[:attemptid],
        gc_payment_method_id: response[:paymentmethodid],
        payment_reference:    response[:paymentreference]
      )

      if response.success?
        ActiveMerchant::Billing::Response.new(
          true, Spree.t('global_collect.payment_authorized'),
          { gc_response: response.to_s },
          authorization: response[:merchantreference]
        )
      else
        ActiveMerchant::Billing::Response.new(
          false, response.error || Spree.t('global_collect.payment_error'),
          gc_response: response.to_s
        )
      end
    end

{'fraction_non_alphanumeric': 0.06955252918287938, 'fraction_numerical': 0.0, 'mean_word_length': 2.4944774851316907, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '405617', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1134, 'n_words': 223}