<commit_before>require 'net/http'
require 'digest'
require 'cgi'

module Przelewy24
  class Client
    attr_reader :merchant_id, :pos_id, :crc, :gateway_url

    def initialize(merchant_id, pos_id, crc)
      @merchant_id = merchant_id
      @pos_id = pos_id
      @crc = crc
      @gateway_url = 'sandbox.przelewy24.pl'
    end

    def test_connection
      signature = Digest::MD5.hexdigest("#{merchant_id}|#{crc}")

      connection = Net::HTTP.new(gateway_url, 443)
      connection.use_ssl = true

      response = connection.start do |http|
        post = Net::HTTP::Post.new('/testConnection')
        post.set_form_data(p24_merchant_id: merchant_id, p24_pos_id: merchant_id, p24_sign: signature)
        http.request(post)
      end

      Response.new(response)
    end

    def create_transaction(data = {})
      Transaction.new(data.reverse_merge(merchant_id: merchant_id, pos_id: pos_id, crc: crc))
    end

    def register_transaction(transaction)
      connection = Net::HTTP.new(gateway_url, 443)<commit_msg>Allow to configure server hostname<commit_after>require 'net/http'
require 'digest'

module Przelewy24
  class Client
    attr_reader :merchant_id, :pos_id, :crc, :gateway_url

    def initialize(merchant_id, pos_id, crc, mode = :sandbox)
      @merchant_id = merchant_id
      @pos_id = pos_id
      @crc = crc

      if mode == :production
        @gateway_url = 'secure.przelewy24.pl'
      else
        @gateway_url = 'sandbox.przelewy24.pl'
      end
    end

    def test_connection
      signature = Digest::MD5.hexdigest("#{merchant_id}|#{crc}")

      connection = Net::HTTP.new(gateway_url, 443)
      connection.use_ssl = true

      response = connection.start do |http|
        post = Net::HTTP::Post.new('/testConnection')
        post.set_form_data(p24_merchant_id: merchant_id, p24_pos_id: merchant_id, p24_sign: signature)
        http.request(post)
      end

      Response.new(response)
    end

    def create_transaction(data = {})
      Transaction.new(data.reverse_merge(merchant_id: merchant_id, pos_id: pos_id, crc: crc))
    end

    def register_transaction(transaction)
      connection = Net::HTTP.new(gateway_url, 443)
{'fraction_non_alphanumeric': 0.10666666666666667, 'fraction_numerical': 0.016551724137931035, 'mean_word_length': 3.283464566929134, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2609688', 'n_tokens_mistral': 779, 'n_tokens_neox': 737, 'n_words': 144}