<commit_before>module Stall
  module AuthorizeDotNet
    class Gateway < Stall::Payments::Gateway
      register :authorize_dot_net

      class_attribute :account
      class_attribute :transaction_key
      class_attribute :md5_hash

      # Test or production mode, default to false, changes the payment
      # gateway target URL
      class_attribute :test_mode
      self.test_mode = !Rails.env.production?

      def self.test_mode=(value)
        OffsitePayments.mode = value ? :test : :production
        @test_mode = value
      end

      def self.request(cart)
        Request.new(cart)
      end

      def self.response(request)
        Response.new(request)
      end

      def self.fake_payment_notification_for(cart)
        Stall::AuthorizeDotNet::FakeGatewayPaymentNotification.new(cart)
      end

      class Request
        attr_reader :cart

        delegate :currency, to: :cart, allow_nil: true

        def initialize(cart)
          @cart = cart
        end

        def payment_form_partial_path
          'stall/authorize_dot_net/payment_form'
        end

        def gateway
          @gateway = Stall::AuthorizeDotNet::Gateway.new(cart)
        end
      end

      class Response
        attr_reader :request

        def initialize(request)
          @request = request
        end

        def rendering_options
          {
            partial: 'stall/authorize_dot_net/relay_response',
            locals: { response: self }
          }
        end

        def success?
          @success ||= valid? && notification.complete?
        end

        def valid?
          @valid ||= notification.acknowledge(gateway.md5_hash, gateway.account)
        end

        def notify
          cart.payment.pay! if success?
        end

        private

        def notification
          @notification ||=
            OffsitePayments::Integrations::AuthorizeNetSim::Notification.new(
              request.raw_post
            )
        end

        def cart
          @cart ||= Cart.find_by_reference(notification.invoice_num)
        end

        def gateway
          @gateway = Stall::AuthorizeDotNet::Gateway
        end
      end
    end
  end
end<commit_msg>make Response#gateway and #cart public<commit_after>module Stall
  module AuthorizeDotNet
    class Gateway < Stall::Payments::Gateway
      register :authorize_dot_net

      class_attribute :account
      class_attribute :transaction_key
      class_attribute :md5_hash

      # Test or production mode, default to false, changes the payment
      # gateway target URL
      class_attribute :test_mode
      self.test_mode = !Rails.env.production?

      def self.test_mode=(value)
        OffsitePayments.mode = value ? :test : :production
        @test_mode = value
      end

      def self.request(cart)
        Request.new(cart)
      end

      def self.response(request)
        Response.new(request)
      end

      def self.fake_payment_notification_for(cart)
        Stall::AuthorizeDotNet::FakeGatewayPaymentNotification.new(cart)
      end

      class Request
        attr_reader :cart

        delegate :currency, to: :cart, allow_nil: true

        def initialize(cart)
          @cart = cart
        end

        def payment_form_partial_path
          'stall/authorize_dot_net/payment_form'
        end

        def gateway
          @gateway = Stall::AuthorizeDotNet::Gateway.new(cart)
        end
      end

      class Response
        attr_reader :request

        def initialize(request)
          @request = request
        end

        def rendering_options
          {
            partial: 'stall/authorize_dot_net/relay_response',
            locals: { response: self }
          }
        end

        def success?
          @success ||= valid? && notification.complete?
        end

        def valid?
          @valid ||= notification.acknowledge(gateway.md5_hash, gateway.account)
        end

        def notify
          cart.payment.pay! if success?
        end

        def gateway
          @gateway = Stall::AuthorizeDotNet::Gateway
        end

        def cart
          @cart ||= Cart.find_by_reference(notification.invoice_num)
        end

        private

        def notification
          @notification ||=
            OffsitePayments::Integrations::AuthorizeNetSim::Notification.new(
              request.raw_post
            )
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.06898116632629907, 'fraction_numerical': 0.0009076469253460404, 'mean_word_length': 1.8754076973255056, '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': '1673804', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1172, 'n_words': 271}