Sha256: 00e69f55c3a9de3ff8428722894d088bc15a9d68ae440ae674a5c0286c5e5eeb

Contents?: true

Size: 1.38 KB

Versions: 79

Compression:

Stored size: 1.38 KB

Contents

class Wco::PricesController < Wco::ApplicationController

  def create
    @price   = Wco::Price.new params[:price].permit!
    authorize! :create, @price

    @price.interval = nil if !params[:price][:interval].present?
    @product        = params[:price][:product_type].constantize.find @price.product_id
    stripe_product  = Stripe::Product.retrieve( @product.product_id )
    price_hash = {
      product:     stripe_product.id,
      unit_amount: @price.amount_cents,
      currency:    'usd',
    }
    if @price.interval.present?
      price_hash[:recurring] = { interval: @price.interval }
    end
    stripe_price = Stripe::Price.create( price_hash )
    # flash_notice 'Created stripe price.'
    flash_notice stripe_price

    @price.product  = @product
    @price.price_id = stripe_price[:id]
    if @price.save
      flash_notice @price
    else
      flash_alert @price
    end
    case @product.class.name
    when 'WcoHosting::ApplianceTmpl'
      redirect_to request.referrer || root_path
    when 'Wco::Product'
      redirect_to controller: :products, action: :index
    end
  end

  def destroy
    @price = Wco::Price.find params[:id]
    authorize! :destroy, @price
    flag = @price.delete
    if flag
      flash_notice 'ok'
    else
      flash_alert @price
    end
    redirect_to request.referrer || root_path
  end

  ## delete and the create, instead
  # def update
  # end

end

Version data entries

79 entries across 79 versions & 1 rubygems

Version Path
wco_models-3.1.0.201 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.199 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.198 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.197 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.196 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.195 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.194 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.193 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.192 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.191 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.190 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.189 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.188 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.187 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.184 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.183 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.182 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.181 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.180 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.178 app/controllers/wco/prices_controller.rb