Class: IshManager::PricesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ish_manager/prices_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#basic_auth, #home, #tinymce

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/ish_manager/prices_controller.rb', line 7

def create
  @price   = Wco::Price.new params[:price].permit( :amount_cents, :interval, :product_id )
  puts! @price, '@price'
  authorize! :create, @price
  if !params[:price][:interval].present?
    @price.interval = nil
  end
  @product       = Wco::Product.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 )
  # puts! stripe_price, 'stripe_price'

  flash_notice 'Created stripe price.'
  @price.product = @product
  @price.price_id = stripe_price[:id]
  if @price.save
    flash_notice @price
  else
    flash_alert @price
  end
  redirect_to controller: :products, action: :index
end

#updateObject



38
39
40
41
42
43
# File 'app/controllers/ish_manager/prices_controller.rb', line 38

def update

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