<commit_before>require 'simple_stripe_plugin/base_controller'

module SimpleStripePlugin
  class StripeController < BaseController
    def charge
      # Set your secret key: remember to change this to your live secret key in production
      # See your keys here https://manage.stripe.com/account
      puts Engine.plugin_object.config
      puts Engine.plugin_object.config['stripe_secret']
      Stripe.api_key = Engine.plugin_object.config['stripe_secret']

      # Get the credit card details submitted by the form
      token = params[:stripeToken]
      amount = params[:amount].to_f * 100
      description = params[:name] + " for " + params[:id_number]

      @response = {}

      # Charge the Customer instead of the card
      begin
        Stripe::Charge.create(
          :amount => amount.to_i, # in cents
          :currency => "cad",
          :card => token,
          :description => description,
        )
        @response = {success: true}
      rescue Stripe::CardError => e
        #Deal With Errors
        body = e.json_body
        err  = body[:error]

        @response = {error: {message: err[:message]}}
      end
      render json: @response
    end
  end
end
<commit_msg>do a small refactor on stripe controller<commit_after>require 'simple_stripe_plugin/base_controller'

module SimpleStripePlugin
  class StripeController < BaseController
    def charge
      # Set your secret key: remember to change this to your live secret key in production
      # See your keys here https://manage.stripe.com/account
      Stripe.api_key = Engine.plugin_object.config['stripe_secret']

      # Get the credit card details submitted by the form
      token = params[:stripeToken]
      amount = (params[:amount].to_f * 100).to_i
      description = params[:name] + " for " + params[:id_number]

      @response = {}

      # Charge the Customer instead of the card
      begin
        Stripe::Charge.create(
          :amount => amount, # in cents
          :currency => "cad",
          :card => token,
          :description => description,
        )
        @response = {success: true}
      rescue Stripe::CardError => e
        #Deal With Errors
        body = e.json_body
        err  = body[:error]

        @response = {error: {message: err[:message]}}
      end
      render json: @response
    end
  end
end

{'fraction_non_alphanumeric': 0.09401709401709402, 'fraction_numerical': 0.002564102564102564, 'mean_word_length': 2.4579025110782866, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '7484426', 'n_tokens_mistral': 670, 'n_tokens_neox': 648, 'n_words': 196}