Class: Wco::PricesController
Instance Method Summary
collapse
#home, #tinymce
#my_truthy?, #obfuscate, #pp_amount, #pp_currency, #pp_date, #pp_datetime, #pp_money, #pp_percent, #pp_time, #pretty_date
Instance Method Details
#create ⇒ Object
4
5
6
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/wco/prices_controller.rb', line 4
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
@price.product = @product
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 stripe_price
@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
|
#destroy ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
|
# File 'app/controllers/wco/prices_controller.rb', line 38
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
|