<commit_before># frozen_string_literal: true
class OrdersController < ApplicationController

  skip_before_action :block_users_with_expired_reservations

  def new
    @products = Product.active.ordered
    @order = Order.new(gift: params[:gift], product: Product.find_by_name("1 year"))
  end

  def create
    order_params = params.require(:order).permit([:product_id, :gift])
    paypal_order.product_id = order_params[:product_id].to_i
    paypal_order.gift       = order_params[:gift]
    if paypal_order.save && paypal_order.prepare
      redirect_to paypal_order.checkout_url
    else
      flash[:alert] = "Something went wrong creating your order, please try again"
      render :new
    end
  end

  def redirect
    if order.charge(params[:PayerID])
      if order.gift?
        flash[:notice] = "Your donation has been received and we've made a voucher code that you can give away"
        redirect_to settings_path("#your-vouchers")
      else
        flash[:notice] = "Your donation has been received and your donator perks are now activated, thanks! <3"
        redirect_to root_path
      end
    else
      flash[:alert] = "Something went wrong while trying to activate your donator status, please check if you have sufficient funds in your PayPal account"
      redirect_to root_path
    end
  end

  def stripe
    if params[:stripe_token] && params[:product_id] && params[:gift]
      order = current_user.stripe_orders.build
      order.payer_id = params[:stripe_token]
      order.product = Product.active.find(params[:product_id].to_i)
      order.gift = (params[:gift] == "true")
      order.save!
      charge = order.charge
      if charge == "succeeded"
        render plain: { charge_status: charge, product_name: order.product_name, gift: order.gift, voucher: order.voucher.try(:code) }.to_json
      else
        render plain: { charge_status: charge }.to_json, status: 402
      end
    end
  end

  def order
    current_user.paypal_orders.find(params[:order_id].to_i)
  end

  def paypal_order
    @paypal_order ||= current_user.paypal_orders.build
  end

end<commit_msg>Require ssl in orders controller<commit_after># frozen_string_literal: true
class OrdersController < ApplicationController

  force_ssl if: :ssl_required?

  skip_before_action :block_users_with_expired_reservations

  def new
    @products = Product.active.ordered
    @order = Order.new(gift: params[:gift], product: Product.find_by_name("1 year"))
  end

  def create
    order_params = params.require(:order).permit([:product_id, :gift])
    paypal_order.product_id = order_params[:product_id].to_i
    paypal_order.gift       = order_params[:gift]
    if paypal_order.save && paypal_order.prepare
      redirect_to paypal_order.checkout_url
    else
      flash[:alert] = "Something went wrong creating your order, please try again"
      render :new
    end
  end

  def redirect
    if order.charge(params[:PayerID])
      if order.gift?
        flash[:notice] = "Your donation has been received and we've made a voucher code that you can give away"
        redirect_to settings_path("#your-vouchers")
      else
        flash[:notice] = "Your donation has been received and your donator perks are now activated, thanks! <3"
        redirect_to root_path
      end
    else
      flash[:alert] = "Something went wrong while trying to activate your donator status, please check if you have sufficient funds in your PayPal account"
      redirect_to root_path
    end
  end

  def stripe
    if params[:stripe_token] && params[:product_id] && params[:gift]
      order = current_user.stripe_orders.build
      order.payer_id = params[:stripe_token]
      order.product = Product.active.find(params[:product_id].to_i)
      order.gift = (params[:gift] == "true")
      order.save!
      charge = order.charge
      if charge == "succeeded"
        render plain: { charge_status: charge, product_name: order.product_name, gift: order.gift, voucher: order.voucher.try(:code) }.to_json
      else
        render plain: { charge_status: charge }.to_json, status: 402
      end
    end
  end

  def order
    current_user.paypal_orders.find(params[:order_id].to_i)
  end

  def paypal_order
    @paypal_order ||= current_user.paypal_orders.build
  end

  private

  def ssl_required?
    Rails.env.production?
  end

end
{'fraction_non_alphanumeric': 0.08952116585704371, 'fraction_numerical': 0.002313208420078649, 'mean_word_length': 3.367676767676768, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1063893', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1316, 'n_words': 355}