Sha256: d3d455ba8bf60b1d86abe532d298bf49473fe0c2abc2d3955ed2df771e862bbd

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 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

  def update
    # if !params[:price][:interval].present?
    #   @price.interval = nil
    # end
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
wco_models-3.1.0.113 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.112 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.111 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.110 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.109 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.108 app/controllers/wco/prices_controller.rb
wco_models-3.1.0.107 app/controllers/wco/prices_controller.rb