<commit_before><commit_msg>ChargesHelper extracted<commit_after>module Supercharged::ChargesHelper
  # No order id while generating form. It will be added later via JS
  FAKE_ORDER_ID = 0

  DEFAULT_AMOUNT_FIELD_OPTIONS = {
    role: "charge-amount",
    required: true,
    min: 0
  }

  def charge_form_for(service_name, options = {}, &block)
    raise ArgumentError, "Missing block" unless block_given?

    default_options = {service: service_name}
    options.merge!(default_options)

    options = with_default_html_options(options)

    account = options.delete(:account)
    notify_url = gateways_result_url(service_name)

    payment_service_for(FAKE_ORDER_ID, account, options) do |service|
      service.notify_url notify_url
      block.call(service)
    end
  end

  def charge_form_amount_field(service, options = {})
    amount_field_name = service.mappings[:amount] || raise("Undefined amount field mapping")

    options = options.merge(DEFAULT_AMOUNT_FIELD_OPTIONS)

    number_field_tag amount_field_name, nil, options
  end

  private

  def with_default_html_options(options)
    options[:html] ||= {}
    options[:html].merge!(role: "gateway-charge-form")
    options
  end

end
{'fraction_non_alphanumeric': 0.09, 'fraction_numerical': 0.0016666666666666668, 'mean_word_length': 4.385650224215246, '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': '3388568', 'n_tokens_mistral': 382, 'n_tokens_neox': 365, 'n_words': 80}